Skip to content
Snippets Groups Projects
Select Git revision
  • cf20da4779a8818f2cb471b713319c353ea0f935
  • main default protected
  • studip-rector
  • ci-opt
  • course-members-export-as-word
  • data-vue-app
  • pipeline-improvements
  • webpack-optimizations
  • rector
  • icon-renewal
  • http-client-and-factories
  • jsonapi-atomic-operations
  • vueify-messages
  • tic-2341
  • 135-translatable-study-areas
  • extensible-sorm-action-parameters
  • sorm-configuration-trait
  • jsonapi-mvv-routes
  • docblocks-for-magic-methods
19 results

courses.php

Blame
  • Forked from Stud.IP / Stud.IP
    Source project has a limited visibility.
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    ConsultationBlock.php 16.85 KiB
    <?php
    /**
     * Representation of a block of consultation slots - defining metadata.
     *
     * @author  Jan-Hendrik Willms <tleilax+studip@gmail.com>
     * @license GPL2 or any later version
     * @since   Stud.IP 4.3
     *
     * @todo Rewrite countBlocks and generateBlocks to use the same underlying
     *       method when the dev board finally fully supports PHP7 since that
     *       required "yield from".
     *
     * @property string block_id database column
     * @property string id alias column for block_id
     * @property string range_id database column
     * @property string range_type database column
     * @property string teacher_id database column
     * @property string start database column
     * @property string end database column
     * @property string room database column
     * @property string calendar_events database column
     * @property string note database column
     * @property string size database column
     * @property bool has_bookings computed column
     * @property Range range computed column
     * @property SimpleORMapCollection slots has_many ConsultationSlot
     * @property ConsultationResponsibility[] responsibilities has_many ConsultationResponsibility
     * @property User[] responsible_persons
     */
    class ConsultationBlock extends SimpleORMap implements PrivacyObject
    {
        /**
         * Configures the model.
         * @param array  $config Configuration
         */
        protected static function configure($config = [])
        {
            $config['db_table'] = 'consultation_blocks';
    
            $config['has_many']['slots'] = [
                'class_name'        => ConsultationSlot::class,
                'assoc_foreign_key' => 'block_id',
                'on_store'          => 'store',
                'on_delete'         => 'delete',
            ];
            $config['has_many']['responsibilities'] = [
                'class_name'        => ConsultationResponsibility::class,
                'assoc_foreign_key' => 'block_id',
                'on_delete'         => 'delete',
                'order_by'          => "ORDER BY range_type = 'user' DESC, range_type = 'statusgroup' DESC",
            ];
    
            $config['additional_fields']['range'] = [
                'set' => function ($block, $field, Range $range) {
                    $block->range_id   = $range->getRangeId();
                    $block->range_type = $range->getRangeType();
                },
                'get' => function ($block) {
                    return RangeFactory::createRange($block->range_type, $block->range_id);
                },
            ];
            $config['additional_fields']['range_display']['get'] = function ($block) {
                if ($block->range instanceof User) {
                    return $block->range->getFullName() . ' <' . $block->range->email . '>';
                }
                if ($block->range instanceof Course || $block->range instanceof Institute) {
                    return sprintf(_('Veranstaltung: %s'), $block->range->getFullName());
                }
    
                if ($block->range instanceof Institute) {