當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。