Example #1
0
 /**
  * Check a record belongs to the currently logged in user.
  * This check is based on the author_id column.
  *
  * @param array $data The record data. Primary key must be present here.
  * @param string $where A WHERE clause to find the record
  * @return bool
  */
 protected function _itemBelongsToUser($data, $where = false)
 {
     $userData = Garp_Auth::getInstance()->getUserData();
     $userId = $userData['id'];
     if (!array_key_exists('author_id', $data)) {
         if (!$where) {
             return false;
         }
         // fetch the record based on the given WHERE clause
         $row = $this->_model->fetchRow($where);
         if (!$row || !$row->author_id) {
             return false;
         }
         $data = $row->toArray();
     }
     return $userId == $data['author_id'];
 }
Example #2
0
 /**
  * Return the current weight of a set of records.
  * Note that only the first record found will be used. Working with multiple records
  * (which is possible using Zend's update() functionality) is not implemented.
  * @param Garp_Model $model
  * @param String $where
  * @param Array $modelRelationConfig 
  * @return Int
  */
 public function findCurrentWeight(Garp_Model $model, $where, $foreignKey, array $modelRelationConfig)
 {
     $foreignKeyColumn = $model->getAdapter()->quoteIdentifier($modelRelationConfig[self::FOREIGN_KEY_COLUMN_KEY]);
     $weightColumn = $modelRelationConfig[self::WEIGHT_COLUMN_KEY];
     $select = $model->select()->from($model->getName(), array('weight' => $weightColumn))->where($foreignKeyColumn . ' = ?', $foreignKey);
     $where = (array) $where;
     foreach ($where as $w) {
         $select->where($w);
     }
     $result = $model->fetchRow($select);
     if ($result && $result->weight) {
         return $result->weight;
     }
     return 0;
 }