1 <?php
2
3 4 5 6 7 8
9 class News_Controller extends Page_Controller {
10
11 protected $view;
12 protected $year;
13 protected $month;
14 protected $day;
15 protected $start_date;
16 protected $end_date;
17
18 19 20
21 public function parseURL() {
22 if ($this->urlParams['Action'] && $this->urlParams['Action'] == "view") {
23 $this->start_date = new sfDate(CalendarUtil::getDateFromString($this->urlParams['ID']));
24
25 if (isset($this->urlParams['OtherID'])) {
26 $this->view = "range";
27 $this->end_date = new sfDate(CalendarUtil::getDateFromString(str_replace("-", "", $this->urlParams['OtherID'])));
28 }
29
30
31 else {
32 switch (strlen(str_replace("-", "", $this->urlParams['ID']))) {
33 case 8:
34 $this->view = "day";
35 $this->end_date = new sfDate($this->start_date->get() + 1);
36 $this->year = $this->start_date->format('Y');
37 $this->month = $this->end_date->format('m');
38 $this->day = $this->end_date->format('d');
39 break;
40
41 case 6:
42 $this->view = "month";
43 $this->end_date = new sfDate($this->start_date->finalDayOfMonth()->date());
44 $this->year = $this->start_date->format('Y');
45 $this->month = $this->end_date->format('m');
46 break;
47
48 case 4:
49 $this->view = "year";
50 $this->end_date = new sfDate($this->start_date->finalDayOfYear()->date());
51 $this->year = $this->start_date->format('Y');
52 break;
53
54 default:
55 $this->view = "default";
56 $this->end_date = new sfDate($this->start_date->addMonth(Calendar::$defaultFutureMonths)->date());
57 break;
58 }
59 }
60 } else {
61
62
63
64 $this->view = "default";
65 $this->start_date = new sfDate(date('Y-m-d'));
66 $this->end_date = new sfDate($this->start_date->addMonth(6)->date());
67 }
68 $this->start_date->reset();
69 }
70
71 public function NewsCalendar() {
72 if ($holder = $this->getNewsHolder())
73 return new NewsLiveCalendarWidget($holder, $this->start_date, $this->end_date, ($this->view == "default"));
74 return false;
75 }
76
77 public function Archive() {
78 if(!$this->start_date) return Director::redirect('/',301);
79 if ($holder = $this->getNewsHolder())
80 return new MonthNavigator($holder, $this->start_date);
81 return false;
82 }
83
84 public function MonthNavigator() {
85 return new MonthNavigator($this->data(), $this->start_date);
86 }
87
88 private function getNewsHolder() {
89 if ($this->ClassName == 'NewsHolder') {
90 return $this->data();
91 }
92 if ($this->ClassName == 'NewsEntry' && $this->Parent() && $this->Parent()->ClassName == 'NewsHolder') {
93 return $this->Parent()->data();
94 }
95 return false;
96 }
97 }
98
99
[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the
Silverstripe Forums to ask development related questions.
-