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

Authority.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.
    StudipTreeNodeCachableTrait.php 1.67 KiB
    <?php
    trait StudipTreeNodeCachableTrait
    {
        protected static $descendants_cache_array = null;
    
        protected static function getDescendantsCacheArray(): StudipCachedArray
        {
            if (self::$descendants_cache_array === null) {
                self::$descendants_cache_array = new StudipCachedArray(
                    static::class . '/descendants',
                    30 * 60
                );
            }
            return self::$descendants_cache_array;
        }
    
        protected static function registerCachableCallbacks(array $config): array
        {
            if (!isset($config['registered_callbacks'])) {
                $config['registered_callbacks'] = [];
            }
    
            if (!isset($config['registered_callbacks']['before_store'])) {
                $config['registered_callbacks']['before_store'] = [];
            }
            $config['registered_callbacks']['before_store'][] = function ($node): void {
                self::getDescendantsCacheArray()->expire();
            };
    
            if (!isset($config['registered_callbacks']['after_delete'])) {
                $config['registered_callbacks']['after_delete'] = [];
            }
            $config['registered_callbacks']['after_delete'][] = function ($node): void {
                self::getDescendantsCacheArray()->expire();
            };
    
            return $config;
        }
    
        protected function getDescendantIds(): array
        {
            $cache = self::getDescendantsCacheArray();
    
            if (isset($cache[$this->id])) {
                return $cache[$this->id];
            }
    
            $ids = [];
    
            foreach ($this->getChildNodes() as $child) {
                $ids = array_merge($ids, [$child->id], $child->getDescendantIds());
            }
    
            $cache[$this->id] = $ids;
    
            return $ids;
        }
    
    }