Skip to content
Snippets Groups Projects
Select Git revision
  • 7a6909c32bc4357dfa0a624d79ad255e9bdd2d11
  • main default protected
  • step-3263
  • feature/plugins-cli
  • feature/vite
  • step-2484-peerreview
  • biest/issue-5051
  • tests/simplify-jsonapi-tests
  • fix/typo-in-1a70031
  • feature/broadcasting
  • database-seeders-and-factories
  • feature/peer-review-2
  • feature-feedback-jsonapi
  • feature/peerreview
  • feature/balloon-plus
  • feature/stock-images-unsplash
  • tic-2588
  • 5.0
  • 5.2
  • biest/unlock-blocks
  • biest-1514
21 results

dates.inc.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;
        }
    
    }