Example #1
0
 public static function createSampleScope($description, $name)
 {
     $scope = new Scope();
     $scope->setDescription($description);
     $scope->setName($name);
     return $scope;
 }
Example #2
0
 /**
  * Edit an existing scope
  * @param \Scope $scope the scope to be changed
  * @param array $newValues array containing the name of the scope
  * @param \User $user user making the changes
  * @return \Scope $altered scope
  * @throws \Exception
  */
 public function editScope(\Scope $scope, $newValues, \User $user = null)
 {
     //Check the portal is not in read only mode, throws exception if it is
     $this->checkPortalIsNotReadOnlyOrUserIsAdmin($user);
     //Throws exception if user is not an administrator
     $this->checkUserIsAdmin($user);
     //Validate the values as per the GOCDB schema and check values are present and valid and check the name is unique, if it has changed.
     $this->validate($newValues, false, $scope->getName());
     //Start transaction
     $this->em->getConnection()->beginTransaction();
     // suspend auto-commit
     try {
         //set name
         $scope->setName($newValues['Name']);
         $scope->setDescription($newValues['Description']);
         $this->em->merge($scope);
         $this->em->flush();
         $this->em->getConnection()->commit();
     } catch (\Exception $e) {
         $this->em->getConnection()->rollback();
         $this->em->close();
         throw $e;
     }
     return $scope;
 }