Select Git revision
MyRealmModel.php
Forked from
Stud.IP / Stud.IP
Source project has a limited visibility.
-
Rasmus Fuhse authoredRasmus Fuhse authored
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;
}