当前位置: 首页>>代码示例>>PHP>>正文


PHP ActiveQuery\ModelCriteria类代码示例

本文整理汇总了PHP中Propel\Runtime\ActiveQuery\ModelCriteria的典型用法代码示例。如果您正苦于以下问题:PHP ModelCriteria类的具体用法?PHP ModelCriteria怎么用?PHP ModelCriteria使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ModelCriteria类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: loadModelCriteria

 /**
  * @param  ModelCriteria $criteria
  * @return $this|null
  *
  * Loads a model criteria.
  * Warning: This doesn't goodly support multi table queries.
  * If you need to use more than one table, use a PDO instance and
  * use the fetchArray() method, or select every columns you need
  */
 public function loadModelCriteria(ModelCriteria $criteria)
 {
     $propelData = $criteria->find();
     if (empty($propelData)) {
         return null;
     }
     $asColumns = $propelData->getFormatter()->getAsColumns();
     /**
      * Format it correctly
      * After this pass, we MUST have a 2D array.
      * The first may be keyed with integers.
      */
     $formattedResult = $propelData->toArray(null, false, TableMap::TYPE_COLNAME);
     if (count($asColumns) > 1) {
         /**
          * Request with multiple select
          * Apply propel aliases
          */
         $formattedResult = $this->applyAliases($formattedResult, $asColumns);
     } elseif (count($asColumns) === 1) {
         /**
          * Request with one select
          */
         $key = str_replace("\"", "", array_keys($asColumns)[0]);
         $formattedResult = [[$key => $formattedResult[0]]];
     }
     $data = $this->applyAliases($formattedResult, $this->aliases);
     /**
      * Then store it
      */
     $this->data = $data;
     return $this;
 }
开发者ID:margery,项目名称:thelia,代码行数:42,代码来源:FormatterData.php

示例2: addSearchInI18nColumn

 /**
  * Add the search clause for an I18N column, taking care of the back/front context, as default_locale_i18n is
  * not defined in the backEnd I18N context.
  *
  * @param ModelCriteria $search
  * @param string $columnName the column to search into, such as TITLE
  * @param string $searchCriteria the search criteria, such as Criterial::LIKE, Criteria::EQUAL, etc.
  * @param string $searchTerm the searched term
  */
 public function addSearchInI18nColumn($search, $columnName, $searchCriteria, $searchTerm)
 {
     if (!$this->getBackendContext()) {
         $search->where("CASE WHEN NOT ISNULL(`requested_locale_i18n`.ID)\n                        THEN `requested_locale_i18n`.`{$columnName}`\n                        ELSE `default_locale_i18n`.`{$columnName}`\n                        END " . $searchCriteria . " ?", $searchTerm, \PDO::PARAM_STR);
     } else {
         $search->where("`requested_locale_i18n`.`{$columnName}` {$searchCriteria} ?", $searchTerm, \PDO::PARAM_STR);
     }
 }
开发者ID:vigourouxjulien,项目名称:thelia,代码行数:17,代码来源:BaseI18nLoop.php

示例3: genericToggleVisibility

 /**
  * Toggle visibility for an object
  *
  * @param ModelCriteria               $query
  * @param UpdateToggleVisibilityEvent $event
  *
  * @return mixed
  */
 public function genericToggleVisibility(ModelCriteria $query, ToggleVisibilityEvent $event)
 {
     if (null !== ($object = $query->findPk($event->getObjectId()))) {
         $newVisibility = !$object->getVisible();
         $object->setDispatcher($event->getDispatcher())->setVisible($newVisibility)->save();
         $event->setObject($object);
     }
     return $object;
 }
开发者ID:alex63530,项目名称:thelia,代码行数:17,代码来源:BaseAction.php

