public function addRole($sRoleName) { $aRoles = func_get_args(); foreach ($aRoles as $mRole) { if (!$mRole instanceof Role) { $mRole = RoleQuery::create()->createOrFindPk($mRole); } GroupRoleQuery::create()->createOrFind($this, $mRole); } }
public function saveData($aRoleData) { $oRole = null; if ($this->sRoleId === null) { $oRole = new Role(); } else { $oRole = RoleQuery::create()->findPk($this->sRoleId); // If the role_key has changed and the new key does not exist yet, delete the current role and create a new one if ($oRole->getRoleKey() !== $aRoleData['role_key']) { if (RoleQuery::create()->filterByRoleKey($aRoleData['role_key'])->count() === 0) { $oRole->delete(); $oRole = new Role(); } } } $this->validate($aRoleData, $oRole); if (!Flash::noErrors()) { throw new ValidationException(); } $oRole->setRoleKey($aRoleData['role_key']); $oRole->setDescription($aRoleData['description']); if (isset($aRoleData['page_id'])) { if (!$oRole->isNew()) { RightQuery::create()->filterByRole($oRole)->delete(); } $aRights = array(); foreach ($aRoleData['page_id'] as $iCounter => $sPageId) { $sRightKey = $sPageId . ($aRoleData['is_inherited'][$iCounter] ? "_inherited" : "_uninherited"); if (isset($aRights[$sRightKey])) { $oRight = $aRights[$sRightKey]; $oRight->setMayEditPageContents($oRight->getMayEditPageContents() || $aRoleData['may_edit_page_contents'][$iCounter]); $oRight->setMayEditPageDetails($oRight->getMayEditPageDetails() || $aRoleData['may_edit_page_details'][$iCounter]); $oRight->setMayDelete($oRight->getMayDelete() || $aRoleData['may_delete'][$iCounter]); $oRight->setMayCreateChildren($oRight->getMayCreateChildren() || $aRoleData['may_create_children'][$iCounter]); $oRight->setMayViewPage($oRight->getMayViewPage() || $aRoleData['may_view_page'][$iCounter]); } else { $oRight = new Right(); $oRight->setPageId($sPageId); $oRight->setRole($oRole); $oRight->setIsInherited($aRoleData['is_inherited'][$iCounter]); $oRight->setMayEditPageContents($aRoleData['may_edit_page_contents'][$iCounter]); $oRight->setMayEditPageDetails($aRoleData['may_edit_page_details'][$iCounter]); $oRight->setMayDelete($aRoleData['may_delete'][$iCounter]); $oRight->setMayCreateChildren($aRoleData['may_create_children'][$iCounter]); $oRight->setMayViewPage($aRoleData['may_view_page'][$iCounter]); $aRights[$sRightKey] = $oRight; } } foreach ($aRights as $oRight) { $oRight->save(); } } $oRole->save(); return array('id' => $oRole->getRoleKey()); }
public function getCriteria() { // select all $oQuery = RoleQuery::create()->distinct(); if ($this->oDelegateProxy->getGroupId() === CriteriaListWidgetDelegate::SELECT_ALL) { return $oQuery->joinGroupRole(null, Criteria::LEFT_JOIN); } // select specific group if (is_numeric($this->oDelegateProxy->getGroupId())) { return $oQuery->useGroupRoleQuery(null, Criteria::LEFT_JOIN)->useGroupQuery(null, Criteria::LEFT_JOIN)->filterById($this->oDelegateProxy->getGroupId())->endUse()->endUse(); } // select roles not included in a group return $oQuery->useGroupRoleQuery(null, Criteria::LEFT_JOIN)->useGroupQuery(null, Criteria::LEFT_JOIN)->filterById(null, Criteria::ISNULL)->endUse()->endUse(); }
/** * Get the associated Role object * * @param PropelPDO $con Optional Connection object. * @param $doQuery Executes a query to get the object if required * @return Role The associated Role object. * @throws PropelException */ public function getRole(PropelPDO $con = null, $doQuery = true) { if ($this->aRole === null && ($this->role_key !== "" && $this->role_key !== null) && $doQuery) { $this->aRole = RoleQuery::create()->findPk($this->role_key, $con); /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. $this->aRole->addRights($this); */ } return $this->aRole; }
/** * Removes this object from datastore and sets delete attribute. * * @param PropelPDO $con * @return void * @throws PropelException * @throws Exception * @see BaseObject::setDeleted() * @see BaseObject::isDeleted() */ public function delete(PropelPDO $con = null) { if ($this->isDeleted()) { throw new PropelException("This object has already been deleted."); } if ($con === null) { $con = Propel::getConnection(RolePeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } $con->beginTransaction(); try { $deleteQuery = RoleQuery::create()->filterByPrimaryKey($this->getPrimaryKey()); $ret = $this->preDelete($con); // denyable behavior if (!(RolePeer::isIgnoringRights() || $this->mayOperate("delete"))) { throw new PropelException(new NotPermittedException("delete.by_role", array("role_key" => "users"))); } if ($ret) { $deleteQuery->delete($con); $this->postDelete($con); $con->commit(); $this->setDeleted(true); } else { $con->commit(); } } catch (Exception $e) { $con->rollBack(); throw $e; } }
/** * Returns the number of related Role objects. * * @param Criteria $criteria * @param boolean $distinct * @param PropelPDO $con * @return int Count of related Role objects. * @throws PropelException */ public function countRolesRelatedByUpdatedBy(Criteria $criteria = null, $distinct = false, PropelPDO $con = null) { $partial = $this->collRolesRelatedByUpdatedByPartial && !$this->isNew(); if (null === $this->collRolesRelatedByUpdatedBy || null !== $criteria || $partial) { if ($this->isNew() && null === $this->collRolesRelatedByUpdatedBy) { return 0; } if ($partial && !$criteria) { return count($this->getRolesRelatedByUpdatedBy()); } $query = RoleQuery::create(null, $criteria); if ($distinct) { $query->distinct(); } return $query->filterByUserRelatedByUpdatedBy($this)->count($con); } return count($this->collRolesRelatedByUpdatedBy); }
/** * Removes this object from datastore and sets delete attribute. * * @param PropelPDO $con * @return void * @throws PropelException * @see BaseObject::setDeleted() * @see BaseObject::isDeleted() */ public function delete(PropelPDO $con = null) { if ($this->isDeleted()) { throw new PropelException("This object has already been deleted."); } if ($con === null) { $con = Propel::getConnection(RolePeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } $con->beginTransaction(); try { $ret = $this->preDelete($con); if ($ret) { RoleQuery::create()->filterByPrimaryKey($this->getPrimaryKey())->delete($con); $this->postDelete($con); $con->commit(); $this->setDeleted(true); } else { $con->commit(); } } catch (PropelException $e) { $con->rollBack(); throw $e; } }