コード例 #1
0
ファイル: LazyEagerLoader.php プロジェクト: CakeDC/cakephp
 /**
  * Builds a query for loading the passed list of entity objects along with the
  * associations specified in $contain.
  *
  * @param \Cake\Collection\CollectionInterface $objects The original entities
  * @param array $contain The associations to be loaded
  * @param \Cake\ORM\Table $source The table to use for fetching the top level entities
  * @return \Cake\ORM\Query
  */
 protected function _getQuery($objects, $contain, $source)
 {
     $primaryKey = $source->primaryKey();
     $method = is_string($primaryKey) ? 'get' : 'extract';
     $keys = $objects->map(function ($entity) use($primaryKey, $method) {
         return $entity->{$method}($primaryKey);
     });
     $query = $source->find()->select((array) $primaryKey)->where(function ($exp, $q) use($primaryKey, $keys, $source) {
         if (is_array($primaryKey) && count($primaryKey) === 1) {
             $primaryKey = current($primaryKey);
         }
         if (is_string($primaryKey)) {
             return $exp->in($source->aliasField($primaryKey), $keys->toList());
         }
         $types = array_intersect_key($q->defaultTypes(), array_flip($primaryKey));
         $primaryKey = array_map([$source, 'aliasField'], $primaryKey);
         return new TupleComparison($primaryKey, $keys->toList(), $types, 'IN');
     })->contain($contain);
     foreach ($query->eagerLoader()->attachableAssociations($source) as $loadable) {
         $config = $loadable->config();
         $config['includeFields'] = true;
         $loadable->config($config);
     }
     return $query;
 }
コード例 #2
0
ファイル: EavToolbox.php プロジェクト: quickapps-plugins/eav
 /**
  * Given a collection of entities gets the ID of all of them.
  *
  * This method iterates the given set and invokes `getEntityId()` for every
  * entity in the set.
  *
  * @param \Cake\Collection\CollectionInterface $results Set of entities
  * @return array List of entity ids suitable for EAV logic
  */
 public function extractEntityIds(CollectionInterface $results)
 {
     $entityIds = [];
     $results->each(function ($entity) use(&$entityIds) {
         if ($entity instanceof EntityInterface) {
             $entityIds[] = $this->getEntityId($entity);
         }
     });
     return $entityIds;
 }
コード例 #3
0
 /**
  * {@inheritDoc}
  */
 protected function _hydrateEntities(CollectionInterface $entities, array $args)
 {
     return $entities->map(function ($entity) use($args) {
         if ($entity instanceof EntityInterface) {
             $entity = $this->_prepareCachedColumns($entity);
             $entity = $this->_attachEntityFields($entity, $args);
             if ($entity === null) {
                 return self::NULL_ENTITY;
             }
         }
         return $entity;
     })->filter(function ($entity) {
         return $entity !== self::NULL_ENTITY;
     });
 }
コード例 #4
0
ファイル: LanguagesTable.php プロジェクト: wasabi-cms/core
 /**
  * Filter the provided result set by languages that are available at the backend.
  *
  * @param CollectionInterface $results The collection to filter.
  * @return FilterIterator
  */
 public function filterBackend(CollectionInterface $results)
 {
     return $results->filter(function (Language $language) {
         return $language->available_at_backend === true;
     });
 }