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