-
Notifications
You must be signed in to change notification settings - Fork 0
/
ECalendarViewDataProvider.php
executable file
·74 lines (63 loc) · 1.92 KB
/
ECalendarViewDataProvider.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
<?php
/**
* ECalendarViewDataProvider.php
*
* @author Martin Ludvik <matolud@gmail.com>
* @copyright Copyright © 2014 by Martin Ludvik
* @license http://opensource.org/licenses/MIT MIT license
*/
Yii::import('ecalendarview.ECalendarViewItem');
Yii::import('ecalendarview.ECalendarViewPagination');
/**
* The data provider prepares data to be shown by {@link ECalendarView}.
*/
class ECalendarViewDataProvider extends CComponent {
/**
* @var ECalendarViewPagination The pagination.
*/
private $_pagination;
/**
* Constructs the data provider and sets it's attributes to default values.
* @param array $config The attributes as key=>value map.
*/
public function __construct(array $config = array()) {
$this->_pagination = new ECalendarViewPagination();
foreach($config as $key => $value) {
$this->$key = $value;
}
}
/**
* Sets the pagination's attributes.
* @param array $config The attributes as key=>value map.
*/
public function setPagination(array $config) {
foreach($config as $key => $value) {
$this->getPagination()->$key = $value;
}
}
/**
* @see ECalendarViewDataProvider::$_pagination
*/
public function getPagination() {
return $this->_pagination;
}
/**
* Retrieves the data.
* @return array The array of {@link ECalendarViewItem}s.
*/
public function getData() {
$data = array();
$startDate = $this->getPagination()->getFirstPageDate();
$endDate = $this->getPagination()->getLastPageDate();
$dateIterator = clone($startDate);
while($dateIterator <= $endDate) {
$data[] = new ECalendarViewItem(array(
'date' => clone($dateIterator),
'isCurrentDate' => $this->getPagination()->isCurrentDate($dateIterator),
'isRelevantDate' => $this->getPagination()->isRelevantDate($dateIterator),
));
$dateIterator->add(new DateInterval('P1D'));
}
return $data;
}
}