Пример #1
0
 /**
  * Get policy.
  *
  * @param UserDao $user
  * @param ItemDao $item
  * @return false|ItempolicyuserDao
  * @throws Zend_Exception
  */
 public function getPolicy($user, $item)
 {
     if (!$user instanceof UserDao) {
         throw new Zend_Exception('Should be a user.');
     }
     if (!$item instanceof ItemDao) {
         throw new Zend_Exception('Should be an item.');
     }
     return $this->initDao('Itempolicyuser', $this->database->fetchRow($this->database->select()->where('item_id = ?', $item->getKey())->where('user_id = ?', $user->getKey())));
 }
Пример #2
0
 /**
  * Set the item of the scalar result.
  *
  * @param Validation_ScalarResultDao $scalarResult target scalar result
  * @param ItemDao $item target item
  * @throws Zend_Exception
  */
 public function setItem($scalarResult, $item)
 {
     if (!$scalarResult instanceof Validation_ScalarResultDao) {
         throw new Zend_Exception('Should be a scalar result.');
     }
     if (!$item instanceof ItemDao) {
         throw new Zend_Exception('Should be an item.');
     }
     $scalarResult->setItemId($item->getKey());
     parent::save($scalarResult);
 }
Пример #3
0
 /**
  * Associate the given scalar and item.
  *
  * @param Tracker_ScalarDao $scalarDao scalar DAO
  * @param ItemDao $itemDao item DAO
  * @param string $label label
  */
 public function associateItem($scalarDao, $itemDao, $label)
 {
     $data = array('scalar_id' => $scalarDao->getKey(), 'item_id' => $itemDao->getKey(), 'label' => $label);
     $this->database->getDB()->insert('tracker_scalar2item', $data);
 }
Пример #4
0
 /**
  * Delete thumbnails on a given item. Called when item is about to be deleted.
  *
  * @param ItemDao $item
  */
 public function deleteByItem($item)
 {
     Zend_Registry::get('dbAdapter')->delete($this->_name, 'item_id = ' . $item->getKey());
 }
Пример #5
0
 /**
  * Set a single result value.
  *
  * @param Validation_DashboardDao $dashboard target dashboard
  * @param FolderDao $folder result folder with which the value is associated
  * @param ItemDao $item item associated with the result
  * @param mixed $value scalar value representing a result
  * @return Validation_ScalarResultDao
  * @throws Zend_Exception
  */
 public function setScore($dashboard, $folder, $item, $value)
 {
     if (!$dashboard instanceof Validation_DashboardDao) {
         throw new Zend_Exception('Should be a dashboard.');
     }
     if (!$folder instanceof FolderDao) {
         throw new Zend_Exception('Should be a folder.');
     }
     if (!$item instanceof ItemDao) {
         throw new Zend_Exception('Should be an item.');
     }
     /** @var Validation_ScalarResultModel $scalarResultModel */
     $scalarResultModel = MidasLoader::loadModel('ScalarResult', 'validation');
     $items = $folder->getItems();
     $tgtItem = null;
     foreach ($items as $curItem) {
         if ($curItem->getKey() == $item->getKey()) {
             $tgtItem = $curItem;
             break;
         }
     }
     if (!$tgtItem) {
         throw new Zend_Exception('Target item not part of result set.');
     }
     // remove a previous scalar value if there is one.
     $oldResults = $scalarResultModel->findBy('item_id', $tgtItem->getKey());
     if (count($oldResults) == 1) {
         $oldResult = $oldResults[0];
         $this->database->removeLink('scores', $dashboard, $oldResult);
     }
     /** @var Validation_ScalarResultDao $scalarResult */
     $scalarResult = MidasLoader::newDao('ScalarResultDao', 'validation');
     $scalarResult->setFolderId($folder->getKey());
     $scalarResult->setItemId($tgtItem->getKey());
     $scalarResult->setValue($value);
     $scalarResultModel->save($scalarResult);
     $this->database->link('scores', $dashboard, $scalarResult);
     return $scalarResult;
 }
Пример #6
0
 /**
  * Check if the policy is valid.
  *
  * @param ItemDao $itemdao
  * @param null|UserDao $userDao
  * @param int $policy
  * @return bool
  * @throws Zend_Exception
  */
 public function policyCheck($itemdao, $userDao = null, $policy = 0)
 {
     if (!$itemdao instanceof ItemDao || !is_numeric($policy)) {
         throw new Zend_Exception('Error in parameter itemdao or policy when checking Item 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' => 'itempolicyuser'), array('item_id'))->where('policy >= ?', $policy)->where('p.item_id = ?', $itemdao->getKey())->where('user_id = ? ', $userId);
     $subqueryGroup = $this->database->select()->setIntegrityCheck(false)->from(array('p' => 'itempolicygroup'), array('item_id'))->where('policy >= ?', $policy)->where('p.item_id = ?', $itemdao->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;
 }