示例4: addI18nCondition

 public static function addI18nCondition(ModelCriteria $query, $i18nTableName, $tableIdColumn, $i18nIdColumn, $localeColumn, $locale)
 {
     if (null === static::$defaultLocale) {
         static::$defaultLocale = Lang::getDefaultLanguage()->getLocale();
     }
     $locale = static::realEscape($locale);
     $defaultLocale = static::realEscape(static::$defaultLocale);
     $query->_and()->where("CASE WHEN " . $tableIdColumn . " IN" . "(SELECT DISTINCT " . $i18nIdColumn . " " . "FROM `" . $i18nTableName . "` " . "WHERE locale={$locale}) " . "THEN " . $localeColumn . " = {$locale} " . "ELSE " . $localeColumn . " = {$defaultLocale} " . "END");
 }
开发者ID:margery,项目名称:thelia,代码行数:9,代码来源:I18n.php

示例5: addStandardI18nSearch

 /**
  * @param ModelCriteria $search
  * @param $searchTerm
  * @param $searchCriteria
  */
 protected function addStandardI18nSearch(&$search, $searchTerm, $searchCriteria)
 {
     foreach (self::$standardI18nSearchFields as $index => $searchInElement) {
         if ($index > 0) {
             $search->_or();
         }
         $this->addSearchInI18nColumn($search, strtoupper($searchInElement), $searchCriteria, $searchTerm);
     }
 }
开发者ID:vigourouxjulien,项目名称:thelia,代码行数:14,代码来源:StandardI18nFieldsSearchTrait.php

示例6: paginate

 public function paginate(ModelCriteria $query, $page = 1, $maxPerPage = 25)
 {
     $queryMd5 = md5($query->toString());
     $key = $query->getTableMap()->getName() . '_query_' . $queryMd5 . '_' . $page . '_' . $maxPerPage;
     $records = GlobalCache::get($key);
     if (empty($records) === true) {
         $records = $query->paginate($page, $maxPerPage);
         if ($records->isEmpty() === false) {
             GlobalCache::set($key, $records);
         }
     }
     return $records;
 }
开发者ID:benconnito,项目名称:kopper,代码行数:13,代码来源:CachedQueryFilter.php

