/** * Get all the RoleType names that the user has DIRECTLY over the given entity, * and optionally limit the returned RoleType names to those with the specified * RoleStatus (GRANTED by default). * * @param \OwnedEntity $entity An entity that extends OwnedEntity (Site, NGI, ServiceGroup, Project) * @param \User $user * @param string RoleStatus value * @return array of RoleType names or an empty array * @throws \LogicException if the classifications array is given and contains unknown values. */ public function getUserRoleNamesOverEntity(\OwnedEntity $entity, \User $user = null, $roleStatus = \RoleStatus::GRANTED) { //This method replaces userHasSiteRole, userHasNgiRole, userHasSGroupRole // user/entity is not manged, so return no roles. if (is_null($user)) { return array(); } if ($user->getId() == null || $entity->getId() == null) { return array(); } // Would be better to use the get_class method to determine the instance // class name, however, there have been instances where this has returned // a class name of the following form: 'DoctrineProxies\__CG__\Site' // which would cause an issue with dql query below. // //$entityClassName= get_class($entity); require_once __DIR__ . '/OwnedEntity.php'; $OwnedEntityService = new \org\gocdb\services\OwnedEntity(); $entityClassName = $OwnedEntityService->getOwnedEntityDerivedClassName($entity); $dql = "SELECT rt.name\n FROM Role r\n JOIN r.roleType rt\n JOIN r.user u\n JOIN r.ownedEntity o\n WHERE u.id = :userId\n AND o.id = :entityId\n AND r.status = :roleStatus\n AND o INSTANCE OF {$entityClassName}"; /*if ($classifications != null) { $dql = $dql." AND rt.classification IN (:classifications)"; }*/ $query = $this->em->createQuery($dql)->setParameter('userId', $user->getId())->setParameter('roleStatus', $roleStatus)->setParameter('entityId', $entity->getId()); /*if ($classifications != null) { $query->setParameter('classifications', $classifications); }*/ $roleNames = $query->getScalarResult(); //print_r($roleNames); $transform = function ($item) { return $item['name']; }; $retArray = array_map($transform, $roleNames); return $retArray; }
/** * Create a new role which establishes that the specified User has the * RoleType over the OwnedEntity. * * @param \RoleType $roleType The role's type * @param strig $name The role name * @param \User $user The role is for this user * @param \OwnedEntity $ownedEntity The role is over this entity * @param string $status The current Role status, e.g. 'STATUS_PENDING' for * role requests and 'STATUS_GRANTED' for granted roles. */ public function __construct(\RoleType $roleType, \User $user, \OwnedEntity $ownedEntity, $status) { $this->roleType = $roleType; $this->setStatus($status); //$this->setName($name); $ownedEntity->addRoleDoJoin($this); $user->addRoleDoJoin($this); // @link http://www.doctrine-project.org/blog/doctrine-2-give-me-my-constructor-back.html Using constructors in Entities }
/** * Create a new project * @param string $name The project's name */ public function __construct($name) { parent::__construct(); // Set cretion date $this->creationDate = new \DateTime("now"); $this->setName($name); $this->ngis = new ArrayCollection(); }
public function __construct() { parent::__construct(); // Set cretion date $this->creationDate = new \DateTime("now"); $this->serviceGroupProperties = new ArrayCollection(); $this->scopes = new ArrayCollection(); $this->services = new ArrayCollection(); }
public function __construct() { parent::__construct(); // Set cretion date $this->creationDate = new \DateTime("now"); $this->sites = new ArrayCollection(); $this->projects = new ArrayCollection(); $this->scopes = new ArrayCollection(); }
public function __construct() { parent::__construct(); // Make sure all dates are treated as UTC! // Set cretion date $this->creationDate = new \DateTime("now"); $this->services = new ArrayCollection(); $this->siteProperties = new ArrayCollection(); $this->scopes = new ArrayCollection(); $this->users = new ArrayCollection(); $this->certificationStatusLog = new ArrayCollection(); }