-
Notifications
You must be signed in to change notification settings - Fork 0
/
ScoreboardModule.php
154 lines (137 loc) · 3.68 KB
/
ScoreboardModule.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php
/**
* Scoreboard class file.
*
* @author Mirza Widihananta <[email protected]>
* @package application.modules.scoreboard
* @since 2013.08.23
*/
/**
* Module for public scoreboard of OSN 2013.
*
* @author Mirza Widihananta <[email protected]>
* @package application.modules.scoreboard
* @since 2013.08.23
*/
class ScoreboardModule extends CWebModule
{
/**
* The default controller for the scoreboard module controller.
* @var string
* @since 2013.08.23
*/
public $defaultController = 'index';
/**
* The default layout for the controllers.
* @var string
* @since 2013.08.23
*/
public $layout = 'main';
/**
* The URL for the assets.
* @var string
* @since 2013.08.23
*/
private $_assetsUrl;
/**
* Invoke a method before a certain controller called.
* @param CController $controller the controller.
* @param CAction $action the action.
* @return boolean whether the action should be executed.
* @since 2013.08.23
*/
public function beforeControllerAction($controller, $action)
{
if (parent::beforeControllerAction($controller, $action)) {
return true;
}
else
return false;
}
/**
* Initializes the module.
* @since 2013.08.23
*/
public function init()
{
$this->setImport(array(
'scoreboard.models.*',
'scoreboard.components.*',
'scoreboard.controllers.*',
));
Yii::app()->errorHandler->errorAction = '/scoreboard/error/index';
}
/**
* Returns the URL for the module's assets.
* @return string url for module's assets.
* @since 2013.08.23
*/
public function getAssetsUrl()
{
if ($this->_assetsUrl === null) {
$this->_assetsUrl = Yii::app()->getAssetManager()->publish($this->getBasePath() . DIRECTORY_SEPARATOR . 'assets');
}
return $this->_assetsUrl;
}
/**
* Sets url assets.
* @param string $value assets url
* @since 2013.08.23
*/
public function setAssetsUrl($value)
{
$this->_assetsUrl = $value;
}
/**
* Returns the assets URL for a CSS asset.
* @param string $file CSS filename
* @return the url for the CSS file
* @since 2013.08.23
*/
public function getCssAssetsUrl($file)
{
return $this->assetsUrl . '/css/' . $file;
}
/**
* Return an image url stored in the assets.
* @param string $file the file's name.
* @return string image URL.
* @since 2013.08.23
*/
public function getImage($file)
{
return $this->getAssetsUrl() . '/images/' . $file;
}
/**
* Return URL of a script file in the module
* @param string $file the file's name
* @return string file URL
* @since 2013.08.23
*/
public function getScriptFile($file)
{
return $this->getAssetsUrl() . '/js/' . $file;
}
/**
* Register CSS files in the module.
* @param string $file the file.
* @param string $media the media.
* @since 2013.08.23
*/
public function registerCssFile($file, $media = 'all')
{
$url = $this->getAssetsUrl() . '/css/' . $file;
Yii::app()->clientScript->registerCssFile($url, $media);
}
/**
* Register a stript file in the module.
* @param string $file the file's name.
* @param int $position the script's position.
* @since 2013.08.23
*/
public function registerScriptFile($file, $position = 0)
{
$url = $this->getScriptFile($file);
Yii::app()->clientScript->registerScriptFile($url, $position);
}
}