Esempio n. 1
0
 protected function addForeignKeyQuery(Doctrine_Query $query, $field, $value)
 {
     $fieldName = $this->getFieldName($field);
     if (is_array($value)) {
         $query->andWhereIn(sprintf('%s.%s', $this->getRootAlias($query, $fieldName), $fieldName), $value);
     } else {
         $query->addWhere(sprintf('%s.%s = ?', $this->getRootAlias($query, $fieldName), $fieldName), $value);
     }
 }
  protected function addClassIdColumnQuery(Doctrine_Query $query, $field, $value)
  {
    $rootalias = 'l';
    
    $fieldName = $this->getFieldName($field);

    if (is_array($value))
    {
      $query->andWhereIn(sprintf('%s.%s', $rootalias, $fieldName), $value);
    }
    else
    {
      $query->addWhere(sprintf('%s.%s = ?', $rootalias, $fieldName), $value);
    }
  }
/**
 * Add a 'whereIn' or 'whereNotIn' to a Doctrine_Query
 *
 * @param Doctrine_Query $q
 * @param string  $wherein
 * @param string  $column
 */
function air2_query_in(Doctrine_Query $q, $wherein, $column)
{
    if (is_string($wherein) && strlen($wherein) && $wherein != '*') {
        $ins = str_split($wherein);
        if ($ins[0] == '!') {
            array_splice($ins, 0, 1);
            if (count($ins) > 0) {
                $q->andWhereNotIn($column, $ins);
            }
        } else {
            if (count($ins) > 0) {
                $q->andWhereIn($column, $ins);
            }
        }
    }
}
 /**
  * Appends the necessary clauses to an existing query in order to restrict the query.
  *
  * @param Doctrine_Query $query
  *
  * @return void
  */
 protected function appendQuery(Doctrine_Query $query)
 {
     if (!self::isActive()) {
         return;
     }
     $target = $this->getTarget();
     // null means unlimited access
     if ($target === null) {
         return;
     }
     $field = $this->getField();
     // if we are dealing with an array, generate an IN statement
     if (is_array($target)) {
         // just kill the query if target is empty
         if (empty($target)) {
             $query->andWhere('true=false');
             return;
         }
         $query->andWhereIn($field, $target);
         return;
     }
     // otherwise it is a scalar and we generate a normal where AND statement
     $query->andWhere($field . ' = ?', $target);
 }
