render(); } public function __construct( $title = '', $config = [], $attributes = [], $data_name = 'fullcalendar' ) { $this->title = $title; $this->config = $config; $this->attributes = $attributes; $this->data_name = $data_name; } public function setDefaultView(?string $view): void { if ($view === null) { unset($this->config['initialView']); } else { $this->config['initialView'] = $view; } } public function setResponsiveDefaultView(?string $view): void { if ($view === null) { unset($this->config['responsiveDefaultView']); } else { $this->config['responsiveDefaultView'] = $view; } } public function render() { $factory = new \Flexi\Factory($GLOBALS['STUDIP_BASE_PATH'] . '/templates'); $template = $factory->open('studip-fullcalendar.php'); $real_data_name = sprintf('data-%s', $this->data_name); //Move the Stud.IP parts of the configuration out of the //fullcalendar configuration: $fullcalendar_config = $this->config; $template_params = [ 'title' => $this->title, 'dialogSize' => 'auto', 'actionUrls' => [], 'displayHolidays' => true, 'displayVacations' => true, 'externalDroppableContainerId' => '', 'externalDroppableEventSelector' => '', 'eventColourPicker' => false ]; if (!empty($this->attributes['class'])) { $template_params['extraClasses'] = $this->attributes['class']; unset($this->attributes['class']); } else { $template_params['extraClasses'] = ''; } $template_params['attributes'] = array_merge( $this->attributes, [$real_data_name => '1'] ); if (array_key_exists('studip_urls', $fullcalendar_config) && is_array($fullcalendar_config['studip_urls']) ) { $template_params['actionUrls'] = $fullcalendar_config['studip_urls']; unset($fullcalendar_config['studip_urls']); } $studip_config_map = [ 'dialog_size' => 'dialogSize', 'display_holidays' => 'displayHolidays', 'display_vacations' => 'displayVacations', 'external_droppable_container_id' => 'externalDroppableContainerId', 'external_droppable_event_selector' => 'externalDroppableEventSelector', 'event_colour_picker' => 'eventColourPicker', ]; foreach ($studip_config_map as $config_key => $param_key) { if (array_key_exists($config_key, $fullcalendar_config)) { $template_params[$param_key] = $fullcalendar_config[$config_key]; unset($fullcalendar_config[$config_key]); } } $template_params['config'] = $fullcalendar_config; return $template->render($template_params); } /** * Creates an array with data for a Fullcalendar instance * from Stud.IP objects that implement the EventSource interface. */ public static function createData($objects = [], $begin = null, $end = null) { if (!count($objects)) { //No data means there is nothing to do. return []; } $data = []; foreach ($objects as $object) { if ($object instanceof \Studip\Calendar\EventSource) { $events = $object->getFilteredEventData( $GLOBALS['user']->id, null, null, $begin, $end ); foreach ($events as $event) { $data[] = $event->toFullcalendarEvent(); } } } return $data; } }