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


PHP Query::contain方法代码示例

本文整理汇总了PHP中Cake\ORM\Query::contain方法的典型用法代码示例。如果您正苦于以下问题:PHP Query::contain方法的具体用法?PHP Query::contain怎么用?PHP Query::contain使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cake\ORM\Query的用法示例。


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

示例1: findMetCustomers

 public function findMetCustomers(Query $query, array $options)
 {
     $query->contain(['Users.Customers'])->matching('Users', function ($q) use($options) {
         return $q->where(['Users.id' => $options['Users.id']]);
     });
     return $query;
 }
开发者ID:bolshas,项目名称:voffice,代码行数:7,代码来源:MeetingsTable.php

示例2: findWithContain

 public function findWithContain(Query $query, array $options = [])
 {
     if (!empty($this->_contain)) {
         $query->contain($this->_contain);
     }
     return $query;
 }
开发者ID:pwerken,项目名称:va-void,代码行数:7,代码来源:AppTable.php

示例3: beforePaginate

 /**
  * {@inheritDoc}
  */
 public function beforePaginate(Event $event, Query $query)
 {
     $query->contain($this->_getAssociations($event));
     $this->_filterByConditions($query, $event);
     $this->_selectActionFields($query, $event);
     $this->_handleDtSorting($query, $event);
 }
开发者ID:QoboLtd,项目名称:cakephp-csv-migrations,代码行数:10,代码来源:IndexViewListener.php

示例4: onBeforeFind

 /**
  * Before find any users, set contain to get user roles too.
  *
  * @param Event $event
  * @param Query $query
  * @param \ArrayObject $options
  * @param $primary
  */
 public function onBeforeFind(Event $event, $query, \ArrayObject $options, $primary)
 {
     $table = $event->subject();
     if ($table->alias() == 'Users') {
         $query->contain(['Roles']);
     }
 }
开发者ID:mohammadsaleh,项目名称:spider,代码行数:15,代码来源:AclManagerEventHandler.php

示例5: beforeFind

 public function beforeFind(Event $event, Query $query, ArrayObject $options, $primary)
 {
     if (!array_key_exists('getRelated', $options) || !$options['getRelated']) {
         //Jen pokud se mají related stahovat
         return true;
     }
     $attachedTables = $this->_InRelatedIndexBehavior->getTablesWithBehaviorNames();
     /** @var \Cake\ORM\Table $attachedTable */
     foreach ($attachedTables as $tableName) {
         $modelName = Inflector::camelize($tableName);
         $query->contain(['Related' . $modelName => []]);
     }
     $query->formatResults(function ($results) {
         return $results->map(function ($row) {
             $temp = $row->toArray();
             $related = [];
             foreach ($temp as $key => $item) {
                 if (preg_match('/related-.*/', $key)) {
                     foreach ($row->{$key} as $id => $similar) {
                         $table_name = explode('-', $key);
                         $row->{$key}[$id]->table_name = end($table_name);
                     }
                     $related = array_merge($related, $row->{$key});
                     unset($row->{$key});
                 }
             }
             $row->related = $related;
             return $row;
         });
     });
     return true;
 }
开发者ID:aiphee,项目名称:cakephp-related-content,代码行数:32,代码来源:HasRelatedBehavior.php

示例6: findParticipationsForStudent

 public function findParticipationsForStudent(Query $query, array $options)
 {
     return $query->contain(['Tests' => function ($q) {
         return $q->select(['Tests.datepreuve']);
     }, 'Tests.Subjects' => function ($q) {
         return $q->select(['Subjects.libelle', 'Subjects.coeff']);
     }])->where($options)->hydrate(false);
 }
开发者ID:AFPA-Dijon,项目名称:afpa,代码行数:8,代码来源:StudentsTestsTable.php

示例7: findTagged

 public function findTagged(Query $query, array $options)
 {
     $query->contain(['Users', 'Users.AccountParameters', 'Hashtags']);
     $query->matching('Hashtags', function ($q) use($options) {
         return $q->where(['Hashtags.name' => $options['tag_name']]);
     });
     $query->order(['Tweets.created' => 'DESC']);
     return $query;
 }
