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

MyRealmModel.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.
    Instance.php 9.88 KiB
    <?php
    
    namespace Courseware;
    
    /**
     * This class represents an instance of a courseware of a course or a user.
     *
     * @author  Marcus Eibrink-Lunzenauer <lunzenauer@elan-ev.de>
     * @author  Ron Lucke <lucke@elan-ev.de>
     * @license GPL2 or any later version
     *
     * @since   Stud.IP 5.0
     */
    class Instance
    {
        public static function deleteForRange(\Range $range): void
        {
            $root = null;
            switch ($range->getRangeType()) {
                case 'course':
                    $root = StructuralElement::getCoursewareCourse($range->getRangeId());
                    break;
                case 'user':
                    $root = StructuralElement::getCoursewareUser($range->getRangeId());
                    break;
                default:
                    throw new \InvalidArgumentException('Only ranges of type "user" and "course" are currently supported.');
            }
    
            // there is no courseware for this course
            if (!$root) {
                return;
            }
    
            $instance = new self($root);
    
            $range->getConfiguration()->delete('COURSEWARE_SEQUENTIAL_PROGRESSION');
            $range->getConfiguration()->delete('COURSEWARE_EDITING_PERMISSION');
    
            $last_element_configs = \ConfigValue::findBySQL('field = ? AND value LIKE ?', ['COURSEWARE_LAST_ELEMENT', '%'.$range->getRangeId().'%']);
            foreach ($last_element_configs as $config) {
                $arr = json_decode($config->value, true);
                $arr = array_filter($arr, function ($key) use ($range) {
                    return $key !== $range->id;
                }, ARRAY_FILTER_USE_KEY);
                \UserConfig::get($config->range_id)->unsetValue('COURSEWARE_LAST_ELEMENT');
                \UserConfig::get($config->range_id)->store('COURSEWARE_LAST_ELEMENT', $arr);
            }
    
            $root->delete();
        }
    
        /**
         * @var StructuralElement
         */
        private $root;
    
        /**
         * Create a new representation of a a courseware instance.
         *
         * This model class purely represents and does not create anything. Its purpose is to have all things related to a
         * single courseware instance in one place.
         *
         * @param StructuralElement $root the root of this courseware instance
         */
        public function __construct(StructuralElement $root)
        {
            $this->root = $root;
        }