1: <?php
2:
3: namespace ZCL\Calendar;
4: /**
5: * компонент fullcalendars
6: */
7: class Calendar extends \Zippy\Html\HtmlComponent implements \Zippy\Interfaces\Requestable, \Zippy\Interfaces\AjaxRender
8: {
9:
10: private $lang='ru';
11: private $event = null;
12: private $data = array();
13: private $view = 'dayGridMonth';
14:
15: public function __construct($id,$lang='ru') {
16: parent::__construct($id);
17: $this->view = 'dayGridMonth';
18: $this->lang = $lang;
19: }
20:
21: public final function RenderImpl() {
22:
23: $id = $this->getAttribute('id');
24: $url = $this->owner->getURLNode() . "::" . $this->id;
25:
26: if (count($this->data) > 0) {
27: $ev = ",events: [";
28: foreach ($this->data as $dt) {
29:
30: $ev .= " { id : '{$dt->id}',
31: title : '{$dt->title}',
32: start : {$dt->start} ,
33: end : {$dt->end} ,
34: backgroundColor: '{$dt->color}',
35:
36: allDay : false },";
37: }
38: $ev = rtrim($ev, ',');
39: $ev .= "]";
40: }
41:
42: $js = <<<EOT
43:
44: var calendarEl = document.getElementById('{$id}');
45: var Calendar = FullCalendar.Calendar;
46:
47: var calendar = new Calendar(calendarEl, {
48:
49: headerToolbar: {
50: left : 'prev,next today',
51: center: 'title',
52: right : 'dayGridMonth,timeGridWeek,timeGridDay'
53: },
54: initialView: '{$this->view}' ,
55:
56: themeSystem: 'bootstrap' ,
57: editable: true,
58: droppable: true,
59:
60: eventClick: function(info) {
61: var url ='{$url}:' + 'click:'+ info.event.id ;
62:
63: window.location= url;
64:
65:
66: },
67: dateClick: function(info) {
68:
69: var url ='{$url}:' + 'add:'+ info.dateStr;
70:
71: window.location= url;
72:
73:
74: },
75:
76: eventResize: function(info) {
77:
78:
79: var url ='{$url}:' + 'resize:'+ info.event.id +':' + info.startDelta.milliseconds + ':' + info.endDelta.milliseconds +'&ajax=true' ;
80:
81: // window.location= url;
82: getUpdate(url) ;
83:
84: } ,
85: eventDrop: function(info) {
86:
87: var url ='{$url}:' + 'move:'+ info.event.id +':' + info.delta.years+':' + info.delta.months+':' + info.delta.days+':' + info.delta.milliseconds +'&ajax=true' ;
88:
89: // window.location= url;
90: getUpdate(url) ;
91:
92: } ,
93: locale: '{$this->lang}'
94: {$ev}
95:
96:
97:
98:
99:
100:
101: });
102:
103: calendar.render();
104: EOT;
105:
106: \Zippy\WebApplication::$app->getResponse()->addJavaScript($js, true);
107: }
108:
109: public final function RequestHandle() {
110: $params = \Zippy\WebApplication::$app->getRequest()->request_params[$this->id];
111: $action = array();
112:
113: $action['action'] = $params[0];
114: $action['id'] = $params[1];
115: $action['startdelta'] = $params[2];
116: $action['enddelta'] = $params[3];
117: $action['years'] = $params[2];
118: $action['months'] = $params[3];
119: $action['days'] = $params[4];
120: $action['ms'] = $params[5];
121:
122: if ($action['action'] == 'add') {
123: $dt = $params[1] . ':' . $params[2] . ':' . $params[3];
124: $action['date'] = strtotime($dt);
125: }
126: if ($action['action'] == 'resize') {
127: $action['startdelta'] = $action['startdelta'] / 1000;
128: $action['enddelta'] = $action['enddelta'] / 1000;
129: }
130: if ($action['action'] == 'move') {
131: $action['years'] = $action['years'];
132: $action['month'] = $action['month'];
133: $action['days'] = $action['days'];
134: $action['ms'] = $action['ms'] / 1000;
135: }
136:
137: if ($this->event != null) {
138: $this->event->onEvent($this, $action);
139: }
140: }
141:
142: public function setEvent(\Zippy\Interfaces\EventReceiver $receiver, $handler) {
143:
144: $this->event = new \Zippy\Event($receiver, $handler);
145: }
146:
147: public function setData($data) {
148: $this->data = $data;
149: }
150:
151: public function AjaxAnswer() {
152:
153: return '';
154: }
155:
156: }
157:
158: class CEvent
159: {
160:
161: public $id, $title, $start, $end, $color;
162:
163: public function __construct($id, $title, $start, $end, $color) {
164: $this->id = $id;
165: $this->title = $title;
166: $this->start = "new Date(" . date("Y", $start) . ", " . (date("m", $start) - 1) . ", " . date("d", $start) . "," . date("H", $start) . "," . date("i", $start) . ")";
167: $this->end = "new Date(" . date("Y", $end) . ", " . (date("m", $end) - 1) . ", " . date("d", $end) . "," . date("H", $end) . "," . date("i", $end) . ")";
168: // $this->end = date("Y-m-dTH:i", $end);
169: $this->color = $color;
170: }
171:
172: }
173: