コード例 #1
0
ファイル: TestUtil.php プロジェクト: Tom-Byrne/gocdb
 public static function createSampleServiceGroup($label)
 {
     $sg = new ServiceGroup();
     $sg->setName($label);
     $sg->setMonitored(1);
     $sg->setEmail($label . "@email.com");
     return $sg;
 }
コード例 #2
0
ファイル: ServiceGroup.php プロジェクト: Tom-Byrne/gocdb
 /**
  * Array
  * (
  *     [Scope] => 2
  *     [SERVICEGROUP] => Array
  *     (
  *         [MONITORED] => Y
  *         [NAME] => TEST
  *         [DESCRIPTION] => This is a test
  *         [EMAIL] => JCasson@hithere.com
  *     )
  * )
  * @param array $values Service group values, defined above
  * @param \User $user User making the request
  */
 public function addServiceGroup($values, \User $user = null)
 {
     //Check the portal is not in read only mode, throws exception if it is
     $this->checkPortalIsNotReadOnlyOrUserIsAdmin($user);
     // Any registered user can create a service group.
     if (is_null($user)) {
         throw new \Exception("Unregistered users can't create service groups.");
     }
     if (is_null($user->getId())) {
         throw new \Exception("Unregistered users can't create service groups.");
     }
     $this->em->getConnection()->beginTransaction();
     $this->validate($values['SERVICEGROUP']);
     $this->uniqueCheck($values['SERVICEGROUP']['NAME']);
     //check there are the required number of scopes specified
     $this->checkNumberOfScopes($values['Scope_ids']);
     try {
         $sg = new \ServiceGroup();
         $sg->setName($values['SERVICEGROUP']['NAME']);
         $sg->setDescription($values['SERVICEGROUP']['DESCRIPTION']);
         $sg->setEmail($values['SERVICEGROUP']['EMAIL']);
         // Set monitored
         if ($values['MONITORED'] == "Y") {
             $sg->setMonitored(true);
         } else {
             $sg->setMonitored(false);
         }
         // Set the scopes
         foreach ($values['Scope_ids'] as $scopeId) {
             $dql = "SELECT s FROM Scope s WHERE s.id = :id";
             $scope = $this->em->createQuery($dql)->setParameter('id', $scopeId)->getSingleResult();
             $sg->addScope($scope);
         }
         $this->em->persist($sg);
         $sgAdminroleType = $this->em->createQuery("SELECT rt FROM RoleType rt WHERE rt.name = ?1")->setParameter(1, \RoleTypeName::SERVICEGROUP_ADMIN)->getSingleResult();
         $newRole = new \Role($sgAdminroleType, $user, $sg, \RoleStatus::GRANTED);
         $this->em->persist($newRole);
         $this->em->flush();
         $this->em->getConnection()->commit();
     } catch (\Exception $e) {
         $this->em->getConnection()->rollback();
         $this->em->close();
         throw $e;
     }
     return $sg;
 }