Esempio n. 5
0
 public function andWhereIn($expr, $params = array(), $not = false)
 {
     if (isset($params) && count($params) == 0) {
         if (!$not) {
             return $this->andWhere('0 = 1');
         } else {
             return parent::andWhereIn($expr, $params, $not);
         }
     }
     $this->addWhereInCount(count($params));
     if ($not) {
         $this->andWhere($expr . ' NOT IN ?', array($params));
     } else {
         $this->andWhere($expr . ' IN ?', array($params));
     }
     return $this;
 }
 public function addActivityQuery(Doctrine_Query $q, $memberId = null, $viewerMemberId = null, $isCheckApp = true)
 {
     if (is_null($memberId)) {
         $memberId = $this->getMyMemberId();
         if (is_null($memberId)) {
             throw new LogicException('The user is not login.');
         }
     }
     if (is_null($viewerMemberId)) {
         $viewerMemberId = $this->getMyMemberId();
     }
     if (is_null($viewerMemberId)) {
         $flag = self::PUBLIC_FLAG_OPEN;
     } else {
         if ($memberId === $viewerMemberId) {
             $flag = self::PUBLIC_FLAG_PRIVATE;
         } else {
             $relation = Doctrine::getTable('MemberRelationship')->retrieveByFromAndTo($viewerMemberId, $memberId);
             if ($relation && $relation->isFriend()) {
                 $flag = self::PUBLIC_FLAG_FRIEND;
             }
             $flag = self::PUBLIC_FLAG_SNS;
         }
     }
     $q->andWhere('member_id = ?', $memberId);
     $flags = $this->getViewablePublicFlags($flag);
     if (1 === count($flags)) {
         $q->andWhere('public_flag = ?', $flags[0]);
     } else {
         $q->andWhereIn('public_flag', $flags);
     }
     $q->andWhere('in_reply_to_activity_id IS NULL');
     if ($isCheckApp) {
         if (sfConfig::get('sf_app') == 'mobile_frontend') {
             $q->andWhere('is_mobile = ?', true);
         } else {
             $q->andWhere('is_pc = ?', true);
         }
     }
 }
 public function addPublicFlagQuery(Doctrine_Query $q, $flag)
 {
     switch ($flag) {
         case self::PUBLIC_FLAG_OPEN:
             $q->andWhere('is_open = 1');
             break;
         case self::PUBLIC_FLAG_SNS:
             $q->andWhere('public_flag = ?', self::PUBLIC_FLAG_SNS);
             break;
         case self::PUBLIC_FLAG_FRIEND:
             $q->andWhereIn('public_flag', array(self::PUBLIC_FLAG_SNS, self::PUBLIC_FLAG_FRIEND));
             break;
     }
 }
 public function addPublicFlagQuery(Doctrine_Query $q, $flag)
 {
     if ($flag === self::PUBLIC_FLAG_PRIVATE) {
         return;
     }
     $flags = self::getViewablePublicFlags($flag);
     if (1 === count($flags)) {
         $q->andWhere('public_flag = ?', array_shift($flags));
     } else {
         $q->andWhereIn('public_flag', $flags);
     }
 }
 /**
  * Fixes issue where doctrine returns all records if params are an empty array
  */
 public function andWhereIn($expr, $params = array(), $not = false)
 {
     return parent::andWhereIn($expr, $params === array() ? array(0) : $params, $not);
 }
 public function addLevelColumnQuery(Doctrine_Query $query, $field, $values)
 {
     if ($values != "") {
         $levels = array();
         $pul = Doctrine::getTable('PossibleUpperLevels')->findByLevelRef($values)->toArray();
         foreach ($pul as $key => $val) {
             $levels[] = $val['level_upper_ref'];
         }
         if (count($levels) > 0) {
             $query->andWhereIn('level_ref', $levels);
         }
     }
     return $query;
 }
 /**
  * Called by dmActions->buildQuery()
  * Restreins the query to objects user can act on.
  *
  * @param Doctrine_Query $query
  */
 public function addPermissionCheckToQuery($query)
 {
     $cacheKey = sprintf('%s/%s/%s/permissionsIds', $this->user->getUser()->get('id'), $this->module->getUnderscore(), $this->action);
     if (!$this->has($cacheKey)) {
         $result = array();
         $queryResult = dmDb::table('DmUser')->getModelPermissions($this->action, $this->user->getUser());
         if (empty($queryResult)) {
             $result[] = -1;
         } else {
             foreach ($queryResult as $permission) {
                 $result[] = $permission['secure_record'];
             }
         }
         $this->set($cacheKey, $result);
     }
     return $query->andWhereIn($query->getRootAlias() . '.id', $this->get($cacheKey));
 }
 public function executeStatusesHomeTimeline(sfWebRequest $request)
 {
     $memberId = $this->getMemberId();
     $validators = array('since_id' => new sfValidatorInteger(array('required' => false, 'min' => 1)), 'max_id' => new sfValidatorInteger(array('required' => false, 'min' => 1)), 'count' => new sfValidatorInteger(array('required' => false, 'max' => 200, 'min' => 1)), 'page' => new sfValidatorInteger(array('required' => false, 'min' => 1)), 'term_user' => new sfValidatorBoolean(array('required' => false)));
     $default = array('count' => 20, 'page' => 1, 'term_user' => false);
     $params = $this->validate($validators, $default);
     $q = Doctrine::getTable('ActivityData')->createQuery();
     $dql = 'member_id = ?';
     $dqlParams = array($memberId);
     $friendIds = Doctrine::getTable('MemberRelationship')->getFriendMemberIds($memberId);
     $flags = Doctrine::getTable('ActivityData')->getViewablePublicFlags(ActivityDataTable::PUBLIC_FLAG_FRIEND);
     if ($friendIds) {
         $query = new Doctrine_Query();
         $query->andWhereIn('member_id', $friendIds);
         $query->andWhereIn('public_flag', $flags);
         $dql .= ' OR ' . implode(' ', $query->getDqlPart('where'));
         $dqlParams = array_merge($dqlParams, $friendIds, $flags);
     }
     $q->andWhere('(' . $dql . ')', $dqlParams);
     $q->andWhere('in_reply_to_activity_id IS NULL');
     $q->limit($params['count']);
     if ($params['since_id']) {
         $q->andWhere('id > ?', $params['since_id']);
     }
     if ($params['max_id']) {
         $q->andWhere('id <= ?', $params['max_id']);
     }
     if (1 !== $params['page']) {
         $q->offset(($params['page'] - 1) * $params['count']);
     }
     $activities = $q->orderBy('id DESC')->execute();
     $statuses = array();
     foreach ($activities as $activity) {
         $statuses[] = array('status' => opActivityDataConverter::activityToStatus($activity, $params['term_user']));
     }
     return $this->render(array('statuses' => $statuses));
 }
Esempio n. 13
0
 static function addRelationshipDetails(Doctrine_Query $q, $detailIds, $alias = 'r')
 {
     return $q->andWhereIn($alias . '.detail_id', (array) $detailIds);
 }