Esempio n. 1
0
 /**
  * Check if the policy is valid.
  *
  * @param FeedDao $feedDao
  * @param null|UserDao $userDao
  * @param int $policy
  * @return bool
  * @throws Zend_Exception
  */
 public function policyCheck($feedDao, $userDao = null, $policy = 0)
 {
     if (!$feedDao instanceof FeedDao || !is_numeric($policy)) {
         throw new Zend_Exception('Error in params when checking Feed Policy.');
     }
     if ($userDao == null) {
         $userId = -1;
     } elseif (!$userDao instanceof UserDao) {
         throw new Zend_Exception('Should be an user.');
     } else {
         $userId = $userDao->getUserId();
         if ($userDao->isAdmin()) {
             return true;
         }
     }
     $subqueryUser = $this->database->select()->setIntegrityCheck(false)->from(array('p' => 'feedpolicyuser'), array('feed_id'))->where('policy >= ?', $policy)->where('p.feed_id = ?', $feedDao->getKey())->where('user_id = ? ', $userId);
     $subqueryGroup = $this->database->select()->setIntegrityCheck(false)->from(array('p' => 'feedpolicygroup'), array('feed_id'))->where('policy >= ?', $policy)->where('p.feed_id = ?', $feedDao->getKey())->where('( ' . $this->database->getDB()->quoteInto('group_id = ? ', MIDAS_GROUP_ANONYMOUS_KEY) . ' OR
                           group_id IN (' . new Zend_Db_Expr($this->database->select()->setIntegrityCheck(false)->from(array('u2g' => 'user2group'), array('group_id'))->where('u2g.user_id = ?', $userId) . '))'));
     $sql = $this->database->select()->union(array($subqueryUser, $subqueryGroup));
     $row = $this->database->fetchRow($sql);
     if ($row == null) {
         return false;
     }
     return true;
 }
 /**
  * Get policy.
  *
  * @param GroupDao $group
  * @param FeedDao $feed
  * @return false|FeedpolicygroupDao
  * @throws Zend_Exception
  */
 public function getPolicy($group, $feed)
 {
     if (!$group instanceof GroupDao) {
         throw new Zend_Exception('Should be a group.');
     }
     if (!$feed instanceof FeedDao) {
         throw new Zend_Exception('Should be a feed.');
     }
     return $this->initDao('Feedpolicygroup', $this->database->fetchRow($this->database->select()->where('feed_id = ?', $feed->getKey())->where('group_id = ?', $group->getKey())));
 }
Esempio n. 3
0
 /**
  * Get policy.
  *
  * @param UserDao $user
  * @param FeedDao $feed
  * @return false|FeedpolicyuserDao
  * @throws Zend_Exception
  */
 public function getPolicy($user, $feed)
 {
     if (!$user instanceof UserDao) {
         throw new Zend_Exception('Should be a user.');
     }
     if (!$feed instanceof FeedDao) {
         throw new Zend_Exception('Should be a feed.');
     }
     return $this->initDao('Feedpolicyuser', $this->database->fetchRow($this->database->select()->where('feed_id = ?', $feed->getKey())->where('user_id = ?', $user->getKey())));
 }