public function modifyQuery(Doctrine_Query $query) { if (!$this->getNode()->isRoot()) { $nodes = $this->getNode()->getDescendants(null, true); if ($nodes) { $sectionIds = array(); foreach ($nodes as $node) { $sectionIds[] = $node->id; } $query->whereIn('t.talk_section_id', $sectionIds); } } }
function buildQuery(Doctrine_Query $query) { $query->orderBy('swBlogComment.created_at ASC'); $query->leftJoin('swBlogComment.swBlogPost'); if ($this->getValue('moderated') == -2) { $query->whereIn('swBlogComment.moderated', array(swBlogComment::MODERATED_NONE, swBlogComment::MODERATED_OK)); } if ($this->getValue('moderated') == -1) { $query->whereIn('swBlogComment.moderated', array(swBlogComment::MODERATED_NONE)); } if ($this->getValue('moderated') == -3) { $query->whereIn('swBlogComment.moderated', array(swBlogComment::MODERATED_KO, swBlogComment::MODERATED_OK)); } if ($this->getValue('moderated') == 1) { $query->whereIn('swBlogComment.moderated', array(swBlogComment::MODERATED_OK)); } if ($this->getValue('moderated') === 0) { $query->whereIn('swBlogComment.moderated', array(swBlogComment::MODERATED_KO)); } if (is_numeric($this->getValue('post_id'))) { $query->addWhere('swBlogComment.post_id = ?', $this->getValue('post_id')); } return $query; }
public function linkInDb($alias, $ids) { $identifier = array_values($this->identifier()); $identifier = array_shift($identifier); $rel = $this->getTable()->getRelation($alias); if ($rel instanceof Doctrine_Relation_Association) { $modelClassName = $rel->getAssociationTable()->getComponentName(); $localFieldName = $rel->getLocalFieldName(); $localFieldDef = $rel->getAssociationTable()->getColumnDefinition($localFieldName); if ($localFieldDef['type'] == 'integer') { $identifier = (int) $identifier; } $foreignFieldName = $rel->getForeignFieldName(); $foreignFieldDef = $rel->getAssociationTable()->getColumnDefinition($foreignFieldName); if ($foreignFieldDef['type'] == 'integer') { for ($i = 0, $l = count($ids); $i < $l; $i++) { $ids[$i] = (int) $ids[$i]; } } foreach ($ids as $id) { $record = new $modelClassName(); $record[$localFieldName] = $identifier; $record[$foreignFieldName] = $id; $record->save(); } } else { if ($rel instanceof Doctrine_Relation_ForeignKey) { $q = new Doctrine_Query(); $q->update($rel->getTable()->getComponentName())->set($rel->getForeign(), '?', array_values($this->identifier())); if (count($ids) > 0) { $q->whereIn($rel->getTable()->getIdentifier(), $ids); } $q->execute(); } else { if ($rel instanceof Doctrine_Relation_LocalKey) { $q = new Doctrine_Query(); $q->update($this->getTable()->getComponentName())->set($rel->getLocalFieldName(), '?', $ids); if (count($ids) > 0) { $q->whereIn($rel->getTable()->getIdentifier(), array_values($this->identifier())); } $q->execute(); } } } return $this; }
/** * Create the query for selecting objects, eventually along with related * objects * * @param array $params an array of criterions for the selection */ public function addToQuery(Doctrine_Query $query, $params) { if (isset($sort)) { $query->orderBy($sort); } if (isset($params['id'])) { $values = explode(',', $params['id']); if (count($values) == 1) { $query->andWhere($this->model . '.id = ?', $values[0]); } else { $query->whereIn($this->model . '.id', $values); } unset($params['id']); } foreach ($params as $name => $value) { $query->andWhere($this->model . '.' . $name . ' = ?', $value); } return $query; }
/** * Adds a new condition to the current query * $filter is the value to be filtered * $op is the opreand to be used: =,>=, like, llike,REGEX, * $completeField. use the index $completField['field'] to * specify the field, to avoid ambiguous * * @param $filter * @param $op * @param $completeField * @return Bvb_Grid_Source_Doctrine */ public function addCondition($filter, $op, $completeField) { $field = $completeField['field']; /** * FIX : #218 * We need to make sure to use HAVING when there is function * in the select, as you cannot use these selected fields in the * WHERE clause, and all others will use the WHERE clause */ $func = 'addWhere'; if (strpos($field, '(') !== false) { $func = 'addHaving'; } switch (strtolower($op)) { case 'sqlexp': $this->_query->{$func}($filter); break; case 'isnull': $this->_query->{$func}($field . ' IS NULL '); break; case 'isnnotull': $this->_query->{$func}($field . ' IS NOT NULL '); break; case 'empty': $this->_query->{$func}($field . " =''"); break; case 'equal': case '=': $this->_query->{$func}($field . ' = ?', $filter); break; case 'regex': $this->_query->{$func}($field . " REGEXP ?", $filter); break; case 'rlike': $this->_query->{$func}($field . " LIKE ?", $filter . "%"); break; case 'llike': $this->_query->{$func}($field . " LIKE ?", "%" . $filter); break; case '>=': $this->_query->{$func}($field . " >= ?", $filter); break; case '>': $this->_query->{$func}($field . " > ?", $filter); break; case '<>': case '!=': $this->_query->{$func}($field . " <> ?", $filter); break; case '<=': $this->_query->{$func}($field . " <= ?", $filter); break; case '<': $this->_query->{$func}($field . " < ?", $filter); break; case 'in': $filter = explode(',', $filter); $this->_query->whereIn($field, $filter); break; case '&': case 'and': case 'AND': case 'flag': case 'FLAG': $this->_query->{$func}($field . " & ? <> 0", $filter); break; case 'range': $start = substr($filter, 0, strpos($filter, '<>')); $end = substr($filter, strpos($filter, '<>') + 2); $this->_query->{$func}($field . " between ? and ?", array($start, $end)); break; case '||': $this->_query->orWhere($field . " LIKE ?", "%" . $filter . "%"); break; case 'like': default: $this->_query->{$func}($field . " LIKE ?", "%" . $filter . "%"); break; } return $this; }
public function addTagsListColumnQuery(Doctrine_Query $query, $field, $values) { if (!is_array($values)) { $values = array($values); } else { $values = array_keys($values); } if (!count($values)) { return; } $ids = Doctrine::getTable('tagging')->createQuery()->select('taggable_id')->leftJoin('tagging.Tag tag')->where('taggable_model = ?', $this->getModelName())->andWhereIn('tag.name', $values)->groupBy('taggable_id')->execute(array(), Doctrine::HYDRATE_SCALAR); $ids = array_map(create_function('$i', 'return $i["tagging_taggable_id"];'), $ids); if (empty($ids)) { $query->where('false'); } else { $query->whereIn($query->getRootAlias() . '.id', $ids); } }
/** * Applies the alarming attribute to a given query retrieving products. * * @param Doctrine_Query $query - query to have alarming attribute applied. * @param Integer $value - alarming? */ public function applyDealIdFilter($query, $value) { $rootAlias = $query->getRootAlias(); $dm = MongoManager::getDM(); $yas = $dm->getRepository('Documents\\YiidActivity')->findBy(array('d_id' => intval($value))); $user_ids = array(); foreach ($yas as $ya) { $user_ids[] = $ya->getUId(); } $user_ids = array_unique($user_ids); if (count($user_ids) == 0) { $user_ids[] = -1; } $query->whereIn($rootAlias . '.id', $user_ids); return $query; }
/** * unlink * removes links from this record to given records * if no ids are given, it removes all links * * @param string $alias related component alias * @param array $ids the identifiers of the related records * @return Doctrine_Record this object */ public function unlink($alias, $ids = array()) { $ids = (array) $ids; $q = new Doctrine_Query(); $rel = $this->getTable()->getRelation($alias); if ($rel instanceof Doctrine_Relation_Association) { $q->delete()->from($rel->getAssociationTable()->getComponentName())->where($rel->getLocal() . ' = ?', array_values($this->identifier())); if (count($ids) > 0) { $q->whereIn($rel->getForeign(), $ids); } $q->execute(); } else { if ($rel instanceof Doctrine_Relation_ForeignKey) { $q->update($rel->getTable()->getComponentName())->set($rel->getForeign(), '?', array(null))->addWhere($rel->getForeign() . ' = ?', array_values($this->identifier())); if (count($ids) > 0) { $q->whereIn($rel->getTable()->getIdentifier(), $ids); } $q->execute(); } } if (isset($this->_references[$alias])) { foreach ($this->_references[$alias] as $k => $record) { if (in_array(current($record->identifier()), $ids)) { $this->_references[$alias]->remove($k); } } $this->_references[$alias]->takeSnapshot(); } return $this; }