/
field.date.php
814 lines (665 loc) · 26.2 KB
/
field.date.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
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
<?php
/**
* @package toolkit
*/
/**
* A simple Date field that stores a full ISO date. Symphony will attempt
* to localize the date on a per Author basis. The field essentially maps to
* PHP's `strtotime`, so it is very flexible in terms of what an Author can
* input into it.
*/
class FieldDate extends Field implements ExportableField, ImportableField
{
const SIMPLE = 0;
const REGEXP = 1;
const RANGE = 3;
const ERROR = 4;
private $key;
protected static $min_date = '1000-01-01 00:00:00';
protected static $max_date = '9999-12-31 23:59:59';
public function __construct()
{
parent::__construct();
$this->_name = __('Date');
$this->_required = true;
$this->key = 1;
$this->set('pre_populate', 'now');
$this->set('required', 'no');
$this->set('location', 'sidebar');
}
/*-------------------------------------------------------------------------
Definition:
-------------------------------------------------------------------------*/
public function canFilter()
{
return true;
}
public function isSortable()
{
return true;
}
public function canPrePopulate()
{
return true;
}
public function allowDatasourceOutputGrouping()
{
return true;
}
public function allowDatasourceParamOutput()
{
return true;
}
public function fetchFilterableOperators()
{
return array(
array(
'title' => 'is',
'filter' => ' ',
'help' => __('Find values that are an exact match for the given string.')
),
array(
'filter' => 'sql: NOT NULL',
'title' => 'is not empty',
'help' => __('Find entries where any value is selected.')
),
array(
'filter' => 'sql: NULL',
'title' => 'is empty',
'help' => __('Find entries where no value is selected.')
),
array(
'title' => 'contains',
'filter' => 'regexp: ',
'help' => __('Find values that match the given <a href="%s">MySQL regular expressions</a>.', array(
'https://dev.mysql.com/doc/mysql/en/regexp.html'
))
),
array(
'title' => 'does not contain',
'filter' => 'not-regexp: ',
'help' => __('Find values that do not match the given <a href="%s">MySQL regular expressions</a>.', array(
'https://dev.mysql.com/doc/mysql/en/regexp.html'
))
),
array(
'title' => 'later than',
'filter' => 'later than '
),
array(
'title' => 'earlier than',
'filter' => 'earlier than '
),
array(
'title' => 'equal to or later than',
'filter' => 'equal to or later than '
),
array(
'title' => 'equal to or earlier than',
'filter' => 'equal to or earlier than '
),
);
}
public function fetchSuggestionTypes()
{
return array('date');
}
/*-------------------------------------------------------------------------
Setup:
-------------------------------------------------------------------------*/
public function createTable()
{
return Symphony::Database()->query(
"CREATE TABLE IF NOT EXISTS `tbl_entries_data_" . $this->get('id') . "` (
`id` int(11) unsigned NOT null auto_increment,
`entry_id` int(11) unsigned NOT null,
`value` varchar(80) default null,
`date` DATETIME default null,
PRIMARY KEY (`id`),
UNIQUE KEY `entry_id` (`entry_id`),
KEY `value` (`value`),
KEY `date` (`date`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"
);
}
/*-------------------------------------------------------------------------
Utilities:
-------------------------------------------------------------------------*/
/**
* Given a string, this function builds the range of dates that match it.
* The strings should be in ISO8601 style format, or a natural date, such
* as 'last week' etc.
*
* @since Symphony 2.2.2
* @param array $string
* The date string to be parsed
* @param string $direction
* Either later or earlier, defaults to null.
* @param boolean $equal_to
* If the filter is equal_to or not, defaults to false.
* @return array
* An associative array containing a date in ISO8601 format (or natural)
* with two keys, start and end.
*/
public static function parseDate($string, $direction = null, $equal_to = false)
{
$parts = array(
'start' => null,
'end' => null
);
// Year
if (preg_match('/^\d{1,4}$/', $string, $matches)) {
$year = current($matches);
$parts['start'] = "$year-01-01 00:00:00";
$parts['end'] = "$year-12-31 23:59:59";
$parts = self::isEqualTo($parts, $direction, $equal_to);
// Year/Month/Day/Time
} elseif (preg_match('/^\d{1,4}[-\/]\d{1,2}[-\/]\d{1,2}\s\d{1,2}:\d{2}/', $string, $matches)) {
// Handles the case of `to` filters
if ($equal_to || is_null($direction)) {
$parts['start'] = $parts['end'] = DateTimeObj::get('Y-m-d H:i:s', $string);
} else {
$parts['start'] = DateTimeObj::get('Y-m-d H:i:s', $string . ' - 1 second');
$parts['end'] = DateTimeObj::get('Y-m-d H:i:s', $string . ' + 1 second');
}
// Year/Month/Day
} elseif (preg_match('/^\d{1,4}[-\/]\d{1,2}[-\/]\d{1,2}$/', $string, $matches)) {
$year_month_day = current($matches);
$parts['start'] = "$year_month_day 00:00:00";
$parts['end'] = "$year_month_day 23:59:59";
$parts = self::isEqualTo($parts, $direction, $equal_to);
// Year/Month
} elseif (preg_match('/^\d{1,4}[-\/]\d{1,2}$/', $string, $matches)) {
$year_month = current($matches);
$parts['start'] = "$year_month-01 00:00:00";
$parts['end'] = DateTimeObj::get('Y-m-t', $parts['start']) . " 23:59:59";
$parts = self::isEqualTo($parts, $direction, $equal_to);
// Relative date, aka '+ 3 weeks'
} else {
// Handles the case of `to` filters
if ($equal_to || is_null($direction)) {
$parts['start'] = $parts['end'] = DateTimeObj::get('Y-m-d H:i:s', $string);
} else {
$parts['start'] = DateTimeObj::get('Y-m-d H:i:s', $string . ' - 1 second');
$parts['end'] = DateTimeObj::get('Y-m-d H:i:s', $string . ' + 1 second');
}
}
return $parts;
}
/**
* Builds the correct date array depending if the filter should include
* the filter as well, ie. later than 2011, is effectively the same as
* equal to or later than 2012.
*
* @since Symphony 2.2.2
* @param array $parts
* An associative array containing a date in ISO8601 format (or natural)
* with two keys, start and end.
* @param string $direction
* Either later or earlier, defaults to null.
* @param boolean $equal_to
* If the filter is equal_to or not, defaults to false.
* @return array
*/
public static function isEqualTo(array $parts, $direction, $equal_to = false)
{
if (!$equal_to) {
return $parts;
}
if ($direction == 'later') {
$parts['end'] = $parts['start'];
} else {
$parts['start'] = $parts['end'];
}
return $parts;
}
public static function parseFilter(&$string)
{
$string = self::cleanFilterString($string);
// Relative check, earlier or later
if (preg_match('/^(equal to or )?(earlier|later) than (.*)$/i', $string, $match)) {
$string = $match[3];
// Validate date
if (!DateTimeObj::validate($string)) {
return self::ERROR;
}
// Date is equal to or earlier/later than
// Date is earlier/later than
$parts = self::parseDate($string, $match[2], $match[1] == "equal to or ");
$earlier = $parts['start'];
$later = $parts['end'];
// Switch between earlier than and later than logic
// The earlier/later range is defined by MySQL's support. RE: #1560
// @link https://dev.mysql.com/doc/refman/en/datetime.html
switch ($match[2]) {
case 'later':
$string = $later . ' to ' . self::$max_date;
break;
case 'earlier':
$string = self::$min_date . ' to ' . $earlier;
break;
}
// Look to see if its a shorthand date (year only), and convert to full date
// Look to see if the give date is a shorthand date (year and month) and convert it to full date
// Match single dates
} elseif (
preg_match('/^(1|2)\d{3}$/i', $string)
|| preg_match('/^(1|2)\d{3}[-\/]\d{1,2}$/i', $string)
|| !preg_match('/\s+to\s+/i', $string)
) {
// Validate
if (!DateTimeObj::validate($string)) {
return self::ERROR;
}
$parts = self::parseDate($string);
$string = $parts['start'] . ' to ' . $parts['end'];
// Match date ranges
} elseif (preg_match('/\s+to\s+/i', $string)) {
if (!$parts = preg_split('/\s+to\s+/', $string, 2, PREG_SPLIT_NO_EMPTY)) {
return self::ERROR;
}
foreach ($parts as $i => &$part) {
// Validate
if (!DateTimeObj::validate($part)) {
return self::ERROR;
}
$part = self::parseDate($part);
}
$string = $parts[0]['start'] . " to " . $parts[1]['end'];
}
// Parse the full date range and return an array
if (!$parts = preg_split('/\s+to\s+/i', $string, 2, PREG_SPLIT_NO_EMPTY)) {
return self::ERROR;
}
$parts = array_map(array('self', 'cleanFilterString'), $parts);
list($start, $end) = $parts;
// Validate
if (!DateTimeObj::validate($start) || !DateTimeObj::validate($end)) {
return self::ERROR;
}
$string = array('start' => $start, 'end' => $end);
return self::RANGE;
}
public static function cleanFilterString($string)
{
$string = trim($string, ' -/');
return urldecode($string);
}
public function buildRangeFilterSQL($data, &$joins, &$where, $andOperation = false)
{
$field_id = $this->get('id');
if (empty($data)) {
return;
}
if ($andOperation) {
foreach ($data as $date) {
// Prevent the DateTimeObj creating a range that isn't supported by MySQL.
$start = ($date['start'] === self::$min_date) ? self::$min_date : DateTimeObj::getGMT('Y-m-d H:i:s', $date['start']);
$end = ($date['end'] === self::$max_date) ? self::$max_date : DateTimeObj::getGMT('Y-m-d H:i:s', $date['end']);
$joins .= " LEFT JOIN `tbl_entries_data_$field_id` AS `t$field_id".$this->key."` ON `e`.`id` = `t$field_id".$this->key."`.entry_id ";
$where .= " AND (`t$field_id".$this->key."`.date >= '" . $start . "' AND `t$field_id".$this->key."`.date <= '" . $end . "') ";
$this->key++;
}
} else {
$tmp = array();
foreach ($data as $date) {
// Prevent the DateTimeObj creating a range that isn't supported by MySQL.
$start = ($date['start'] === self::$min_date) ? self::$min_date : DateTimeObj::getGMT('Y-m-d H:i:s', $date['start']);
$end = ($date['end'] === self::$max_date) ? self::$max_date : DateTimeObj::getGMT('Y-m-d H:i:s', $date['end']);
$tmp[] = "`t$field_id".$this->key."`.date >= '" . $start . "' AND `t$field_id".$this->key."`.date <= '" . $end . "' ";
}
$joins .= " LEFT JOIN `tbl_entries_data_$field_id` AS `t$field_id".$this->key."` ON `e`.`id` = `t$field_id".$this->key."`.entry_id ";
$where .= " AND (".implode(' OR ', $tmp).") ";
$this->key++;
}
}
/**
* Format the $data parameter according to this field's settings.
*
* @since Symphony 2.6.0
* @param array $date
* The date to format
* @return string
*/
public function formatDate($date)
{
// Get format
$format = 'date_format';
if ($this->get('time') === 'yes') {
$format = 'datetime_format';
}
return DateTimeObj::format($date, DateTimeObj::getSetting($format));
}
/*-------------------------------------------------------------------------
Settings:
-------------------------------------------------------------------------*/
public function findDefaults(array &$settings)
{
if (!isset($settings['pre_populate'])) {
$settings['pre_populate'] = $this->get('pre_populate');
}
}
public function displaySettingsPanel(XMLElement &$wrapper, $errors = null)
{
parent::displaySettingsPanel($wrapper, $errors);
// Default date
$label = Widget::Label(__('Default date'));
$help = new XMLElement('i', __('optional, accepts absolute or relative dates'));
$input = Widget::Input('fields['.$this->get('sortorder').'][pre_populate]', $this->get('pre_populate') ? $this->get('pre_populate') : '', 'input');
$label->appendChild($help);
$label->appendChild($input);
$wrapper->appendChild($label);
// Display settings
$div = new XMLElement('div', null, array('class' => 'two columns'));
$this->createCheckboxSetting($div, 'time', __('Display time'));
$this->createCheckboxSetting($div, 'calendar', __('Show calendar'));
$wrapper->appendChild($div);
// Requirements and table display
$this->appendStatusFooter($wrapper);
}
public function commit()
{
if (!parent::commit()) {
return false;
}
$id = $this->get('id');
if ($id === false) {
return false;
}
$fields = array();
$fields['pre_populate'] = ($this->get('pre_populate') ? $this->get('pre_populate') : '');
$fields['time'] = ($this->get('time') ? $this->get('time') : 'no');
$fields['calendar'] = ($this->get('calendar') ? $this->get('calendar') : 'no');
return FieldManager::saveSettings($id, $fields);
}
/*-------------------------------------------------------------------------
Publish:
-------------------------------------------------------------------------*/
public function displayPublishPanel(XMLElement &$wrapper, $data = null, $flagWithError = null, $fieldnamePrefix = null, $fieldnamePostfix = null, $entry_id = null)
{
$name = $this->get('element_name');
$value = null;
// New entry
if (empty($data) && is_null($flagWithError) && !is_null($this->get('pre_populate'))) {
$prepopulate = $this->get('pre_populate');
$date = self::parseDate($prepopulate);
$date = $date['start'];
$value = $this->formatDate($date);
// Error entry, display original data
} elseif (!is_null($flagWithError)) {
$value = $_POST['fields'][$name];
// Empty entry
} elseif (isset($data['value'])) {
$value = $this->formatDate($data['value']);
}
$label = Widget::Label($this->get('label'));
if ($this->get('required') !== 'yes') {
$label->appendChild(new XMLElement('i', __('Optional')));
}
// Input
$label->appendChild(Widget::Input("fields{$fieldnamePrefix}[{$name}]", $value));
$label->setAttribute('class', 'date');
if (!is_null($flagWithError)) {
$label = Widget::Error($label, $flagWithError);
}
// Calendar
if ($this->get('calendar') === 'yes') {
$wrapper->setAttribute('data-interactive', 'data-interactive');
$ul = new XMLElement('ul');
$ul->setAttribute('class', 'suggestions');
$ul->setAttribute('data-field-id', $this->get('id'));
$ul->setAttribute('data-search-types', 'date');
$calendar = new XMLElement('li');
$calendar->appendChild(Widget::Calendar(($this->get('time') === 'yes')));
$ul->appendChild($calendar);
$label->appendChild($ul);
}
$wrapper->appendChild($label);
}
public function checkPostFieldData($data, &$message, $entry_id = null)
{
$message = null;
// If this field is required
if ($this->get('required') === 'yes' && strlen(trim($data)) == 0) {
$message = __('‘%s’ is a required field.', array($this->get('label')));
return self::__MISSING_FIELDS__;
} elseif (empty($data)) {
return self::__OK__;
}
// Handle invalid dates
if (!DateTimeObj::validate($data)) {
$message = __('The date specified in ‘%s’ is invalid.', array($this->get('label')));
return self::__INVALID_FIELDS__;
}
return self::__OK__;
}
public function processRawFieldData($data, &$status, &$message = null, $simulate = false, $entry_id = null)
{
$status = self::__OK__;
$timestamp = null;
// Prepopulate date
if (is_null($data) || $data == '') {
if ($this->get('pre_populate') !='') {
$date = self::parseDate($this->get('pre_populate'));
$date = $date['start'];
$timestamp = $this->formatDate($date);
}
// Convert given date to timestamp
} elseif ($status == self::__OK__ && DateTimeObj::validate($data)) {
$timestamp = DateTimeObj::get('U', $data);
}
// Valid date
if (!is_null($timestamp)) {
return array(
'value' => DateTimeObj::get('c', $timestamp),
'date' => DateTimeObj::getGMT('Y-m-d H:i:s', $timestamp)
);
// Invalid date
} else {
return array(
'value' => null,
'date' => null
);
}
}
/*-------------------------------------------------------------------------
Output:
-------------------------------------------------------------------------*/
public function appendFormattedElement(XMLElement &$wrapper, $data, $encode = false, $mode = null, $entry_id = null)
{
if (isset($data['value'])) {
// Get date
if (is_array($data['value'])) {
$date = current($data['value']);
} else {
$date = $data['value'];
}
$wrapper->appendChild(General::createXMLDateObject($date, $this->get('element_name')));
}
}
public function prepareTextValue($data, $entry_id = null)
{
$value = '';
if (isset($data['value'])) {
$value = $this->formatDate($data['value']);
}
return $value;
}
public function getParameterPoolValue(array $data, $entry_id = null)
{
return DateTimeObj::get('Y-m-d H:i:s', $data['value']);
}
/*-------------------------------------------------------------------------
Import:
-------------------------------------------------------------------------*/
public function getImportModes()
{
return array(
'getValue' => ImportableField::STRING_VALUE,
'getPostdata' => ImportableField::ARRAY_VALUE
);
}
public function prepareImportValue($data, $mode, $entry_id = null)
{
$value = $status = $message = null;
$modes = (object)$this->getImportModes();
// Prepopulate date:
if ($data === null || $data === '') {
if (!is_null($this->get('pre_populate'))) {
$timestamp = self::parseDate($this->get('pre_populate'));
$timestamp = $timestamp['start'];
}
// DateTime to timestamp:
} elseif ($data instanceof DateTime) {
$timestamp = $data->getTimestamp();
// Convert given date to timestamp:
} elseif (DateTimeObj::validate($data)) {
$timestamp = DateTimeObj::get('U', $data);
}
// Valid date found:
if (isset($timestamp)) {
$value = DateTimeObj::get('c', $timestamp);
}
if ($mode === $modes->getValue) {
return $value;
} elseif ($mode === $modes->getPostdata) {
return $this->processRawFieldData($data, $status, $message, true, $entry_id);
}
return null;
}
/*-------------------------------------------------------------------------
Export:
-------------------------------------------------------------------------*/
/**
* Return a list of supported export modes for use with `prepareExportValue`.
*
* @return array
*/
public function getExportModes()
{
return array(
'getValue' => ExportableField::VALUE,
'getObject' => ExportableField::OBJECT,
'getPostdata' => ExportableField::POSTDATA
);
}
/**
* Give the field some data and ask it to return a value using one of many
* possible modes.
*
* @param mixed $data
* @param integer $mode
* @param integer $entry_id
* @return DateTime|null
*/
public function prepareExportValue($data, $mode, $entry_id = null)
{
$modes = (object)$this->getExportModes();
if ($mode === $modes->getValue) {
return $this->formatDate(
isset($data['value']) ? $data['value'] : null
);
}
if ($mode === $modes->getObject) {
$timezone = Symphony::Configuration()->get('timezone', 'region');
$date = new DateTime(
isset($data['value']) ? $data['value'] : 'now'
);
$date->setTimezone(new DateTimeZone($timezone));
return $date;
} elseif ($mode === $modes->getPostdata) {
return isset($data['value'])
? $data['value']
: null;
}
return null;
}
/*-------------------------------------------------------------------------
Filtering:
-------------------------------------------------------------------------*/
public function buildDSRetrievalSQL($data, &$joins, &$where, $andOperation = false)
{
if (self::isFilterRegex($data[0])) {
$this->buildRegexSQL($data[0], array('value'), $joins, $where);
} elseif (self::isFilterSQL($data[0])) {
$this->buildFilterSQL($data[0], array('value'), $joins, $where);
} else {
$parsed = array();
// For the filter provided, loop over each piece
foreach ($data as $string) {
$type = self::parseFilter($string);
if ($type == self::ERROR) {
return false;
}
if (!is_array($parsed[$type])) {
$parsed[$type] = array();
}
$parsed[$type][] = $string;
}
foreach ($parsed as $value) {
$this->buildRangeFilterSQL($value, $joins, $where, $andOperation);
}
}
return true;
}
/*-------------------------------------------------------------------------
Sorting:
-------------------------------------------------------------------------*/
public function buildSortingSQL(&$joins, &$where, &$sort, $order = 'ASC')
{
if ($this->isRandomOrder($order)) {
$sort = 'ORDER BY RAND()';
} else {
$sort = sprintf(
'ORDER BY (
SELECT %s
FROM tbl_entries_data_%d AS `ed`
WHERE entry_id = e.id
) %s',
'`ed`.date',
$this->get('id'),
$order
);
}
}
public function buildSortingSelectSQL($sort, $order = 'ASC')
{
return null;
}
/*-------------------------------------------------------------------------
Grouping:
-------------------------------------------------------------------------*/
public function groupRecords($records)
{
if (!is_array($records) || empty($records)) {
return;
}
$groups = array('year' => array());
foreach ($records as $r) {
$data = $r->getData($this->get('id'));
$timestamp = DateTimeObj::get('U', $data['value']);
$info = getdate($timestamp);
$year = $info['year'];
$month = ($info['mon'] < 10 ? '0' . $info['mon'] : $info['mon']);
if (!isset($groups['year'][$year])) {
$groups['year'][$year] = array(
'attr' => array('value' => $year),
'records' => array(),
'groups' => array()
);
}
if (!isset($groups['year'][$year]['groups']['month'])) {
$groups['year'][$year]['groups']['month'] = array();
}
if (!isset($groups['year'][$year]['groups']['month'][$month])) {
$groups['year'][$year]['groups']['month'][$month] = array(
'attr' => array('value' => $month),
'records' => array(),
'groups' => array()
);
}
$groups['year'][$year]['groups']['month'][$month]['records'][] = $r;
}
return $groups;
}
}