1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
class TrainingHolder extends Page |
|
|
|
|
4
|
|
|
{ |
5
|
|
|
private static $icon = "mysite/images/treeicons/TrainingHolder"; |
|
|
|
|
6
|
|
|
|
7
|
|
|
//parents and children in sitetree |
8
|
|
|
private static $allowed_children = array("TrainingPage"); //can also be "none"; |
|
|
|
|
9
|
|
|
private static $default_child = "TrainingPage"; |
|
|
|
|
10
|
|
|
|
11
|
|
|
public function canCreate($member = null) |
12
|
|
|
{ |
13
|
|
|
return TrainingHolder::get()->count() ? false: true; |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
public function canDelete($member = null) |
17
|
|
|
{ |
18
|
|
|
return false; |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function getCMSFields() |
|
|
|
|
22
|
|
|
{ |
23
|
|
|
$fields = parent::getCMSFields(); |
24
|
|
|
return $fields; |
25
|
|
|
} |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
class TrainingHolder_Controller extends Page_Controller |
|
|
|
|
29
|
|
|
{ |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* |
33
|
|
|
* @return ArrayList |
34
|
|
|
*/ |
35
|
|
|
public function MonthlyCourses() |
36
|
|
|
{ |
37
|
|
|
$results = new ArrayList(); |
38
|
|
|
|
39
|
|
|
$stage = Versioned::current_stage(); |
40
|
|
|
$suffix = (!$stage || $stage == 'Stage') ? "" : "_$stage"; |
41
|
|
|
|
42
|
|
|
$sqlResults = DB::query("
|
43
|
|
|
SELECT DISTINCT MONTH(\"Date\") AS \"Month\", YEAR(\"Date\") AS \"Year\"
|
44
|
|
|
FROM \"SiteTree$suffix\" NATURAL JOIN \"TrainingPage$suffix\"
|
45
|
|
|
WHERE \"ParentID\" = ".$this->ID." AND \"Date\" > CONVERT_TZ(now(),'+00:00','+13:00')
|
46
|
|
|
ORDER BY \"Year\" DESC, \"Month\" ASC;" |
47
|
|
|
); |
48
|
|
|
|
49
|
|
|
if ($sqlResults) { |
50
|
|
|
foreach ($sqlResults as $sqlResult) { |
51
|
|
|
$month = (isset($sqlResult['Month'])) ? (int) $sqlResult['Month'] : 1; |
52
|
|
|
$year = ($sqlResult['Year']) ? (int) $sqlResult['Year'] : date('Y'); |
53
|
|
|
|
54
|
|
|
$date = DBField::create_field('Date', array( |
55
|
|
|
'Day' => 1, |
56
|
|
|
'Month' => $month, |
57
|
|
|
'Year' => $year |
58
|
|
|
)); |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
$results->push(new ArrayData(array( |
62
|
|
|
'Date' => $date, |
63
|
|
|
'Courses' => TrainingPage::get() |
64
|
|
|
->filter(array("ShowInMenus" => 1)) |
65
|
|
|
->where(" MONTH(\"TrainingPage\".\"Date\") = $month AND YEAR(\"TrainingPage\".\"Date\") = $year") |
66
|
|
|
))); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
return $results; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|