forked from pdrakeweb/Drupal-FullCalendar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviews_plugin_style_fullcalendar_ajax_json.inc
executable file
·198 lines (193 loc) · 7.26 KB
/
views_plugin_style_fullcalendar_ajax_json.inc
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<?php
// require_once(drupal_get_path('module', 'views_ajax_endpoint') . '/views_plugin_style_ajax.inc');
class views_plugin_style_fullcalendar_ajax_json extends views_plugin_style {
/**
* Set default options.
*/
function option_definition() {
$options = parent::option_definition();
$options['field'] = 0;
$options['index'] = 0;
$options['nid'] = 0;
$options['title'] = 0;
$options['start'] = 0;
$options['end'] = 0;
$options['url'] = 0;
$options['allDay'] = 0;
$options['className'] = 0;
$options['editable'] = 0;
$options['description'] = 0;
$options['daily_limit'] = '';
return $options;
}
/**
* Extend the options form.
*/
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
// Style types
$fields = array(0 => '<'. t('None') .'>');
foreach ($this->view->display_handler->get_option('fields') as $field => $definition) {
$fields[$field] = !empty($definition['label']) ? $definition['label'] : $field;
}
$form['field'] = array(
'#title' => t('Field'),
'#description' => t('Choose a field to be used for field updates.'),
'#type' => 'select',
'#options' => $fields,
'#default_value' => $this->options['field'],
);
$form['index'] = array(
'#title' => t('index'),
'#description' => t('Choose a field to be used for index (delta) items.'),
'#type' => 'select',
'#options' => $fields,
'#default_value' => $this->options['index'],
);
$form['nid'] = array(
'#title' => t('nid'),
'#description' => t('Choose a field to be used for the nid.'),
'#type' => 'select',
'#options' => $fields,
'#default_value' => $this->options['nid'],
);
$form['title'] = array(
'#title' => t('title'),
'#description' => t('Choose a field to be used for the title.'),
'#type' => 'select',
'#options' => $fields,
'#default_value' => $this->options['title'],
);
$form['start'] = array(
'#title' => t('start'),
'#description' => t('Choose a field to be used for start date.'),
'#type' => 'select',
'#options' => $fields,
'#default_value' => $this->options['start'],
);
$form['end'] = array(
'#title' => t('end'),
'#description' => t('Choose a field to be used for end date.'),
'#type' => 'select',
'#options' => $fields,
'#default_value' => $this->options['end'],
);
$form['url'] = array(
'#title' => t('url'),
'#description' => t('Choose a field to be used for the URL.'),
'#type' => 'select',
'#options' => $fields,
'#default_value' => $this->options['url'],
);
$form['allDay'] = array(
'#title' => t('allDay'),
'#description' => t('Choose a field to be used for the allDay status.'),
'#type' => 'select',
'#options' => $fields,
'#default_value' => $this->options['allDay'],
);
$form['className'] = array(
'#title' => t('className'),
'#description' => t('Choose a field to be used for the className.'),
'#type' => 'select',
'#options' => $fields,
'#default_value' => $this->options['className'],
);
$form['editable'] = array(
'#title' => t('editable'),
'#description' => t('Choose a field to be used for edit status of the item.'),
'#type' => 'select',
'#options' => $fields,
'#default_value' => $this->options['editable'],
);
$form['description'] = array(
'#title' => t('description'),
'#description' => t('Choose a field to be used for the description of the item.'),
'#type' => 'select',
'#options' => $fields,
'#default_value' => $this->options['description'],
);
$form['daily_limit'] = array(
'#type' => 'textfield',
'#title' => t('Daily Event Limit'),
'#default_value' => $this->options['daily_limit'],
'#description' => t("(Advanced) Limit the number of events per day which will be returned."),
);
}
function query() {
if (!empty($this->options['daily_limit'])) {
$this->view->query->add_field(NULL, "date_format(STR_TO_DATE(" . $this->view->field[$this->options['start']]->options['table'] . '.' . $this->view->field[$this->options['start']]->options['field'] . ", '%Y-%m-%%dT%T'), '%Y-%m-%%d')", 'daily_limiter');
$this->view->query->orderby = array();
$this->view->query->add_orderby($this->view->field[$this->options['start']]->options['table'], $this->view->field[$this->options['start']]->options['field'], 'ASC');
}
}
function render() {
$output = parent::render();
drupal_set_header('Content-type: text/javascript; charset=utf-8');
$jsonoutput = array();
if (!empty($this->options['daily_limit'])) {
$n = array();
$k = $this->options['daily_limit'];
}
if (empty($this->rendered_fields)) {
return drupal_to_js($jsonoutput);
}
foreach ($this->rendered_fields as $field) {
$structure = array();
$include_event = true;
foreach ($this->options as $key => $value) {
if (!is_null($value) && $value && ($value != "0")) {
$structure[$key] = $field[$value];
}
if ($key == 'recurring') {
$structure[$key] = FALSE;
}
if ($key == 'allDay') {
$structure[$key] = FALSE;
}
if ($key == 'className') {
$structure[$key] = 'crayon crayon-' . theme('seed_crayon', $field[$value]);
}
if ($key == 'field') {
$structure[$key] = "field_date";
}
if ($key == 'start') {
$structure[$key] = array_pop(explode(' ', strip_tags($field[$value])));
if (!empty($k) && $n[substr($structure[$key],0,10)]++ > $k) {
$include_event = false;
break;
} elseif (!empty($k) && $n[substr($structure[$key],0,10)] == $k) {
$structure['title'] = 'More Events';
$structure['url'] = '#'.$structure[$key];
$structure['className'] = 'viewmore';
$structure['start'] = substr($structure[$key],0,10).'T24:00';
$structure['flyout'] = false;
break;
}
}
if ($key == 'end') {
$structure[$key] = array_shift(explode(' ', strip_tags($field[$value])));
}
}
if ($include_event) {
// Add unexcluded rendered fields to flyout. This is should be in a seperate theme func.
// @todo - This doesn't work, but it feels right. :)
//$structure['flyout'] = theme(array('views_view_fields'), $this->view, $this->options, $row, 'nid');
if (!isset($structure['flyout'])) {
$structure['flyout'] = '<span class="crayon-popup"><span class="crayon-popup-label">';
foreach ($this->display->display_options['fields'] as $field_name => $options) {
if (empty($options['exclude'])) {
$structure['flyout'] .= '<div>' . $field[$field_name] . '</div>';
}
}
if (spaces_access_admin()) {
$structure['flyout'] .= l('Edit', 'node/' . $field['nid'] . '/edit/nojs', array('attributes' => array('class' => 'ctools-use-modal')));
}
$structure['flyout'] .= '</span></span>';
}
$jsonoutput[] = $structure;
}
}
return drupal_to_js($jsonoutput);
}
}