/**
  * Contructor
  * @param type $controller
  * @param type $name
  */
 function __construct($controller, $name)
 {
     //Administering calendars
     if (CalendarConfig::subpackage_enabled('calendars')) {
         //Configuration for calendar grid field
         $gridCalendarConfig = GridFieldConfig_RecordEditor::create();
         $gridCalendarConfig->removeComponentsByType('GridFieldDataColumns');
         $gridCalendarConfig->addComponent($dataColumns = new GridFieldDataColumns(), 'GridFieldEditButton');
         $c = singleton('Calendar');
         $summaryFields = $c->summaryFields();
         //$summaryFields = array(
         //	'Title' => 'Title',
         //	//'SubscriptionOptIn' => 'Opt In',
         //	//'Shaded' => 'Shaded'
         //);
         $s = CalendarConfig::subpackage_settings('calendars');
         //show shading info in the gridfield
         if ($s['shading']) {
             $summaryFields['Shaded'] = 'Shaded';
         }
         $dataColumns->setDisplayFields($summaryFields);
         //settings for the case that colors are enabled
         if ($s['colors']) {
             $dataColumns->setFieldFormatting(array("Title" => '<div style=\\"height:20px;width:20px;display:inline-block;vertical-align:middle;margin-right:6px;background:$Color\\"></div> $Title'));
         }
         $GridFieldCalendars = new GridField('Calendars', '', PublicCalendar::get(), $gridCalendarConfig);
         $fields = new FieldList($GridFieldCalendars);
         $actions = new FieldList();
         $this->addExtraClass('CalendarsForm');
         parent::__construct($controller, $name, $fields, $actions);
     }
 }
 /**
  * Contructor
  * @param type $controller
  * @param type $name
  */
 public function __construct($controller, $name)
 {
     //Administering categories
     if (CalendarConfig::subpackage_enabled('categories')) {
         $gridCategoryConfig = GridFieldConfig_RecordEditor::create();
         $GridFieldCategories = new GridField('Categories', '', PublicEventCategory::get(), $gridCategoryConfig);
         $fields = new FieldList($GridFieldCategories);
         $actions = new FieldList();
         $this->addExtraClass('CategoriesForm');
         parent::__construct($controller, $name, $fields, $actions);
     }
 }
 public function RegistrationsEnabled()
 {
     return CalendarConfig::subpackage_enabled('registrations');
 }
예제 #4
0
 /**
  * Sanity checks before write
  * Rules for event saving:
  * 1. Events have
  *
  *
  */
 public function onBeforeWrite()
 {
     parent::onBeforeWrite();
     $debug = false;
     if (CalendarConfig::subpackage_enabled('debug')) {
         $debug = true;
     }
     //echo "executing onbeforewrite \n";
     //only allowing to run this once:
     if ($this->hasWritten) {
         return false;
     }
     $this->hasWritten = true;
     //echo "this should only execute once \n";
     //Convert to allday event if the entered time is 00:00
     //(i.e. this field has been left blank)
     //This only happens if allday events are enabled
     //NOTE: Currently it seems to me as if there should be no need to disable allday events
     if (CalendarConfig::subpackage_setting('events', 'enable_allday_events')) {
         //This only happens on first save to correct for the rare cases that someone might
         //actually want to add an event like this
         if (!$this->ID) {
             if (date("H:i", strtotime($this->StartDateTime)) == '00:00') {
                 $this->AllDay = true;
                 if ($debug) {
                     $this->debugLog('Converted to allday event as the entered time was 00:00');
                 }
             }
         }
     }
     //If the timeframetype is duration - set end date based on duration
     if ($this->TimeFrameType == 'Duration') {
         $formatDate = $this->calcEndDateTimeBasedOnDuration();
         //only write the end date if a duration has actually been entered
         //If not, leave the end date blank for now, and it'll be taken care later in this method
         if ($this->StartDateTime != $formatDate) {
             $this->EndDateTime = $formatDate;
             if ($debug) {
                 $this->debugLog('Time frame type: Duration: Set end date');
             }
         } else {
             //setting the end date/time to null, as it has automatically been set via javascript
             $this->EndDateTime = null;
             if ($debug) {
                 $this->debugLog('Time frame type: Duration: setting the end date/time to null, as it has automatically been set via javascript');
             }
         }
     } else {
         //reset duration
         $this->Duration = '';
         if ($debug) {
             $this->debugLog('reset duration');
         }
     }
     //Sanity checks:
     //1. We always need an end date/time - if no end date is set, set end date 1 hour after start date
     //This won't happen if leaving end date/time empty is allowed through the config
     //This should not happen to single day allday events as these are supposed to have start and end date
     //set to the same date via the js in the edit form
     if (CalendarConfig::subpackage_setting('events', 'force_end')) {
         if (!$this->EndDateTime) {
             $this->EndDateTime = date("Y-m-d H:i:s", strtotime($this->StartDateTime) + 3600);
             if ($debug) {
                 $this->debugLog('Sanity check 1: Setting end date');
             }
         }
     }
     //2. We can't have negative dates
     //If this happens for some reason, we make the event an allday event, and set start date = end date
     //Should only be triggered, if EndDateTime is set
     if (isset($this->EndDateTime)) {
         if (strtotime($this->EndDateTime) < strtotime($this->StartDateTime)) {
             $this->EndDateTime = $this->StarDateTime;
             $this->AllDay = true;
             $msg = "Sanity check 2: Setting end date = start date and setting all day \n" . "as {$this->EndDateTime} was lower than {$this->StartDateTime} \n" . strtotime($this->EndDateTime) . " vs " . strtotime($this->StartDateTime);
             if ($debug) {
                 $this->debugLog($msg);
             }
         }
     }
     //3. If end dates are not enforced, and no end date has been set, set the NoEnd attribute
     //Equally, if the Noend attribute has been set  via a checkbox, we reset EndDateTime and Duration
     if (!CalendarConfig::subpackage_setting('events', 'force_end')) {
         if (isset($this->EndDateTime)) {
             if ($this->NoEnd) {
                 $this->Duration = null;
                 $this->EndDateTime = null;
                 if ($debug) {
                     $this->debugLog('Sanity check 3: as the event has the noend setting, setting duration and enddatetime to null');
                 }
             }
         } else {
             $this->NoEnd = true;
             if ($debug) {
                 $this->debugLog('Sanity check 3: as end date/time has not been set, setting NoEnd to true');
             }
         }
     }
     //4. All day events can't have open ends
     //so if and event both has the allday attribute and the noend attribute,
     //noend is enforced over allday
     if ($this->AllDay && $this->NoEnd) {
         $this->AllDay = false;
         if ($debug) {
             $this->debugLog('Sanity check 4: as both allday and noend have been set, noend wins');
         }
     }
 }
 public function CategoriesEnabled()
 {
     return CalendarConfig::subpackage_enabled('categories');
 }