public function indexDirectory($dir) { if (!file_exists($dir)) { throw new Doctrine_Search_Indexer_Exception('Unknown directory ' . $dir); } $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir), RecursiveIteratorIterator::LEAVES_ONLY); $files = array(); foreach ($it as $file) { $name = $file->getPathName(); if (strpos($name, '.svn') === false) { $files[] = $name; } } $q = new Doctrine_Query(); $q->delete()->from('Doctrine_File f')->where('f.url LIKE ?', array($dir . '%'))->execute(); // clear the index $q = new Doctrine_Query(); $q->delete()->from('Doctrine_File_Index i')->where('i.file_id = ?')->execute(); $conn = Doctrine_Manager::connection(); $coll = new Doctrine_Collection('Doctrine_File'); foreach ($files as $file) { $coll[]->url = $file; } $coll->save(); }
public function addSymplistIndexColumnQuery(Doctrine_Query $query, $field, $value) { if ($value) { $query->andWhere('symplist_index IS NOT NULL'); } return $query; }
private function saveRelatedAttributeSelections($embed_token) { // Get the relevant form $forms = $this->embeddedForms; if (isset($forms[$embed_token])) { $stock_forms = $forms[$embed_token]->getEmbeddedForms(); // Get the stock values from request $request_data = $this->getValue($embed_token); foreach ($request_data as $name => $form) { // Save form object if (!isset($stock_forms[$name])) { continue; } $stock_object = $stock_forms[$name]->getObject(); $stock_object->save(); $query = new Doctrine_Query(); // $stock_object->unlink('rtShopVariations', array(), true); $query->delete('rtShopStockToVariation s2v')->where('s2v.stock_id = ?', $stock_object->getId())->execute(); $values = array(); foreach ($this->getAttributes() as $attribute) { $tmp_val = $form['rt_shop_variations_list_' . $attribute->getId()]; $values[$tmp_val[0]] = $tmp_val[0]; } $stock_object->link('rtShopVariations', array_values($values), true); } } }
public function testCreateView() { $query = new Doctrine_Query($this->connection); $query->from('User'); $view = new Doctrine_View($query, 'MyView'); $this->assertEqual($view->getName(), 'MyView'); $this->assertTrue($view->getQuery() === $query); $this->assertTrue($view === $query->getView()); $this->assertTrue($view->getConnection() instanceof Doctrine_Connection); $success = true; try { $view->create(); } catch (Exception $e) { $success = false; } $this->assertTrue($success); $users = $view->execute(); $count = $this->conn->count(); $this->assertTrue($users instanceof Doctrine_Collection); $this->assertEqual($users->count(), 8); $this->assertEqual($users[0]->name, 'zYne'); $this->assertEqual($users[0]->state(), Doctrine_Record::STATE_CLEAN); $this->assertEqual($count, $this->conn->count()); $success = true; try { $view->drop(); } catch (Exception $e) { $success = false; } $this->assertTrue($success); }
public function retrieveAsso(Doctrine_Query $q) { $alias = $q->getRootAlias(); $q->select("{$alias}.name, {$alias}.login, {$alias}.description, {$alias}.logo, {$alias}.salle, {$alias}.phone, {$alias}.facebook, p.id, p.asso_id, p.couleur"); $q->leftJoin("{$alias}.Pole p"); return $q->fetchOne(); }
function buildQuery(Doctrine_Query $query) { if ($this->getValue('name')) { $query->andWhere('name LIKE ?', '%' . $this->getValue('name') . '%'); } return $query; }
/** * Count results * * @return int */ public function count() { if ($this->_rowCount === null) { $this->_rowCount = $this->_query->count(); } return $this->_rowCount; }
public function testTicket() { $q = new Doctrine_Query(); // simple query with deep relations $q->addSelect('Resume.id, Level.id, Level.label')->from('ticket384_Resume Resume')->leftJoin('Resume.KnownLanguages KnownLanguages')->leftJoin('KnownLanguages.Level Level')->leftJoin('KnownLanguages.Language Language'); try { // get the wrong resultset $aResult = $q->fetchArray(); $this->fail(); } catch (Doctrine_Query_Exception $e) { $this->pass(); } $q->free(); // now correct // we have to select at least KnownLanguages.id in order to get the Levels, // which are only reachable through the KnownLanguages, hydrated properly. $q = new Doctrine_Query(); $q->addSelect('Resume.id, Level.id, Level.label, KnownLanguages.id')->from('ticket384_Resume Resume')->leftJoin('Resume.KnownLanguages KnownLanguages')->leftJoin('KnownLanguages.Level Level')->leftJoin('KnownLanguages.Language Language'); $aResult = $q->fetchArray(); // should be setted $bSuccess = isset($aResult[0]['KnownLanguages'][0]['Level']); $this->assertTrue($bSuccess); if (!$bSuccess) { $this->fail('fetchArray doesnt hydrate nested child relations, if parent doesnt have a column selected'); } }
public function _setProgramFilterCallback(Doctrine_Query $query, $value) { if (!empty($value)) { $query->andWhere('pI.program_id = ?', $value); } return $query; }
public function addClassificationColumnQuery(Doctrine_Query $query, $field, $values) { if ($values != "") { $query->andWhere(" classification = ? ", $values); } return $query; }
public function retrieveFolderList(Doctrine_Query $q) { $alias = $q->getRootAlias(); $q->leftJoin($alias . '.Assets a'); $q->orderBy($alias . '.lft'); return $q; }
public function listPeriodeFiliereRegion(Doctrine_Query $q) { $rootAlias = $q->getRootAlias(); $q->leftJoin($rootAlias . '.CopisimFiliere c'); $q->leftJoin($rootAlias . '.CopisimRegion d'); return $q; }
public function testJoinWithConditionAndNotInClause() { // Related to ticket #1329 $q = new Doctrine_Query(); $q->parseDqlQuery("SELECT a.name, b.id FROM User a LEFT JOIN a.Phonenumber b WITH a.id NOT IN (1, 2, 3)"); $this->assertEqual($q->getSqlQuery(), "SELECT e.id AS e__id, e.name AS e__name, p.id AS p__id FROM entity e LEFT JOIN phonenumber p ON e.id = p.entity_id AND (e.id NOT IN (1, 2, 3)) WHERE (e.type = 0)"); }
public function testZeroValuesMaintained3() { $q = new Doctrine_Query(); $q->from('ZeroValueTest'); $users = $q->execute(); $this->assertIdentical($users[0]['is_super_admin'], false); }
public function load($condition) { $condition = trim($condition); $e = Doctrine_Tokenizer::sqlExplode($condition); if (count($e) > 2) { $a = explode('.', $e[0]); $field = array_pop($a); $reference = implode('.', $a); $operator = $e[1]; $value = $e[2]; $alias = $this->query->getTableAlias($reference); $map = $this->query->getAliasDeclaration($reference); $table = $map['table']; // check if value is enumerated value $enumIndex = $table->enumIndex($field, trim($value, "'")); if (substr($value, 0, 1) == '(') { // trim brackets $trimmed = Doctrine_Tokenizer::bracketTrim($value); if (substr($trimmed, 0, 4) == 'FROM' || substr($trimmed, 0, 6) == 'SELECT') { // subquery found $q = new Doctrine_Query(); $value = '(' . $q->parseQuery($trimmed)->getQuery() . ')'; } elseif (substr($trimmed, 0, 4) == 'SQL:') { $value = '(' . substr($trimmed, 4) . ')'; } else { // simple in expression found $e = Doctrine_Tokenizer::sqlExplode($trimmed, ','); $value = array(); foreach ($e as $part) { $index = $table->enumIndex($field, trim($part, "'")); if ($index !== false) { $value[] = $index; } else { $value[] = $this->parseLiteralValue($part); } } $value = '(' . implode(', ', $value) . ')'; } } else { if ($enumIndex !== false) { $value = $enumIndex; } else { $value = $this->parseLiteralValue($value); } } switch ($operator) { case '<': case '>': case '=': case '!=': if ($enumIndex !== false) { $value = $enumIndex; } default: $condition = $alias . '.' . $field . ' ' . $operator . ' ' . $value; } } return $condition; }
public function testAggregateFunctionsInHavingReturnValidSql() { $q = new Doctrine_Query(); $q->parseQuery('SELECT u.name, COUNT(p.id) count FROM User u LEFT JOIN u.Phonenumber p GROUP BY count'); $this->assertEqual($q->getQuery(), 'SELECT e.id AS e__id, e.name AS e__name, COUNT(p.id) AS p__0 FROM entity e LEFT JOIN phonenumber p ON e.id = p.entity_id WHERE (e.type = 0) GROUP BY p__0'); }
protected function addIsPublishedColumnQuery(Doctrine_Query $query, $field, $values) { if ($values) { $query->addWhere('r.date_published < NOW()'); } else { $query->addWhere('r.date_published >= NOW() OR r.date_published IS NULL'); } }
public function addVisiteurIdColumnQuery(Doctrine_Query $query, $field, $value) { //Pour le xxxx tu peux utiliser $query->getRootAlias() pour récupérer l'alias racine de ta requete if ($value['text']) { $query->leftjoin($query->getRootAlias() . ".Visiteur v"); $query->andWhere('v.pseudo_son like ?', "%" . $value['text'] . "%"); } }
/** public function testShortAliasesWithSingleComponent() { $q = new Doctrine_Query(); $q->select('u.name')->from('User u'); $this->assertEqual($q->getSqlQuery(), 'SELECT e.id AS e__id, e.name AS e__name FROM entity e WHERE (e.type = 0)'); } */ public function testShortAliasesWithOneToManyLeftJoin() { $q = new Doctrine_Query(); $q->select('u.name, p.id')->from('User u LEFT JOIN u.Phonenumber p'); $this->assertEqual($q->getSqlQuery(), 'SELECT e.id AS e__id, e.name AS e__name, p.id AS p__id FROM entity e LEFT JOIN phonenumber p ON e.id = p.entity_id WHERE (e.type = 0)'); $users = $q->execute(); $this->assertEqual($users->count(), 8); }
public function addUpcoming(Doctrine_Query $q, $limit = null) { $q->orderBy('start_date'); $q->addWhere('DATE(start_date) >= DATE(NOW())'); if (!is_null($limit)) { $q->limit($limit); } }
public function addCallerIdColumnQuery(Doctrine_Query $query, $field, $values) { if ($values != "") { $alias = $query->getRootAlias(); $query->andWhere($alias . '.id != ?', $values); } return $query; }
public function testApplyInheritance() { $query = new Doctrine_Query(); $query->from('InheritanceDeal d, d.Users u'); $query->where('u.id = 1'); $sql = 'SELECT i.id AS i__id, i.name AS i__name, i2.id AS i2__id, i2.username AS i2__username FROM inheritance_deal i LEFT JOIN inheritance_entity_user i3 ON (i.id = i3.entity_id) AND i3.type = 1 LEFT JOIN inheritance_user i2 ON i2.id = i3.user_id WHERE i2.id = 1'; $this->assertEqual($sql, $query->getSql()); }
public function addIgNumColumnQuery(Doctrine_Query $query, $field, $values) { if ($values != "") { $conn_MGR = Doctrine_Manager::connection(); $query->andWhere("ig_num_indexed like concat(fullToIndex(" . $conn_MGR->quote($values, 'string') . "), '%') "); } return $query; }
public function testQuerySetOffsetToZero() { $q = new Doctrine_Query(); $q->from('User u'); $q->offset(20); $q->offset(0); $this->assertEqual($q->getSqlQuery(), 'SELECT e.id AS e__id, e.name AS e__name, e.loginname AS e__loginname, e.password AS e__password, e.type AS e__type, e.created AS e__created, e.updated AS e__updated, e.email_id AS e__email_id FROM entity e WHERE (e.type = 0)'); }
public function filterScope(Doctrine_Query $query, sfUser $user) { //@todo: fix this shit!!!!! //this is very ugly $eventFilter = Doctrine_Query::create()->from('FishEvent fe')->select('fe.id')->where("fe.location_id in (" . Doctrine::getTable('Location')->getVisibleLocationsQuery($user, "lc1")->select('lc1.id') . ")"); $profitFilter = Doctrine_Query::create()->from('Profit pr')->select('pr.id')->where("pr.location_id in (" . Doctrine::getTable('Location')->getVisibleLocationsQuery($user, "lc2")->select('lc2.id') . ")"); return $query->andWhere("c.location_id in (" . Doctrine::getTable('Location')->getVisibleLocationsQuery($user, "lc3")->select('lc3.id') . ") or c.location_id is null")->andWhere("c.profit_id in ({$profitFilter}) or c.profit_id is null")->andWhere("c.fish_event_id in ({$eventFilter}) or c.fish_event_id is null"); }
public function testInlineMultiple() { $yml = <<<END --- DC147_Multiple: ISBN2: name: isbn2 ISBN3: name: isbn3 DC147_Product: Product_1: name: book3 MultipleValues: Multi_1: value: 123345678 Multiple: ISBN2 Multi_2: value: 232323233 Multiple: ISBN3 Product_2: name: book4 MultipleValues: Multi_3: value: 444455555 Multiple: ISBN2 Multi_4: value: 232323233 Multiple: ISBN3 END; try { file_put_contents('test.yml', $yml); Doctrine_Core::loadData('test.yml', true); $this->conn->clear(); $query = new Doctrine_Query(); $query->from('DC147_Product p, p.MultipleValues v, v.Multiple m')->where('p.name = ?', 'book3'); $product = $query->fetchOne(); $this->assertEqual($product->name, 'book3'); $this->assertEqual($product->MultipleValues->count(), 2); $this->assertEqual($product->MultipleValues[0]->value, '123345678'); $this->assertEqual(is_object($product->MultipleValues[0]->Multiple), true); $this->assertEqual($product->MultipleValues[0]->Multiple->name, 'isbn2'); $query = new Doctrine_Query(); $query->from('DC147_Product p, p.MultipleValues v, v.Multiple m')->where('p.name = ?', 'book4'); $product = $query->fetchOne(); $this->assertEqual($product->name, 'book4'); $this->assertEqual($product->MultipleValues->count(), 2); $this->assertEqual($product->MultipleValues[0]->value, '444455555'); $this->assertEqual($product->MultipleValues[1]->value, '232323233'); $this->assertEqual(is_object($product->MultipleValues[0]->Multiple), true); $this->assertEqual(is_object($product->MultipleValues[1]->Multiple), true); $this->assertEqual($product->MultipleValues[0]->Multiple->name, 'isbn2'); $this->assertEqual($product->MultipleValues[1]->Multiple->name, 'isbn3'); $this->pass(); } catch (Exception $e) { $this->fail(); } unlink('test.yml'); }
protected function addNameColumnQuery(Doctrine_Query $query, $field, $values) { $fieldName = $this->getFieldName($field); if (is_array($values)) { foreach ($values as $value) { $query->addWhere('r.' . $fieldName . ' LIKE ?', '%' . $value . '%'); } } }
/** * Typesafe call to modify * @access private **/ protected function modifyImpl(Doctrine_Query &$o) { if ($this->groupfields) { $groups = explode(",", $this->groupfields); foreach ($groups as $group) { $o->addGroupBy($group); } } }
public function testTicket() { try { $q = new Doctrine_Query(); $r = $q->from('T929_Person P')->leftJoin('P.Country Ct')->leftJoin('Ct.Translation T1 WITH T1.lang = ?', 'fr')->leftJoin('P.JobPositions J')->leftJoin('J.Category C')->leftJoin('C.Translation T2 WITH T2.lang = ?', 'fr')->where('P.name = ?', 'Jonathan')->fetchOne(); } catch (Exception $e) { $this->fail($e->getMessage()); } }
public function executeShowcase() { $q = new Doctrine_Query(); $this->madule = $q->select('m.*')->from('Madule m')->where('id = ?', array($this->getRequestParameter('id')))->fetchOne(); $this->forward404Unless($this->madule); $this->madule->setShowcase(!$this->madule->getShowcase()); $this->madule->save(); return $this->redirect($this->getRequest()->getReferer()); }