Skip to content
Snippets Groups Projects
Select Git revision
  • 256be6d2ed505fd531cb0bb3937807c4a1a8cac5
  • 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

admin.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.
    ResourceCategory.class.php 28.38 KiB
    <?php
    
    /**
     * ResourceCategory.class.php - model class for resource categories
     *
     * The ResourceCategory class can be used as a Factory for
     * Resource objects.
     *
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU General Public License as
     * published by the Free Software Foundation; either version 2 of
     * the License, or (at your option) any later version.
     *
     * @author      Moritz Strohm <strohm@data-quest.de>
     * @copyright   2017
     * @license     http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
     * @category    Stud.IP
     * @package     resources
     * @since       4.1
     *
     * @property string $id database column
     * @property string $name database column
     * @property string $description database column
     * @property int $system database column
     * @property int|null $iconnr database column
     * @property string $class_name database column
     * @property int $mkdate database column
     * @property int $chdate database column
     * @property SimpleORMapCollection|ResourceCategoryProperty[] $property_links has_many ResourceCategoryProperty
     * @property SimpleORMapCollection|ResourcePropertyDefinition[] $property_definitions has_and_belongs_to_many ResourcePropertyDefinition
     */
    class ResourceCategory extends SimpleORMap
    {
        private static $cache;
    
        protected static function configure($config = [])
        {
            $config['db_table'] = 'resource_categories';
    
            $config['has_and_belongs_to_many']['property_definitions'] = [
                'class_name'        => ResourcePropertyDefinition::class,
                'assoc_foreign_key' => 'property_id',
                'thru_table'        => 'resource_category_properties',
                'thru_key'          => 'category_id',
                'order_by'          => 'ORDER BY name ASC'
            ];
    
            $config['has_many']['property_links'] = [
                'class_name'  => ResourceCategoryProperty::class,
                'assoc_func'  => 'findByCategory_id',
                'foreign_key' => 'id',
                'on_delete'   => 'delete'
            ];
    
            $config['registered_callbacks']['after_create'][] = function ($category) {
                self::$cache[$category->id] = $category;
            };
            $config['registered_callbacks']['after_store'][] = function ($category) {
                self::$cache[$category->id] = $category;
            };
            $config['registered_callbacks']['after_delete'][] = function ($category) {
                unset(self::$cache[$category->id]);
            };
    
            parent::configure($config);
        }
    
        /**
         * Retrieves all resource categories from the database.
         * @param bool $force_reload