/**
  * Deletes the usertype specified by ID.
  * @return bool Was it successful?
  */
 protected function body()
 {
     if (!$this->userHasPrivileges(User::usersPrivPresets)) {
         return false;
     }
     if (!$this->isInputSet('id')) {
         return false;
     }
     $id = $this->getParams('id');
     if ($id == Repositories::StudentUserType) {
         return $this->death(StringID::CannotRemoveBasicStudentType);
     }
     /**
      * @var $deletedType \UserType
      */
     $deletedType = Repositories::findEntity(Repositories::UserType, $id);
     $users = Repositories::getRepository(Repositories::User)->findBy(['type' => $id]);
     /** @var \UserType $studentType */
     $studentType = Repositories::findEntity(Repositories::UserType, Repositories::StudentUserType);
     foreach ($users as $user) {
         /** @var $user \User */
         $user->setType($studentType);
         Repositories::persist($user);
     }
     Repositories::remove($deletedType);
     Repositories::flushAll();
     return true;
 }
 protected function body()
 {
     if (!$this->isInputValid(array('id' => 'isIndex'))) {
         return false;
     }
     $id = $this->getParams('id');
     /**
      * @var $question \Question
      */
     $question = Repositories::findEntity(Repositories::Question, $id);
     if (!$this->authorizedToManageLecture($question->getLecture())) {
         return $this->death(StringID::InsufficientPrivileges);
     }
     // What if some tests refer to this question? Then the deletion should not be permitted.
     /**
      * @var $xtests \Xtest[]
      */
     $xtests = Repositories::getRepository(Repositories::Xtest)->findAll();
     foreach ($xtests as $xtest) {
         $templateArray = explode(',', $xtest->getTemplate());
         if (in_array($question->getId(), $templateArray)) {
             return $this->death(StringID::CannotDeleteQuestionThatsPartOfATest);
         }
     }
     Repositories::remove($question);
     return true;
 }
 protected function body()
 {
     if (!$this->isInputValid(array('id' => 'isIndex'))) {
         return false;
     }
     $id = $this->getParams('id');
     /**
      * @var $xtest \Xtest
      */
     $xtest = Repositories::findEntity(Repositories::Xtest, $id);
     if (!$this->checkTestGenerationPrivileges($xtest->getLecture()->getId())) {
         return $this->death(StringID::InsufficientPrivileges);
     }
     Repositories::remove($xtest);
     return true;
 }
 protected function body()
 {
     if (!$this->isInputValid(array('id' => 'isIndex'))) {
         return false;
     }
     $id = $this->getParams('id');
     /**
      * @var $subscription \Subscription
      */
     $subscription = Repositories::findEntity(Repositories::Subscription, $id);
     if ($subscription->getUser()->getId() !== User::instance()->getId()) {
         return $this->death(StringID::InsufficientPrivileges);
     }
     Repositories::remove($subscription);
     return true;
 }
 /**
  * Deletes test with supplied ID (with input & output files).
  * @param int $id test ID
  * @return array error properties provided by removalError() or retrievalError(),
  * or false in case of success
  */
 public static function deleteTestById($id)
 {
     /**
      * @var $test \PluginTest
      */
     $test = Repositories::findEntity(Repositories::PluginTest, $id);
     $testFolder = Config::get('paths', 'tests');
     // Delete input solution file
     if (is_file(Filesystem::combinePaths($testFolder, $test->getInput()))) {
         Filesystem::removeFile(Filesystem::combinePaths($testFolder, $test->getInput()));
     }
     // Delete plugin test output
     if (is_file(Filesystem::combinePaths($testFolder, $test->getOutput()))) {
         Filesystem::removeFile(Filesystem::combinePaths($testFolder, $test->getOutput()));
     }
     Repositories::remove($test);
     return false;
 }