protected function body() { if (!$this->userHasPrivileges(User::usersPrivPresets)) { return false; } $privilegeGroups = array('users', 'subscriptions', 'plugins', 'assignments', 'submissions', 'lectures', 'groups', 'other'); $inputs = array_merge(array('name' => array('isAlphaNumeric', 'isNotEmpty')), array_combine($privilegeGroups, array_pad(array(), count($privilegeGroups), array()))); if (!$this->isInputValid($inputs)) { return false; } $id = $this->getParams('id'); $name = $this->getParams('name'); $privileges = array(); foreach ($privilegeGroups as $i => $group) { $value = $this->getParams($group); $privileges = array_merge($privileges, $value != '' ? explode(';', $value) : array()); } if (count($privileges)) { $privileges = array_combine($privileges, array_pad(array(), count($privileges), true)); } $privileges = User::instance()->packPrivileges($privileges); if ($id === null || $id === '') { $usertype = new \UserType(); $usertype->setName($name); $usertype->setPrivileges($privileges); Repositories::persistAndFlush($usertype); } else { /** @var \UserType $usertype */ $usertype = Repositories::findEntity(Repositories::UserType, $id); $usertype->setName($name); $usertype->setPrivileges($privileges); Repositories::persistAndFlush($usertype); } return true; }
/** * Returns true if the active user is authorized to manage the lecture specified by the parameter. * @param $lectureId int Database ID of the lecture. * @return bool Is the active user authorized to manage it? */ protected function checkTestGenerationPrivileges($lectureId) { /** * @var $lecture \Lecture */ $lecture = Repositories::findEntity(Repositories::Lecture, $lectureId); return $this->authorizedToManageLecture($lecture); }
protected function body() { if (!$this->userHasPrivileges(User::assignmentsSubmit)) { return false; } $ratings = Repositories::getEntityManager()->createQuery("SELECT s, SUM(s.rating) AS rating, a, g.id FROM \\Submission s JOIN s.assignment a JOIN a.group g WHERE s.user = :userId AND s.status = 'graded' GROUP BY g, g.name")->setParameter('userId', User::instance()->getId())->getResult(); foreach ($ratings as $rating) { /** @var \Group $group */ $group = Repositories::findEntity(Repositories::Group, (int) $rating["id"]); $this->addRowToOutput([User::instance()->getName(), User::instance()->getEmail(), $rating["id"], $rating["rating"], $group->getName(), $group->getDescription(), $group->getLecture()->getName(), $group->getLecture()->getDescription()]); } return true; }
protected function body() { if (!$this->userHasPrivileges(User::pluginsTest)) { return false; } if (!$this->isInputValid(array('id' => 'isIndex'))) { return false; } /** * @var $test \PluginTest */ $test = Repositories::findEntity(Repositories::PluginTest, $this->getParams('id')); $this->setOutput($test->getOutput(), Config::get('defaults', 'pluginOutputFileName') . '.zip'); return true; }
protected function body() { if (!$this->isInputValid(array('id' => 'isIndex'))) { return false; } $id = $this->getParams('id'); /** @var \XTest $test */ $test = Repositories::findEntity(Repositories::Xtest, $id); if (!$this->checkTestGenerationPrivileges($test->getLecture()->getId())) { return false; } $randomized = $this->generateTest($test->getTemplate(), $test->getCount()); $test->setGenerated(implode(',', $randomized)); Repositories::persistAndFlush($test); return true; }