protected function body()
 {
     if (!$this->userHasPrivileges(User::lecturesManageAll, User::lecturesManageOwn, User::groupsManageAll, User::groupsManageOwn)) {
         return;
     }
     $lite = $this->getParams('lite');
     $user = User::instance();
     $displayAll = $user->hasPrivileges(User::lecturesManageAll) || $lite;
     /**
      * @var $problems \Problem[]
      */
     $problems = Repositories::getEntityManager()->createQuery("SELECT p, l FROM \\Problem p JOIN p.lecture l WHERE p.deleted = false AND (:displayAll = true OR l.owner = :userid)")->setParameter('displayAll', $displayAll)->setParameter('userid', $user->getId())->getResult();
     foreach ($problems as $problem) {
         $row = array($problem->getId(), $problem->getName());
         if (!$lite) {
             $row[] = $problem->getDescription();
             if ($problem->getPlugin()) {
                 $row[] = $problem->getPlugin()->getId();
             } else {
                 $row[] = "";
             }
             $row[] = $problem->getConfig();
         }
         $row[] = $problem->getLecture()->getId();
         if (!$lite) {
             $row[] = $problem->getLecture()->getName();
             $row[] = $problem->getLecture()->getDescription();
         }
         $this->addRowToOutput($row);
     }
 }
 /**
  * Returns an array of all tests that can be viewed, edited and deleted by the logged-in user.
  *
  * @return \Xtest[] tests that can be edited by the active user
  */
 public static function GetTestsVisibleToUser()
 {
     $repository = Repositories::getRepository(Repositories::Xtest);
     if (User::instance()->hasPrivileges(User::lecturesManageAll)) {
         return $repository->findAll();
     } else {
         return Repositories::getEntityManager()->createQuery("SELECT x FROM \\Xtest x JOIN x.lecture l WHERE l.owner = :ownerId")->setParameter('ownerId', User::instance()->getId())->getResult();
     }
 }
 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::groupsAdd)) {
         return false;
     }
     $requests = Repositories::getEntityManager()->createQuery("SELECT s, g FROM \\Subscription s JOIN s.group g WHERE g.owner = :ownerId")->setParameter("ownerId", User::instance()->getId())->getResult();
     foreach ($requests as $request) {
         /**
          * @var $request \Subscription
          */
         if ($request->getStatus() !== \Subscription::STATUS_REQUESTED) {
             continue;
         }
         $this->addRowToOutput([$request->getId(), $request->getUser()->getName(), $request->getUser()->getRealName(), $request->getUser()->getEmail(), $request->getGroup()->getName(), $request->getGroup()->getDescription(), $request->getGroup()->getLecture()->getName(), $request->getGroup()->getLecture()->getDescription()]);
     }
     return true;
 }
 protected function body()
 {
     if (!$this->userHasPrivileges(User::groupsManageAll, User::groupsManageOwn)) {
         return false;
     }
     /**
      * @var $assignments \Assignment[]
      */
     if (User::instance()->hasPrivileges(User::groupsManageAll)) {
         $assignments = Repositories::getRepository(Repositories::Assignment)->findBy(['deleted' => false]);
     } else {
         $assignments = Repositories::getEntityManager()->createQuery('SELECT a, g FROM \\Assignment a JOIN a.group g WHERE a.deleted = false AND g.owner = :ownerId')->setParameter('ownerId', User::instance()->getId())->getResult();
     }
     foreach ($assignments as $assignment) {
         $row = array($assignment->getId(), $assignment->getProblem()->getId(), $assignment->getProblem()->getName(), $assignment->getDeadline()->format('Y-m-d H:i:s'), $assignment->getReward(), $assignment->getGroup()->getId(), $assignment->getGroup()->getName(), $assignment->getGroup()->getOwner()->getId());
         $this->addRowToOutput($row);
     }
     return true;
 }
 protected function body()
 {
     if (!$this->userHasPrivileges()) {
         return false;
     }
     $onSubmissionRated = $this->paramExists(User::sendEmailOnSubmissionRatedStudent);
     $onSubmissionConfirmed = $this->paramExists(User::sendEmailOnSubmissionConfirmedTutor);
     $onAssignmentAvailable = $this->paramExists(User::sendEmailOnAssignmentAvailableStudent);
     $userEntity = User::instance()->getEntity();
     User::instance()->setData(User::sendEmailOnSubmissionRatedStudent, $this->paramExists(User::sendEmailOnSubmissionRatedStudent) ? 1 : 0);
     User::instance()->setData(User::sendEmailOnSubmissionConfirmedTutor, $this->paramExists(User::sendEmailOnSubmissionConfirmedTutor) ? 1 : 0);
     User::instance()->setData(User::sendEmailOnAssignmentAvailableStudent, $this->paramExists(User::sendEmailOnAssignmentAvailableStudent) ? 1 : 0);
     // Update
     $userEntity->setSendEmailOnNewAssignment(!!$onAssignmentAvailable);
     $userEntity->setSendEmailOnNewSubmission(!!$onSubmissionConfirmed);
     $userEntity->setSendEmailOnSubmissionRated(!!$onSubmissionRated);
     Repositories::getEntityManager()->persist($userEntity);
     Repositories::getEntityManager()->flush($userEntity);
     return true;
 }
 protected function body()
 {
     if (!$this->userHasPrivileges(User::groupsManageAll, User::groupsManageOwn)) {
         return false;
     }
     $canManageAll = User::instance()->hasPrivileges(User::groupsManageAll);
     /*
      * Output format documentation:
      * GROUPID => [
      * 	name
      *  lecture (name)
      *  owned (true/false, whether owned by the active user)
      *  assignments
      *   ASSIGNMENTID => [
      *    problem (name)
      *    reward (maximum reward int)
      *   ]
      *  students
      *   STUDENTID => [
      *    name (RealName)
      *    ratings
      *     ASSIGNMENTID => [
      *      id (SubmissionId)
      *      rating (submission rating)
      *     ]
      *    sum (sum of all ratings for all submissions of this student for this group)
      *   ]
      * ]
      */
     /** @var \Submission[] $submissions */
     $submissions = Repositories::getEntityManager()->createQuery('SELECT s, a, g, p, l FROM \\Submission s JOIN s.assignment a JOIN a.group g JOIN g.lecture l JOIN a.problem p WHERE s.status <> \'deleted\' AND a.deleted = false AND g.deleted = false AND l.deleted = false AND p.deleted = false')->getResult();
     $result = array();
     foreach ($submissions as $s) {
         $assignment = $s->getAssignment();
         $group = $assignment->getGroup();
         $lecture = $group->getLecture();
         $problem = $assignment->getProblem();
         if (!$canManageAll && $group->getOwner()->getId() !== User::instance()->getId()) {
             continue;
         }
         if (!isset($result[$group->getId()])) {
             $result[$group->getId()] = array('name' => $group->getName(), 'lecture' => $lecture->getName(), 'owned' => $group->getOwner()->getId() === User::instance()->getId(), 'assignments' => array(), 'students' => array());
         }
         $assignments =& $result[$group->getId()]['assignments'];
         if (!isset($assignments[$assignment->getId()])) {
             $assignments[$assignment->getId()] = array('problem' => $problem->getName(), 'reward' => $assignment->getReward());
         }
         $students =& $result[$group->getId()]['students'];
         if (!isset($students[$s->getUser()->getId()])) {
             $students[$s->getUser()->getId()] = array('name' => $s->getUser()->getRealName(), 'ratings' => array(), 'sum' => 0);
         }
         $student =& $students[$s->getUser()->getId()];
         $ratings =& $student['ratings'];
         $ratings[$assignment->getId()] = array('id' => $s->getId(), 'rating' => $s->getRating());
         if ($s->getStatus() === \Submission::STATUS_GRADED && is_numeric($s->getRating())) {
             $student['sum'] += $s->getRating();
         }
     }
     $this->setOutput($result);
     return true;
 }