开发者ID:TituxMetal,项目名称:Twitthome-CakePHP3,代码行数:9,代码来源:TweetsTable.php

示例8: findToAutoRenew

 /**
  * Finds all memberships that will expire in the next 24 hours, are marked
  * for automatic renewal, and have not been renewed or canceled.
  *
  * @param Query $query
  * @param array $options
  * @return Query
  */
 public function findToAutoRenew(Query $query, array $options)
 {
     return $query->contain(['Users' => function ($q) {
         return $q->select(['id', 'name', 'email', 'stripe_customer_id']);
     }, 'MembershipLevels' => function ($q) {
         return $q->select(['id', 'name', 'cost']);
     }])->where(function ($exp, $q) {
         return $exp->isNull('canceled');
     })->where(function ($exp, $q) {
         return $exp->lte('expires', date('Y-m-d H:i:s', strtotime('+1 day')));
     })->where(['auto_renew' => 1])->order(['expires' => 'ASC']);
 }
开发者ID:PhantomWatson,项目名称:macc,代码行数:20,代码来源:MembershipsTable.php

示例9: getProperty

 /**
  * Get CakePHP property
  *
  * @param string $dataName Column data name
  *
  * @throws Exception
  * @return array|string
  */
 protected function getProperty($dataName)
 {
     $dataName = explode('.', trim($dataName));
     if (count($dataName) != 2) {
         throw new Exception('You are set invalid date.');
     }
     $tableAlias = $dataName[0];
     $colName = $dataName[1];
     if ($this->query->repository()->alias() == $tableAlias) {
         return $colName;
     } elseif (array_key_exists($tableAlias, $this->query->contain())) {
         return ['propertyPath' => $this->query->eagerLoader()->normalized($this->query->repository())[$tableAlias]['propertyPath'], 'field' => $colName];
     }
 }
开发者ID:atkrad,项目名称:data-tables,代码行数:22,代码来源:CakePHP.php

示例10: findReadStatus

 /**
  * Dynamic finder that loads all users for a thread without me
  *
  * @param \Cake\ORM\Query $query the original query to append to
  * @param array $users the list of users to be ignored
  * @return \Cake\ORM\Query The amended query
  */
 public function findReadStatus(Query $query, array $users)
 {
     $query->contain(['Messages' => function ($q) use($users) {
         return $q->find('readStatus', $users);
     }]);
     return $query->map(function ($thread) {
         $opened = false;
         foreach ($thread['messages'] as $message) {
             if ($message['message_read_statuses'][0]['opened']) {
                 $opened = true;
                 break;
             }
         }
         $thread['opened'] = $opened;
         return $thread;
     });
 }
开发者ID:gintonicweb,项目名称:messages,代码行数:24,代码来源:ThreadsTable.php

示例11: beforeFind

 /**
  * Attaches comments to each entity on find operation.
  *
  * @param \Cake\Event\Event $event The event that was triggered
  * @param \Cake\ORM\Query $query The query object
  * @param array $options Additional options as an array
  * @param bool $primary Whether is find is a primary query or not
  * @return void
  */
 public function beforeFind(Event $event, $query, $options, $primary)
 {
     if ($this->_enabled && $query->count() > 0) {
         $pk = $this->_table->primaryKey();
         $tableAlias = Inflector::underscore($this->_table->alias());
         $query->contain(['Comments' => function ($query) {
             return $query->find('threaded')->contain(['Users'])->order($this->config('order'));
         }]);
         if ($this->config('count') || isset($options['comments_count']) && $options['comments_count'] === true) {
             $query->formatResults(function ($results) use($pk, $tableAlias) {
                 return $results->map(function ($entity) use($pk, $tableAlias) {
                     $entityId = $entity->{$pk};
                     $count = TableRegistry::get('Comment.Comments')->find()->where(['entity_id' => $entityId, 'table_alias' => $tableAlias])->count();
                     $entity->set('comments_count', $count);
                     return $entity;
                 });
             });
         }
     }
 }