示例7: testPreAndPostDelete

 public function testPreAndPostDelete()
 {
     $c = new ModelCriteria('bookstore', '\\Propel\\Tests\\Bookstore\\Book');
     $books = $c->find();
     $count = count($books);
     $book = $books->shift();
     $this->con->lastAffectedRows = 0;
     $c = new ModelCriteriaWithPreAndPostDeleteHook('bookstore', '\\Propel\\Tests\\Bookstore\\Book', 'b');
     $c->where('b.Id = ?', $book->getId());
     $nbBooks = $c->delete($this->con);
     $this->assertEquals(12, $this->con->lastAffectedRows, 'postDelete() is called after delete() even if preDelete() returns not null');
     $this->con->lastAffectedRows = 0;
     $c = new ModelCriteriaWithPreAndPostDeleteHook('bookstore', '\\Propel\\Tests\\Bookstore\\Book');
     $nbBooks = $c->deleteAll($this->con);
     $this->assertEquals(12, $this->con->lastAffectedRows, 'postDelete() is called after deleteAll() even if preDelete() returns not null');
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:16,代码来源:ModelCriteriaHooksTest.php

示例8: getBackEndI18n

 public static function getBackEndI18n(ModelCriteria &$search, $requestedLocale, $columns = array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'), $foreignTable = null, $foreignKey = 'ID')
 {
     if ($foreignTable === null) {
         $foreignTable = $search->getTableMap()->getName();
         $aliasPrefix = '';
     } else {
         $aliasPrefix = $foreignTable . '_';
     }
     $requestedLocaleI18nAlias = $aliasPrefix . 'requested_locale_i18n';
     $requestedLocaleJoin = new Join();
     $requestedLocaleJoin->addExplicitCondition($search->getTableMap()->getName(), $foreignKey, null, $foreignTable . '_i18n', 'ID', $requestedLocaleI18nAlias);
     $requestedLocaleJoin->setJoinType(Criteria::LEFT_JOIN);
     $search->addJoinObject($requestedLocaleJoin, $requestedLocaleI18nAlias)->addJoinCondition($requestedLocaleI18nAlias, '`' . $requestedLocaleI18nAlias . '`.LOCALE = ?', $requestedLocale, null, \PDO::PARAM_STR);
     $search->withColumn('NOT ISNULL(`' . $requestedLocaleI18nAlias . '`.`ID`)', $aliasPrefix . 'IS_TRANSLATED');
     foreach ($columns as $column) {
         $search->withColumn('`' . $requestedLocaleI18nAlias . '`.`' . $column . '`', $aliasPrefix . 'i18n_' . $column);
     }
 }
开发者ID:badelas,项目名称:thelia,代码行数:18,代码来源:ModelCriteriaTools.php

示例9: expandQuery

 /**
  * @param \Propel\Runtime\ActiveQuery\ModelCriteria $expandableQuery
  * @param bool $excludeDirectParent
  * @param bool $excludeRoot
  *
  * @return \Propel\Runtime\ActiveQuery\ModelCriteria
  */
 public function expandQuery(ModelCriteria $expandableQuery, $excludeDirectParent = true, $excludeRoot = true)
 {
     $expandableQuery->addJoin(SpyTouchTableMap::COL_ITEM_ID, SpyProductCategoryTableMap::COL_FK_PRODUCT_ABSTRACT, Criteria::LEFT_JOIN);
     $expandableQuery->addJoin(SpyProductCategoryTableMap::COL_FK_CATEGORY_NODE, SpyCategoryNodeTableMap::COL_ID_CATEGORY_NODE, Criteria::INNER_JOIN);
     $expandableQuery->addJoin(SpyCategoryNodeTableMap::COL_FK_CATEGORY, SpyCategoryAttributeTableMap::COL_FK_CATEGORY, Criteria::INNER_JOIN);
     $expandableQuery = $this->categoryQueryContainer->joinCategoryQueryWithUrls($expandableQuery);
     $expandableQuery = $this->categoryQueryContainer->selectCategoryAttributeColumns($expandableQuery);
     $expandableQuery = $this->categoryQueryContainer->joinCategoryQueryWithChildrenCategories($expandableQuery);
     $expandableQuery = $this->categoryQueryContainer->joinLocalizedRelatedCategoryQueryWithAttributes($expandableQuery, 'categoryChildren', 'child');
     $expandableQuery = $this->categoryQueryContainer->joinRelatedCategoryQueryWithUrls($expandableQuery, 'categoryChildren', 'child');
     $expandableQuery = $this->categoryQueryContainer->joinCategoryQueryWithParentCategories($expandableQuery, $excludeDirectParent, $excludeRoot);
     $expandableQuery = $this->categoryQueryContainer->joinLocalizedRelatedCategoryQueryWithAttributes($expandableQuery, 'categoryParents', 'parent');
     $expandableQuery = $this->categoryQueryContainer->joinRelatedCategoryQueryWithUrls($expandableQuery, 'categoryParents', 'parent');
     $expandableQuery->withColumn('GROUP_CONCAT(DISTINCT spy_category_node.id_category_node)', 'node_id');
     $expandableQuery->withColumn(SpyCategoryNodeTableMap::COL_FK_CATEGORY, 'category_id');
     $expandableQuery->orderBy('depth', Criteria::DESC);
     $expandableQuery->orderBy('descendant_id', Criteria::DESC);
     $expandableQuery->groupBy('abstract_sku');
     return $expandableQuery;
 }
开发者ID:spryker,项目名称:ProductCategory,代码行数:27,代码来源:ProductCategoryPathQueryExpander.php

示例10: from

 public static function from($queryClassAndAlias)
 {
     list($class, $alias) = ModelCriteria::getClassAndAlias($queryClassAndAlias);
     $queryClass = $class . 'Query';
     if (!class_exists($queryClass)) {
         throw new ClassNotFoundException('Cannot find a query class for ' . $class);
     }
     $query = new $queryClass();
     if (null !== $alias) {
         $query->setModelAlias($alias);
     }
     return $query;
 }
开发者ID:kalaspuffar,项目名称:php-orm-benchmark,代码行数:13,代码来源:PropelQuery.php

示例11: testRequirePkReturnsModel

 public function testRequirePkReturnsModel()
 {
     // retrieve the test data
     $c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book');
     $testBook = $c->findOne();
     $book = BookQuery::create()->requirePk($testBook->getId());
     $this->assertInstanceOf(BookTableMap::OM_CLASS, $book);
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:8,代码来源:ModelCriteriaTest.php

示例12: joinTaxRates

 /**
  * @api
  *
  * @param \Propel\Runtime\ActiveQuery\ModelCriteria $expandableQuery
  *
  * @return $this
  */
 public function joinTaxRates(ModelCriteria $expandableQuery)
 {
     $expandableQuery->addJoin(SpyTaxSetTableMap::COL_ID_TAX_SET, SpyTaxSetTaxTableMap::COL_FK_TAX_SET, Criteria::LEFT_JOIN)->addJoin(SpyTaxSetTaxTableMap::COL_FK_TAX_RATE, SpyTaxRateTableMap::COL_ID_TAX_RATE, Criteria::LEFT_JOIN);
     $expandableQuery->withColumn('GROUP_CONCAT(DISTINCT ' . SpyTaxRateTableMap::COL_NAME . ')', 'tax_rate_names')->withColumn('GROUP_CONCAT(DISTINCT ' . SpyTaxRateTableMap::COL_RATE . ')', 'tax_rate_rates');
     return $this;
 }
开发者ID:spryker,项目名称:Tax,代码行数:13,代码来源:TaxQueryContainer.php

示例13: testPruneCompositeKey

 public function testPruneCompositeKey()
 {
     BookstoreDataPopulator::depopulate();
     BookstoreDataPopulator::populate();
     // save all books to make sure related objects are also saved - BookstoreDataPopulator keeps some unsaved
     $c = new ModelCriteria('bookstore', '\\Propel\\Tests\\Bookstore\\Book');
     $books = $c->find();
     foreach ($books as $book) {
         $book->save();
     }
     BookTableMap::clearInstancePool();
     $nbBookListRel = BookListRelQuery::create()->prune()->count();
     $this->assertEquals(2, $nbBookListRel, 'prune() does nothing when passed a null object');
     $testBookListRel = BookListRelQuery::create()->findOne();
     $nbBookListRel = BookListRelQuery::create()->prune($testBookListRel)->count();
     $this->assertEquals(1, $nbBookListRel, 'prune() removes an object from the result');
 }
开发者ID:kalaspuffar,项目名称:php-orm-benchmark,代码行数:17,代码来源:QueryBuilderTest.php

示例14: queryDistinctLocalesFromQuery

 /**
  * @api
  *
  * @param \Propel\Runtime\ActiveQuery\ModelCriteria $query
  *
  * @return \Propel\Runtime\ActiveQuery\ModelCriteria
  */
 public function queryDistinctLocalesFromQuery(ModelCriteria $query)
 {
     $query->distinct('locale_name')->withColumn(SpyLocaleTableMap::COL_ID_LOCALE, 'value')->withColumn(SpyLocaleTableMap::COL_LOCALE_NAME, 'label');
     return $query;
 }
开发者ID:spryker,项目名称:Glossary,代码行数:12,代码来源:GlossaryQueryContainer.php

示例15: searchWithPagination

 /**
  * @param ModelCriteria    $search
  * @param PropelModelPager|null $pagination
  *
  * @return array|PropelModelPager
  */
 protected function searchWithPagination(ModelCriteria $search, &$pagination)
 {
     $page = intval($this->getArgValue('page'));
     $limit = intval($this->getArgValue('limit'));
     $pagination = $search->paginate($page, $limit);
     if ($page > $pagination->getLastPage()) {
         return [];
     } else {
         return $pagination;
     }
 }
开发者ID:vigourouxjulien,项目名称:thelia,代码行数:17,代码来源:BaseLoop.php


注:本文中的Propel\Runtime\ActiveQuery\ModelCriteria类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。