forked from faravaghi/jalali-fullcalendar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
JFullCalendar.php
98 lines (81 loc) · 2.73 KB
/
JFullCalendar.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
<?php
class JFullCalendar extends CWidget
{
/**
* Html ID
* @var string
*/
public $id = 'calendar';
/**
* @var string Google's calendar URL.
*/
public $googleCalendarUrl;
/**
* @var string Theme's CSS file.
*/
public $themeCssFile;
/**
* @var array FullCalendar's options.
*/
public $options=array();
/**
* @var array HTML options.
*/
public $htmlOptions=array();
/**
* @var bool
*/
public $loadPrintCss=false;
/**
* @var string Language code as ./locale/<code>.php file
*/
public $lang;
public function run()
{
if ($this->lang) {
$this->registerLocale();
}
$this->registerFiles();
$this->showOutput();
}
protected function registerLocale()
{
$langFile=dirname(__FILE__).'/locale/'.$this->lang.'.php';
if (file_exists($langFile))
$this->options=CMap::mergeArray($this->options, include($langFile));
}
protected function registerFiles()
{
$assetsDir=(defined(__DIR__) ? __DIR__ : dirname(__FILE__)).'/assets';
$assets=Yii::app()->assetManager->publish($assetsDir);
$ext=defined('YII_DEBUG') ? 'js' : 'min.js';
$cs=Yii::app()->clientScript;
$cs->registerCoreScript('jquery');
$cs->registerScriptFile($assets.'/fullcalendar/jalali.js');
$cs->registerScriptFile($assets.'/fullcalendar/fullcalendar.'.$ext);
$cs->registerScriptFile($assets.'/fullcalendar/jquery-ui-1.8.23.custom.min.js');
/* $cs->registerCssFile($assets.'/fullcalendar/fullcalendar.css'); */
$cs->registerCssFile($assets.'/fullcalendar/fullcalendar_theme.css');
if ($this->loadPrintCss) {
$cs->registerCssFile($assets.'/fullcalendar/fullcalendar.print.css');
}
if ($this->googleCalendarUrl) {
$cs->registerScriptFile($assets.'/fullcalendar/gcal.js');
$this->options['events']=$this->googleCalendarUrl;
}
if ($this->themeCssFile) {
$this->options['theme']=true;
$cs->registerCssFile($assets.'/themes/'.$this->themeCssFile);
}
$BootBoxBaseUrl = Yii::app()->getAssetManager()->publish(Yii::getPathOfAlias('ext.bootbox'));
$cs->registerScriptFile($BootBoxBaseUrl . '/bootstrap.bootbox.min.js');
$js='var '. $this->id .' = $("#'.$this->id.'").fullCalendar('.CJavaScript::encode($this->options).');';
$cs->registerScript(__CLASS__.'#'.$this->id, $js, CClientScript::POS_READY);
}
protected function showOutput()
{
if (! isset($this->htmlOptions['id']))
$this->htmlOptions['id']=$this->id;
echo CHtml::tag('div', $this->htmlOptions,'');
}
}