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); } }
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; }
/** * Daily update of repositories * * @param null * @return void */ function source_handle_on_frequently() { require_once ANGIE_PATH . '/classes/xml/xml2array.php'; $results = 'Repositories updated: '; $repositories = Repositories::findByUpdateType(REPOSITORY_UPDATE_FREQUENTLY); foreach ($repositories as $repository) { // don't update projects other than active ones $project = Projects::findById($repository->getProjectId()); if ($project->getStatus() !== PROJECT_STATUS_ACTIVE) { continue; } // if $repository->loadEngine(); $repository_engine = new RepositoryEngine($repository, true); $last_commit = $repository->getLastCommit(); $revision_to = is_null($last_commit) ? 1 : $last_commit->getRevision() + 1; $logs = $repository_engine->getLogs($revision_to); if (!$repository_engine->has_errors) { $repository->update($logs['data']); $total_commits = $logs['total']; $results .= $repository->getName() . ' (' . $total_commits . ' new commits); '; if ($total_commits > 0) { $repository->sendToSubscribers($total_commits, $repository_engine); $repository->createActivityLog($total_commits); } // if } // if } // foreach return is_foreachable($repositories) && count($repositories) > 0 ? $results : 'No repositories for frequently update'; }
protected function body() { if (!$this->userHasPrivileges(User::groupsJoinPublic, User::groupsJoinPrivate, User::groupsRequest)) { return false; } $user = User::instance(); $displayPublic = $user->hasPrivileges(User::groupsJoinPublic); $displayPrivate = $user->hasPrivileges(User::groupsJoinPrivate, User::groupsRequest); /** * @var $groups \Group[] * @var $subscriptions \Subscription[] */ $subscriptions = Repositories::getRepository(Repositories::Subscription)->findBy(array('user' => $user->getId())); $subscriptionGroupIds = array_map(function ($subscription) { /** @var $subscription \Subscription */ return $subscription->getGroup()->getId(); }, $subscriptions); $conditions = array('deleted' => false); if (!$displayPrivate) { $conditions['type'] = 'public'; } if (!$displayPublic) { $conditions['type'] = 'private'; } $groups = Repositories::getRepository(Repositories::Group)->findBy($conditions); foreach ($groups as $group) { if (in_array($group->getId(), $subscriptionGroupIds)) { continue; } $row = array($group->getId(), $group->getName(), $group->getDescription(), $group->getType(), $group->getLecture()->getId(), $group->getLecture()->getName(), $group->getLecture()->getDescription()); $this->addRowToOutput($row); } 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); }
/** * 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::pluginsExplore, User::lecturesManageOwn, User::lecturesManageAll)) { return false; } /** @var \Plugin[] $plugins */ $plugins = Repositories::getRepository(Repositories::Plugin)->findAll(); foreach ($plugins as $plugin) { $this->addRowToOutput([$plugin->getId(), $plugin->getName(), $plugin->getType(), $plugin->getDescription(), $plugin->getConfig()]); } return true; }
protected function fork($pathOrUrl) { $rs = new Repositories(); $new = $rs->createNew(); $vc = $new->getVc(); //VersionControl_Git wants an existing dir, git clone not \rmdir($new->gitDir); $cmd = $vc->getCommand('clone')->addArgument('--separate-git-dir')->addArgument($GLOBALS['phorkie']['cfg']['gitdir'] . '/' . $new->id . '.git')->addArgument($pathOrUrl)->addArgument($new->workDir); try { $cmd->execute(); } catch (\Exception $e) { //clean up, we've got no workdir otherwise $new->delete(); throw $e; } $rs = new Repository_Setup($new); $rs->afterInit(); //update info for dumb git HTTP transport //the post-update hook should do that IMO, but does not somehow $vc->getCommand('update-server-info')->execute(); return $new; }
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::groupsJoinPublic, User::groupsJoinPrivate, User::groupsRequest)) { return false; } $subscriptions = Repositories::getRepository(Repositories::Subscription)->findBy(['user' => User::instance()->getId()]); foreach ($subscriptions as $subscription) { /** * @var $subscription \Subscription */ $this->addRowToOutput([$subscription->getId(), $subscription->getGroup()->getName(), $subscription->getGroup()->getDescription(), $subscription->getGroup()->getLecture()->getName(), $subscription->getGroup()->getLecture()->getDescription(), $subscription->getStatus()]); } return true; }
protected function body() { if (!$this->userHasPrivileges(User::usersAdd, User::usersManage, User::usersPrivPresets)) { return false; } $userTypes = Repositories::getRepository(Repositories::UserType)->findAll(); /** * @var $userTypes \UserType[] */ foreach ($userTypes as $userType) { $this->addRowToOutput([$userType->getId(), $userType->getName(), User::instance()->unpackPrivileges($userType->getPrivileges())]); } return true; }
protected function body() { if (!$this->userHasPrivileges(User::pluginsTest)) { return false; } /** * @var $tests \PluginTest[] */ $tests = Repositories::getRepository(Repositories::PluginTest)->findAll(); foreach ($tests as $test) { $this->addRowToOutput([$test->getId(), $test->getDescription(), $test->getPlugin()->getName(), $test->getPlugin()->getDescription(), $test->getPlugin()->getConfig(), $test->getConfig(), $test->getStatus(), $test->getSuccess(), $test->getInfo(), $test->getOutput() ? "yes" : ""]); } 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->userHasPrivileges(User::usersExplore)) { return; } /** * @var $users \User[] */ $users = Repositories::getRepository(Repositories::User)->findAll(); foreach ($users as $user) { if ($user->getDeleted() == true) { continue; } $this->addRowToOutput([$user->getId(), $user->getName(), $user->getType()->getId(), $user->getType()->getName(), $user->getRealName(), $user->getEmail(), $user->getLastAccess()->format("Y-m-d H:i:s")]); } }
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; }
protected function body() { if (!$this->userHasPrivileges(User::assignmentsSubmit)) { return; } /** * @var $submissions \Submission[] */ $submissions = Repositories::getRepository(Repositories::Submission)->findBy(['user' => User::instance()->getId()]); foreach ($submissions as $submission) { if ($submission->getStatus() == \Submission::STATUS_DELETED) { continue; } $row = [$submission->getId(), $submission->getAssignment()->getProblem()->getName(), $submission->getAssignment()->getDeadline()->format("Y-m-d H:i:s"), $submission->getDate()->format("Y-m-d H:i:s"), $submission->getStatus(), $submission->getSuccess(), $submission->getInfo(), $submission->getRating(), $submission->getExplanation(), $submission->getOutputfile() != '']; $this->addRowToOutput($row); } }
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::groupsAdd, User::groupsManageAll, User::groupsManageOwn)) { return false; } $user = User::instance(); $displayAll = $user->hasPrivileges(User::groupsManageAll); $groups = $displayAll ? Repositories::getRepository(Repositories::Group)->findBy(array('deleted' => false)) : Repositories::getRepository(Repositories::Group)->findBy(array('deleted' => false, 'owner' => $user->getId())); /** * @var $group \Group */ foreach ($groups as $group) { $row = array($group->getId(), $group->getName(), $group->getDescription(), $group->getType(), $group->getLecture()->getId(), $group->getLecture()->getName(), $group->getLecture()->getDescription()); $this->addRowToOutput($row); } return true; }
/** * Get all commits related to a project object * * @param integer $object_id * @return array */ function findCommitsByObject($object) { $parent_object_ids = array(); $parent_object_ids[] = $object->getId(); /** * Try to find commits related to children objects */ $task_ids = array(); if (instance_of($object, 'Ticket')) { $tasks = db_execute_all("SELECT id FROM " . TABLE_PREFIX . "project_objects WHERE parent_id = " . $object->getid() . " AND `type` = 'Task'"); if (is_foreachable($tasks)) { foreach ($tasks as $task) { $task_ids[] = $task['id']; } // foreach } // if } // if $objects_ids = array_merge($parent_object_ids, $task_ids); $commit_project_objects = CommitProjectObjects::find(array('conditions' => array("object_id IN(" . implode(',', $objects_ids) . ")"), 'order' => 'repository_id ASC, revision DESC')); if (is_foreachable($commit_project_objects)) { $commits = array(); $revisions = array(); foreach ($commit_project_objects as $commit_project_object) { if (!in_array($commit_project_object->getRevision(), $revisions)) { // prevent commits from showing more than once $revisions[] = $commit_project_object->getRevision(); $commit = Commits::findByRevision($commit_project_object->getRevision(), Repositories::findById($commit_project_object->getRepositoryId())); if (instance_of($commit, 'Commit')) { $commit->repository = Repositories::findById($commit->getProjectId()); $commits[] = $commit; } // if } // if } // foreach return group_by_date($commits); } else { return false; } // if }
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(User::lecturesAdd, User::lecturesManageAll, User::lecturesManageOwn, User::groupsAdd)) { return; } $lite = $this->getParams('lite'); $user = User::instance(); $displayAll = $user->hasPrivileges(User::lecturesManageAll) || $lite; /** * @var $lectures \Lecture[] */ $lectures = $displayAll ? Repositories::getRepository('Lecture')->findBy(array('deleted' => false)) : Repositories::getRepository('Lecture')->findBy(array('owner' => $user->getId(), 'deleted' => false)); foreach ($lectures as $lecture) { $row = array($lecture->getId(), $lecture->getName()); if (!$lite) { $row[] = $lecture->getDescription(); } $this->addRowToOutput($row); } }
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->isInputSet(array('name', 'table'))) { return false; } $table = $this->getParams('table'); $name = strtolower($this->getParams('name')); $columnName = "name"; switch ($table) { case 'groups': $repositoryName = Repositories::Group; break; case 'lectures': $repositoryName = Repositories::Lecture; break; case 'plugins': $repositoryName = Repositories::Plugin; break; case 'problems': $repositoryName = Repositories::Problem; break; case 'users': $repositoryName = Repositories::User; break; case 'usertypes': $repositoryName = Repositories::UserType; break; default: return $this->stop('name duplicity check cannot be performed on table' . $table); } $repository = Repositories::getRepository($repositoryName); $results = $repository->findBy([$columnName => $name]); $nameConflict = count($results) > 0; if ($table == 'groups' || $table == 'lectures' || $table == 'problems') { $nameConflict = false; // For these three, we now allow duplicate names. } $this->addOutput('nameTaken', $nameConflict); return true; }
/** * Get CreatedBy information * * @param Repository $repository * @return User */ function getCreatedBy($repository = null) { if (is_null($repository)) { $repository = Repositories::findById($this->getParentId()); $repository->mapped_users = SourceUsers::findByRepository($repository); } // if if (isset($repository->mapped_users[$this->getCreatedByName()]) && instance_of($repository->mapped_users[$this->getCreatedByName()], 'SourceUser')) { $source_user = $repository->mapped_users[$this->getCreatedByName()]; if (instance_of($source_user->system_user, 'User')) { return $source_user->system_user; } // if } // if return parent::getCreatedBy(); }
/** * List of repositories * */ function index() { $this->addBreadcrumb(lang('List')); $repositories = Repositories::findByProjectId($this->active_project->getId()); $this->smarty->assign(array('repositories' => $repositories, 'page_back_url' => assemble_url('mobile_access_view_project', array('project_id' => $this->active_project->getId())))); }
<?php namespace QueryL10n; // Autoloading of composer dependencies $root_folder = realpath(__DIR__ . '/../..'); require_once "{$root_folder}/vendor/autoload.php"; $source_path = "{$root_folder}/app/sources/"; $repos = new Repositories($source_path); $available_repositories = $repos->getRepositories(); $errors = []; // Check if there are duplicated display_order values $order = []; foreach ($available_repositories as $repo_data) { $repo_order = $repo_data['display_order']; if ($repo_order == 0) { continue; } if (!in_array($repo_order, $order)) { $order[] = $repo_order; } else { $errors[] = "Repository *{$repo_data['id']}* has a duplicated display_order ({$repo_order})"; } } // Check if display_order values are not sequential sort($order); for ($i = 0; $i < count($order) - 1; $i++) { if ($order[$i] + 1 != $order[$i + 1]) { $errors[] = "display_order value is not sequential ({$order[$i + 1]})"; } }
protected function handleRequest(\Subscription $subscriptionRequest) { $subscriptionRequest->setStatus(\Subscription::STATUS_SUBSCRIBED); Repositories::persistAndFlush($subscriptionRequest); }
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; }
protected function handleRequest(\Subscription $subscriptionRequest) { Repositories::remove($subscriptionRequest); }
/** * List repositories * * @param null * @return void */ function index() { if (Repository::canAdd($this->logged_user, $this->active_project)) { $this->wireframe->addPageAction(lang('Add Repository'), source_module_add_repository_url($this->active_project)); } // if $repositories = Repositories::findByProjectId($this->active_project->getId()); $this->smarty->assign(array('repositories' => Repositories::findByProjectId($this->active_project->getId()))); }