Exemplo n.º 1
0
 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());
 }
Exemplo n.º 2
0
 /**
  * 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(RightPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = RightQuery::create()->filterByPrimaryKey($this->getPrimaryKey());
         $ret = $this->preDelete($con);
         // denyable behavior
         if (!(RightPeer::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;
     }
 }
Exemplo n.º 3
0
 /**
  * If this collection has already been initialized with
  * an identical criteria, it returns the collection.
  * Otherwise if this Page is new, it will return
  * an empty collection; or if this Page has previously
  * been saved, it will retrieve related Rights from storage.
  *
  * This method is protected by default in order to keep the public
  * api reasonable.  You can provide public methods for those you
  * actually need in Page.
  *
  * @param Criteria $criteria optional Criteria object to narrow the query
  * @param PropelPDO $con optional connection object
  * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN)
  * @return PropelObjectCollection|Right[] List of Right objects
  */
 public function getRightsJoinUserRelatedByUpdatedBy($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
 {
     $query = RightQuery::create(null, $criteria);
     $query->joinWith('UserRelatedByUpdatedBy', $join_behavior);
     return $this->getRights($query, $con);
 }
Exemplo n.º 4
0
 /**
  * Returns a new RightQuery object.
  *
  * @param     string $modelAlias The alias of a model in the query
  * @param   RightQuery|Criteria $criteria Optional Criteria to build the query from
  *
  * @return RightQuery
  */
 public static function create($modelAlias = null, $criteria = null)
 {
     if ($criteria instanceof RightQuery) {
         return $criteria;
     }
     $query = new RightQuery(null, null, $modelAlias);
     if ($criteria instanceof Criteria) {
         $query->mergeWith($criteria);
     }
     return $query;
 }