<?php require_once __DIR__ . "/../bootstrap.php"; require_once __DIR__ . "/AddUtils.php"; /* AddNGIs.php: Loads a list of scopes from an XML file and inserts them into * the doctrine prototype. * XML format is the xml input format for scope data */ $scopesFileName = __DIR__ . "/" . $GLOBALS['dataDir'] . "/Scopes.xml"; $scopes = simplexml_load_file($scopesFileName); foreach ($scopes as $scope) { $doctrineScope = new Scope(); $name = ""; foreach ($scope as $key => $value) { if ($key == "name") { $name = (string) $value; } } $doctrineScope->setName($name); $entityManager->persist($doctrineScope); } $entityManager->flush();
public static function createSampleScope($description, $name) { $scope = new Scope(); $scope->setDescription($description); $scope->setName($name); return $scope; }
/** * 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; }