protected function compile()
 {
     $this->loadLanguageFile('tl_calendar_events');
     $objEvents = \HeimrichHannot\CalendarPlus\CalendarPlusEventsModel::findAll(array('order' => 'startDate DESC'));
     // HOOK: modify event objects for the chooser
     if (isset($GLOBALS['TL_HOOKS']['getEventObjectsForChooser']) && is_array($GLOBALS['TL_HOOKS']['getEventObjectsForChooser'])) {
         foreach ($GLOBALS['TL_HOOKS']['getEventObjectsForChooser'] as $callback) {
             $this->import($callback[0]);
             $this->{$callback}[0]->{$callback}[1]($objEvents);
         }
     }
     $items = array();
     if ($objEvents !== null) {
         while ($objEvents->next()) {
             $items[$objEvents->id] = array('title' => $objEvents->shortTitle ? $objEvents->shortTitle : $objEvents->title, 'date' => date('d.m.Y', $objEvents->startDate));
         }
     }
     // HOOK: modify event items for the chooser
     if (isset($GLOBALS['TL_HOOKS']['getEventItemsForChooser']) && is_array($GLOBALS['TL_HOOKS']['getEventItemsForChooser'])) {
         foreach ($GLOBALS['TL_HOOKS']['getEventItemsForChooser'] as $callback) {
             $this->import($callback[0]);
             $this->{$callback}[0]->{$callback}[1]($objEvents, $items);
         }
     }
     $this->Template->items = $items;
     if ($this->jumpTo) {
         $this->Template->action = $this->generateFrontendUrl($this->jumpTo);
     } else {
         $this->Template->action = '';
     }
 }
 public static function filterSubEvents(&$arrDca)
 {
     if (\Input::get('table') == 'tl_calendar_events') {
         $intEpid = \Input::get('epid');
         if ($intEpid) {
             if (($objEvents = \HeimrichHannot\CalendarPlus\CalendarPlusEventsModel::findByParentEvent($intEpid)) !== null) {
                 while ($objEvents->next()) {
                     $arrDca['list']['sorting']['root'][] = $objEvents->id;
                 }
             } else {
                 $arrDca['list']['sorting']['root'] = array(-1);
                 // don't display anything
             }
         } else {
             if (($objEvents = \HeimrichHannot\CalendarPlus\CalendarPlusEventsModel::findByParentEvent(0)) !== null) {
                 while ($objEvents->next()) {
                     $arrDca['list']['sorting']['root'][] = $objEvents->id;
                 }
             }
         }
     }
 }
 public static function getPromoterSelectOptions(\DataContainer $dc)
 {
     $arrItems = array();
     if (!is_array($dc->objModule->cal_calendar) || empty($dc->objModule->cal_calendar)) {
         return $arrItems;
     }
     $strCacheKey = 'promoters_select_options_' . implode('_', $dc->objModule->cal_calendar);
     if (FileCache::getInstance()->isExisting($strCacheKey)) {
         return FileCache::getInstance()->get($strCacheKey);
     }
     $objPromoters = CalendarPlusEventsModel::getUniquePromotersByPids($dc->objModule->cal_calendar);
     if ($objPromoters !== null) {
         $arrItems = $objPromoters->fetchEach('title');
     }
     // sort
     asort($arrItems);
     FileCache::getInstance()->set($strCacheKey, $arrItems);
     return $arrItems;
 }
 /**
  * Generate the widget and return it as string
  * @return string
  */
 public function generate()
 {
     switch ($this->widgetType) {
         case 'radio':
             $arrOptions = array();
             foreach ($this->arrOptions as $i => $arrOption) {
                 // further info link
                 if (CalendarPlusEventsModel::hasTextOrTeaser($arrOption['value'])) {
                     $arrOption['url'] = $this->replaceInsertTags('{{event_url::' . $arrOption['value'] . '}}');
                 }
                 // places left
                 if (in_array('event_subscription', $this->Config->getActiveModules())) {
                     $this->import('Database');
                     $objSubEvent = CalendarPlusEventsModel::findByPk($arrOption['value']);
                     if ($objSubEvent !== null) {
                         $objParentEvent = CalendarPlusEventsModel::findByPk($objSubEvent->parentEvent);
                         if ($objParentEvent !== null && $objSubEvent->addSubscription && !$objParentEvent->hidePlacesLeftSubEvents) {
                             $placesLeftSubEvent = CalendarPlusEventsModel::getPlacesLeftSubEvent($objSubEvent->id, $this->Database);
                             $arrOption['placesLeft'] = sprintf($GLOBALS['TL_LANG']['tl_event_subscription'][$placesLeftSubEvent <= 0 ? 'noPlacesLeftSubEventTeaser' : 'placesLeftSubEventTeaser'], $placesLeftSubEvent, $objSubEvent->placesTotal);
                             if ($placesLeftSubEvent <= 0) {
                                 $arrOption['disabled'] = true;
                             }
                         }
                     }
                 }
                 $arrOptions[] = $this->generateRadioButton($arrOption, $i);
             }
             // Add a "no entries found" message if there are no options
             if (empty($arrOptions)) {
                 $arrOptions[] = '<p class="tl_noopt">' . $GLOBALS['TL_LANG']['MSC']['noResult'] . '</p>';
             }
             return sprintf('<fieldset id="ctrl_%s" class="subevent tl_radio_container%s"><legend>%s%s%s%s</legend>%s</fieldset>%s', $this->strId, $this->strClass != '' ? ' ' . $this->strClass : '', $this->required ? '<span class="invisible">' . $GLOBALS['TL_LANG']['MSC']['mandatory'] . '</span> ' : '', $this->strLabel, $this->required ? '<span class="mandatory">*</span>' : '', $this->xlabel, implode('', array_map(function ($value) {
                 return '<div>' . $value . '</div>';
             }, $arrOptions)), $this->wizard);
             break;
         case 'checkbox':
             $arrOptions = array();
             $this->multiple = true;
             $this->mandatory = false;
             if (!$this->multiple && count($this->arrOptions) > 1) {
                 $this->arrOptions = array($this->arrOptions[0]);
             }
             // The "required" attribute only makes sense for single checkboxes
             if (!$this->multiple && $this->mandatory) {
                 $this->arrAttributes['required'] = 'required';
             }
             $state = $this->Session->get('checkbox_groups');
             // Toggle the checkbox group
             if (\Input::get('cbc')) {
                 $state[\Input::get('cbc')] = isset($state[\Input::get('cbc')]) && $state[\Input::get('cbc')] == 1 ? 0 : 1;
                 $this->Session->set('checkbox_groups', $state);
                 $this->redirect(preg_replace('/(&(amp;)?|\\?)cbc=[^& ]*/i', '', \Environment::get('request')));
             }
             $blnFirst = true;
             $blnCheckAll = false;
             foreach ($this->arrOptions as $i => $arrOption) {
                 // further info link
                 if (CalendarPlusEventsModel::hasTextOrTeaser($arrOption['value'])) {
                     $arrOption['url'] = $this->replaceInsertTags('{{event_url::' . $arrOption['value'] . '}}');
                 }
                 // places left
                 if (in_array('event_subscription', $this->Config->getActiveModules())) {
                     $this->import('Database');
                     $objSubEvent = CalendarPlusEventsModel::findByPk($arrOption['value']);
                     if ($objSubEvent !== null) {
                         $objParentEvent = CalendarPlusEventsModel::findByPk($objSubEvent->parentEvent);
                         if ($objParentEvent !== null && $objSubEvent->addSubscription && !$objParentEvent->hidePlacesLeftSubEvents) {
                             $placesLeftSubEvent = CalendarPlusEventsModel::getPlacesLeftSubEvent($objSubEvent->id, $this->Database);
                             $arrOption['placesLeft'] = sprintf($GLOBALS['TL_LANG']['tl_event_subscription'][$placesLeftSubEvent <= 0 ? 'noPlacesLeftSubEventTeaser' : 'placesLeftSubEventTeaser'], $placesLeftSubEvent, $objSubEvent->placesTotal);
                             if ($placesLeftSubEvent <= 0) {
                                 $arrOption['disabled'] = true;
                             }
                         }
                     }
                 }
                 // Single dimension array
                 if (is_numeric($i)) {
                     $arrOptions[] = $this->generateCheckbox($arrOption, $i);
                     continue;
                 }
                 $id = 'cbc_' . $this->strId . '_' . standardize($i);
                 $img = 'folPlus';
                 $display = 'none';
                 if (!isset($state[$id]) || !empty($state[$id])) {
                     $img = 'folMinus';
                     $display = 'block';
                 }
                 $arrOptions[] = '<div class="checkbox_toggler' . ($blnFirst ? '_first' : '') . '"><a href="' . $this->addToUrl('cbc=' . $id) . '" onclick="AjaxRequest.toggleCheckboxGroup(this,\'' . $id . '\');Backend.getScrollOffset();return false"><img src="' . TL_FILES_URL . 'system/themes/' . \Backend::getTheme() . '/images/' . $img . '.gif" width="18" height="18" alt="toggle checkbox group"></a>' . $i . '</div><fieldset id="' . $id . '" class="tl_checkbox_container checkbox_options" style="display:' . $display . '"><input type="checkbox" id="check_all_' . $id . '" class="tl_checkbox" onclick="Backend.toggleCheckboxGroup(this, \'' . $id . '\')"> <label for="check_all_' . $id . '" style="color:#a6a6a6"><em>' . $GLOBALS['TL_LANG']['MSC']['selectAll'] . '</em></label>';
                 // Multidimensional array
                 foreach ($arrOption as $k => $v) {
                     $arrOptions[] = $this->generateCheckbox($v, $i . '_' . $k);
                 }
                 $arrOptions[] = '</fieldset>';
                 $blnFirst = false;
                 $blnCheckAll = false;
             }
             // Add a "no entries found" message if there are no options
             if (empty($arrOptions)) {
                 $arrOptions[] = '<p class="tl_noopt">' . $GLOBALS['TL_LANG']['MSC']['noResult'] . '</p>';
                 $blnCheckAll = false;
             }
             if ($this->multiple) {
                 return sprintf('<fieldset id="ctrl_%s" class="tl_checkbox_container%s"><legend>%s%s%s%s</legend><input type="hidden" name="%s" value="">%s%s</fieldset>%s', $this->strId, $this->strClass != '' ? ' ' . $this->strClass : '', $this->required ? '<span class="invisible">' . $GLOBALS['TL_LANG']['MSC']['mandatory'] . '</span> ' : '', $this->strLabel, $this->required ? '<span class="mandatory">*</span>' : '', $this->xlabel, $this->strName, $blnCheckAll ? '<input type="checkbox" id="check_all_' . $this->strId . '" class="tl_checkbox" onclick="Backend.toggleCheckboxGroup(this,\'ctrl_' . $this->strId . '\')"> <label for="check_all_' . $this->strId . '" style="color:#a6a6a6"><em>' . $GLOBALS['TL_LANG']['MSC']['selectAll'] . '</em></label><br>' : '', str_replace('<br></fieldset><br>', '</fieldset>', implode('', array_map(function ($value) {
                     return '<div>' . $value . '</div>';
                 }, $arrOptions))), $this->wizard);
             } else {
                 return sprintf('<div id="ctrl_%s" class="tl_checkbox_single_container%s"><input type="hidden" name="%s" value="">%s</div>%s', $this->strId, $this->strClass != '' ? ' ' . $this->strClass : '', $this->strName, str_replace('<br></div><br>', '</div>', implode('', array_map(function ($value) {
                     return '<div>' . $value . '</div>';
                 }, $arrOptions))), $this->wizard);
             }
             break;
         default:
             // Form data rendering
             $widgetType = 'checkbox';
             $objFormField = \Database::getInstance()->prepare('SELECT * FROM tl_form_field ff INNER JOIN tl_form f ON ff.pid=f.id INNER JOIN tl_formdata fd ON fd.form=f.title WHERE ff.name=? AND fd.id=?')->limit(1)->execute(array('name' => $this->name, 'id' => \Input::get('id')));
             if ($objFormField->numRows > 0) {
                 $widgetType = $objFormField->widgetType;
                 $arrOptions = deserialize($objFormField->options, true);
             }
             $result = sprintf('<fieldset id="ctrl_' . $this->name . '" class="tl_checkbox_container"><h3>%s</h3>', $this->generateLabel());
             $subEvents = EventSubscriptionHelper::getDeserializedArray($this->activeRecord->{$this->name});
             if ($_GET['act'] == 'edit') {
                 foreach ($arrOptions as $i => $arrOption) {
                     $result .= '<input type="' . $widgetType . '" name="' . $this->name . '[]" id="opt_' . $this->name . '_' . $i . '" class="tl_checkbox" value="' . $arrOption['value'] . '" ' . (in_array($arrOption['value'], $subEvents) ? 'checked="checked"' : '') . 'onfocus="Backend.getScrollOffset()">' . '<label for="opt_' . $this->name . '_' . $i . '">' . $arrOption['label'] . '</label><br>';
                 }
             }
             return $result . '</fieldset>';
             break;
     }
 }
 protected function getParentEventDetails($intParentEvent, $intCalendar, $strBegin)
 {
     $objParentEvent = CalendarPlusEventsModel::findPublishedByParentAndIdOrAlias($intParentEvent, array($intCalendar));
     // do not show subevent, if parent event does not exist
     if ($objParentEvent === null) {
         return null;
     }
     $strUrl = $this->strUrl;
     $objCalendar = \CalendarModel::findByPk($objParentEvent->pid);
     // Get the current "jumpTo" page
     if ($objCalendar !== null && $objCalendar->jumpTo && ($objTarget = $objCalendar->getRelated('jumpTo')) !== null) {
         $strUrl = $this->generateFrontendUrl($objTarget->row(), \Config::get('useAutoItem') && !\Config::get('disableAlias') ? '/%s' : '/events/%s');
     }
     return $this->getEventDetails($objParentEvent, $objParentEvent->startTime, $objParentEvent->endTime, $strUrl, $strBegin, $objParentEvent->pid);
 }