Beispiel #1
0
 /**
  * DOCUMENT ME
  * @param mixed $privilege
  * @param mixed $ids
  */
 public function setGroupAccessesById($privilege, $ids)
 {
     // Could probably be more elegant using Doctrine collections
     $query = Doctrine_Query::create();
     // Make sure we select() only a.* so that we don't wind up
     // reloading the page object and causing problems in updateObject().
     $query->select('a.*')->from('aGroupAccess a')->innerJoin('a.Page p')->where('a.privilege = ? AND p.id = ?', array($privilege, $this->id));
     $accesses = $query->execute();
     foreach ($accesses as $access) {
         if ($access->privilege === $privilege) {
             $access->delete();
         }
     }
     foreach ($ids as $id) {
         $access = new aGroupAccess();
         $access->group_id = $id;
         $access->privilege = $privilege;
         $access->page_id = $this->id;
         $access->save();
     }
 }
 /**
  * DOCUMENT ME
  * @param mixed $page
  * @param mixed $groupId
  * @param mixed $privilege
  * @param mixed $set
  * @param mixed $applyToSubpages
  */
 protected function setGroupAccessForPrivilege($page, $groupId, $privilege, $set, $applyToSubpages)
 {
     $ids = array();
     if ($applyToSubpages) {
         $results = Doctrine::getTable('aPage')->createQuery('p')->where('p.lft >= ? AND p.rgt <= ?', array($page->lft, $page->rgt))->select('p.id')->execute(array(), Doctrine::HYDRATE_SCALAR);
         foreach ($results as $result) {
             $ids[] = $result['p_id'];
         }
     } else {
         $ids = array($page->id);
     }
     if ($set) {
         foreach ($ids as $id) {
             $access = new aGroupAccess();
             $access->group_id = $groupId;
             $access->privilege = $privilege;
             $access->page_id = $id;
             $access->save();
             $access->free();
             unset($access);
         }
     } else {
         // Doctrine delete query syntax is a little odd
         Doctrine_Query::create()->delete('aGroupAccess a')->andWhereIn('a.page_id', $ids)->andWhere('a.group_id = ?', $groupId)->andWhere('a.privilege = ?', $privilege)->execute();
     }
 }