diff --git a/code/CalendarEntry.php b/code/CalendarEntry.php index 694fcec..60ed072 100644 --- a/code/CalendarEntry.php +++ b/code/CalendarEntry.php @@ -34,30 +34,34 @@ public function validate() return $result; } + /** + * @return FieldList + */ public function getCMSFields() { - $this->beforeUpdateCMSFields(function ($fields) { - $datefield = new DateField('Date', 'Date (DD/MM/YYYY)*'); - $datefield->setConfig('showcalendar', true); - $datefield->setConfig('dateformat', 'dd/MM/YYYY'); - - $imagefield = new UploadField('Image', 'Image'); - $imagefield->allowedExtensions = array('jpg', 'gif', 'png'); - $imagefield->setFolderName("Managed/CalendarImages"); - $imagefield->setCanPreviewFolder(false); - - $fields->addFieldToTab('Root.Main', new TextField('Title', "Event Title*")); - $fields->addFieldToTab('Root.Main', $datefield); - $fields->addFieldToTab('Root.Main', new TextField('Time', "Time (HH:MM)")); - $fields->addFieldToTab('Root.Main', new TextareaField('Description')); - $fields->addFieldToTab('Root.Main', $imagefield); - }); - $fields = parent::getCMSFields(); - $this->extend('updateCMSFields', $fields); + // add the new fields in + $fields->addFieldsToTab( + 'Root.Main', + array( + TextField::create('Title', "Event Title*"), + DateField::create('Date', 'Date (DD/MM/YYYY)*') + ->setConfig('showcalendar', true) + ->setConfig('dateformat', 'dd/MM/YYYY'), + TextField::create('Time', "Time (HH:MM)"), + TextareaField::create('Description'), + + UploadField::create('Image', 'Image') + ->setAllowedExtensions(array('jpg', 'gif', 'png')) + ->setFolderName("Managed/CalendarImages") + ->setCanPreviewFolder(false) + ) + ); + + $fields->removeFieldFromTab('Root.Main', 'CalendarPageID'); - $fields->removeFieldFromTab("Root.Main", "CalendarPageID"); + $this->extend('updateCalendarCMSFields', $fields); return $fields; } @@ -65,12 +69,14 @@ public function getCMSFields() public function getMonthDigit() { $date = strtotime($this->Date); + return date('m', $date); } public function getYear() { $date = strtotime($this->Date); + return date('Y', $date); } @@ -80,6 +86,7 @@ public function canCreate($members = null) if ($extended !== null) { return $extended; } + return true; } @@ -89,6 +96,7 @@ public function canEdit($members = null) if ($extended !== null) { return $extended; } + return true; } @@ -98,6 +106,7 @@ public function canDelete($members = null) if ($extended !== null) { return $extended; } + return true; } @@ -107,6 +116,7 @@ public function canView($members = null) if ($extended !== null) { return $extended; } + return true; } } diff --git a/code/CalendarPage.php b/code/CalendarPage.php index 0720ec8..c12b6ac 100644 --- a/code/CalendarPage.php +++ b/code/CalendarPage.php @@ -20,9 +20,7 @@ public function getCMSFields() { $fields = parent::getCMSFields(); - if ($this->EventTabFirst) { - $fields->insertBefore(new Tab('Events'), 'Main'); - } + if ($this->EventTabFirst) $fields->insertBefore(new Tab('Events'), 'Main'); $config = GridFieldConfig_RecordEditor::create(); $gridField = new GridField("Events", "Upcoming Events", $this->Events()->where("Date >= CURRENT_DATE OR Date IS NULL"), $config); @@ -47,12 +45,13 @@ class CalendarPage_Controller extends Page_Controller public function init() { + parent::init(); + if (Director::fileExists(project() . "/css/calendar.css")) { Requirements::css(project() . "/css/calendar.css"); } else { Requirements::css("basic-calendar/css/calendar.css"); } - parent::init(); } public function getEvents($dates = "all") @@ -74,25 +73,28 @@ public function getEvents($dates = "all") public function ShowPast() { - return isset($_GET['past']) ? true : false; + return isset($_GET['past']); } // THIS PAGE'S ENTRIES public function getFutureCalendarEntries() { $entries = GroupedList::create(CalendarEntry::get()->filter(array("CalendarPageID"=>$this-ID))->Sort('Date, Time')->where("Date >= CURRENT_DATE OR Date IS NULL")); + return $entries; } public function getGroupedPastCalendarEntries() { $entries = GroupedList::create(CalendarEntry::get()->filter(array("CalendarPageID"=>$this-ID))->Sort('Date, Time')->where("Date < CURRENT_DATE")); + return $entries; } public function getGroupedCalendarEntries() { $entries = GroupedList::create(CalendarEntry::get()->filter(array("CalendarPageID"=>$this-ID))->Sort('Date, Time')); + return $entries; } @@ -100,18 +102,21 @@ public function getGroupedCalendarEntries() public function getAllGroupedFutureCalendarEntries() { $entries = GroupedList::create(CalendarEntry::get()->Sort('Date, Time')->where("Date >= CURRENT_DATE OR Date IS NULL")); + return $entries; } public function getAllGroupedPastCalendarEntries() { $entries = GroupedList::create(CalendarEntry::get()->Sort('Date, Time')->where("Date < CURRENT_DATE")); + return $entries; } public function getAllGroupedCalendarEntries() { $entries = GroupedList::create(CalendarEntry::get()->Sort('Date, Time')); + return $entries; } }