开发者ID:quickapps-plugins,项目名称:comment,代码行数:29,代码来源:CommentableBehavior.php

示例12: beforeFind

 /**
  * [beforeFind description]
  *
  * @param  Event $event [description]
  * @param  Query $query [description]
  * @param array  $options
  *
  * @return $this|array|Query [type]          [description]
  *
  * ### Options
  * `images` When setting images to false nothing will be added to the query and no image fields will be returned in the resultset and will probably
  * speed up overall performance
  */
 public function beforeFind(Event $event, Query $query, $options = [])
 {
     if (isset($options['images']) && !$options['images']) {
         return $query;
     }
     $fields = $this->config('fields');
     $contain = $conditions = [];
     foreach ($fields as $field => $type) {
         $field = $this->_fieldName($field);
         $contain[$field] = $conditions;
     }
     /**
      * @param $row
      * @param $key
      * @param $mapReduce MapReduce
      */
     $mapper = function ($row, $key, $mapReduce) use($fields) {
         foreach ($fields as $field => $type) {
             $name = $this->_fieldName($field, false);
             $image = isset($row[$name]) ? $row[$name] : null;
             // make sure we set the correct registry alias for the entity so
             // we can access the entity's repository from the ImageHelper
             if (!empty($image)) {
                 if (is_array($image)) {
                     foreach ($image as &$imageEntity) {
                         $this->_setEntitySource($imageEntity);
                     }
                 } else {
                     $this->_setEntitySource($image);
                 }
             }
             if ($image === null) {
                 unset($row[$name]);
                 continue;
             }
             $row[$field] = $image;
             unset($row[$name]);
         }
         if ($row instanceof Entity) {
             $row->clean();
         }
         $mapReduce->emitIntermediate($row, $key);
     };
     /**
      * @param $items
      * @param $key
      * @param $mapReduce MapReduce
      */
     $reducer = function ($items, $key, $mapReduce) {
         if (isset($items[0])) {
             $mapReduce->emit($items[0], $key);
         }
     };
     $request = Router::getRequest();
     if (!isset($request->params['prefix']) || $request->params['prefix'] !== 'admin') {
         //TODO zuniverzálnit
         foreach ($contain as $key => &$item) {
             $item['conditions'] = [$key . '.active' => true];
         }
     }
     $q = $query->contain($contain)->mapReduce($mapper, $reducer);
     return $q;
 }
开发者ID:aiphee,项目名称:image,代码行数:76,代码来源:ImageBehavior.php

示例13: findOfHired

 public function findOfHired(Query $query, $options = [])
 {
     return $query->contain(['Employees'])->where(['Salaries.to_date IS' => null]);
 }
开发者ID:surjit,项目名称:cakephp3-advanced-examples,代码行数:4,代码来源:SalariesTable.php

示例14: findWithOfficialLanguage

 public function findWithOfficialLanguage(Query $query)
 {
     return $query->contain('OfficialLanguages');
 }
开发者ID:harikt,项目名称:cakephp3-examples,代码行数:4,代码来源:CountriesTable.php

示例15: findLanguage

 /**
  * Custom finder method
  * users translating to/from given language
  *
  * @param Query $query
  * @param array $options ['language_id'] == language_id, ['target'] == true (target language) false (source language)
  * @return Query
  */
 public function findLanguage(Query $query, array $options)
 {
     $query->contain(['LanguagesDirection'])->matching('LanguagesDirection', function (\Cake\ORM\Query $query) use($options) {
         return $query->where(['LanguagesDirection.language_id' => $options['language_id'], 'LanguagesDirection.target' => $options['target']]);
     });
     return $query;
 }
开发者ID:edasubert,项目名称:tweeslate,代码行数:15,代码来源:UsersTable.php


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