diff options
| author | Philipp Schüttlöffel <schuettloeffel@zqs.uni-hannover.de> | 2024-09-24 10:53:31 +0200 |
|---|---|---|
| committer | Philipp Schüttlöffel <schuettloeffel@zqs.uni-hannover.de> | 2024-09-24 10:53:31 +0200 |
| commit | 4459dd7917f4d1c34f40bb68f0e991e9c3d53e4c (patch) | |
| tree | 5c07151ae61276d334e88f6309c30d439a85c12e /lib/classes/Fullcalendar.php | |
| parent | da0022e5c1abbf9825ae76debaabdff7e8623bb4 (diff) | |
| parent | 97a188592c679890a25c37ab78463add76a52ff7 (diff) | |
Merge branch 'main' into issue-3911issue-3911
Diffstat (limited to 'lib/classes/Fullcalendar.php')
| -rw-r--r-- | lib/classes/Fullcalendar.php | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/lib/classes/Fullcalendar.php b/lib/classes/Fullcalendar.php new file mode 100644 index 0000000..db8364a --- /dev/null +++ b/lib/classes/Fullcalendar.php @@ -0,0 +1,109 @@ +<?php + + +namespace Studip; + + +class Fullcalendar +{ + protected $title; + + /** + * Fullcalendar configuration options. + * They are passed to the JavaScript fullcalendar class. + */ + protected $config; + + /** + * Additional HTML attributes that shall be attached to the + * section element in which the fullcalendar instance is created. + */ + protected $attributes; + + + /** + * The name of the fullcalendar for the data attribute. This is set + * to "fullcalendar" by default, but custom fullcalendars may require + * special data attributes to prevent the default Fullcalendar JS + * initialiser to be executed. + */ + protected $data_name; + + + public static function create( + $title = '', + $config = [], + $attributes = [], + $data_name = 'fullcalendar' + ) + { + $instance = new \Studip\Fullcalendar( + $title, + $config, + $attributes, + $data_name + ); + + return $instance->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 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); + return $template->render( + [ + 'title' => $this->title, + 'config' => $this->config, + 'attributes' => array_merge( + $this->attributes, + [$real_data_name => '1'] + ) + ] + ); + } + + + /** + * 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; + } +} |
