コード例 #1
0
ファイル: PluginaPage.class.php プロジェクト: verenate/gri
 public function setAccessesById($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('aAccess 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 aAccess();
         $access->user_id = $id;
         $access->privilege = $privilege;
         $access->page_id = $this->id;
         $access->save();
     }
 }
コード例 #2
0
 /**
  * DOCUMENT ME
  * @param mixed $page
  * @param mixed $userId
  * @param mixed $privilege
  * @param mixed $set
  * @param mixed $applyToSubpages
  */
 protected function setAccessForPrivilege($page, $userId, $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 aAccess();
             $access->user_id = $userId;
             $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('aAccess a')->andWhereIn('a.page_id', $ids)->andWhere('a.user_id = ?', $userId)->andWhere('a.privilege = ?', $privilege)->execute();
     }
 }