コード例 #1
0
 /**
  * Modifies the results from a table find in order to merge full translation records
  * into each entity under the `_translations` key
  *
  * @param \Cake\Datasource\ResultSetInterface $results Results to modify.
  * @return \Cake\Collection\Collection
  */
 public function groupTranslations($results)
 {
     return $results->map(function ($row) {
         $translations = (array) $row['_i18n'];
         $result = [];
         foreach ($translations as $translation) {
             unset($translation['id']);
             $result[$translation['locale']] = $translation;
         }
         $row['_translations'] = $result;
         unset($row['_i18n']);
         if (is_object($row)) {
             $row->clean();
         }
         return $row;
     });
 }
コード例 #2
0
 /**
  * Modifies the results from a table find in order to merge full version records
  * into each entity under the `_versions` key
  *
  * @param \Cake\Datasource\ResultSetInterface $results Results to modify.
  * @return \Cake\Collection\Collection
  */
 public function groupVersions($results)
 {
     $property = $this->versionAssociation()->property();
     return $results->map(function ($row) use($property) {
         $versionField = $this->_config['versionField'];
         $versions = (array) $row->get($property);
         $grouped = new Collection($versions);
         $result = [];
         foreach ($grouped->combine('field', 'content', 'version_id') as $versionId => $keys) {
             $entityClass = $this->_table->entityClass();
             $version = new $entityClass($keys + [$versionField => $versionId], ['markNew' => false, 'useSetters' => false, 'markClean' => true]);
             $result[$versionId] = $version;
         }
         $options = ['setter' => false, 'guard' => false];
         $row->set('_versions', $result, $options);
         unset($row[$property]);
         $row->clean();
         return $row;
     });
 }
コード例 #3
0
ファイル: TranslateBehavior.php プロジェクト: wepbunny/cake2
 /**
  * Modifies the results from a table find in order to merge full translation records
  * into each entity under the `_translations` key
  *
  * @param \Cake\Datasource\ResultSetInterface $results Results to modify.
  * @return \Cake\Collection\Collection
  */
 public function groupTranslations($results)
 {
     return $results->map(function ($row) {
         if (!$row instanceof EntityInterface) {
             return $row;
         }
         $translations = (array) $row->get('_i18n');
         $grouped = new Collection($translations);
         $result = [];
         foreach ($grouped->combine('field', 'content', 'locale') as $locale => $keys) {
             $entityClass = $this->_table->entityClass();
             $translation = new $entityClass($keys + ['locale' => $locale], ['markNew' => false, 'useSetters' => false, 'markClean' => true]);
             $result[$locale] = $translation;
         }
         $options = ['setter' => false, 'guard' => false];
         $row->set('_translations', $result, $options);
         unset($row['_i18n']);
         $row->clean();
         return $row;
     });
 }
コード例 #4
0
 /**
  * Modifies the results from a table find in order to merge full version records
  * into each entity under the `_versions` key
  *
  * @param \Cake\Datasource\ResultSetInterface $results Results to modify.
  * @return \Cake\Collection\Collection
  */
 public function groupVersions($results)
 {
     return $results->map(function ($row) {
         $versions = (array) $row->get('__version');
         $grouped = new Collection($versions);
         $result = [];
         foreach ($grouped->combine('field', 'content', 'version_id') as $versionId => $keys) {
             $version = $this->_table->newEntity($keys + ['version_id' => $versionId], ['markNew' => false, 'useSetters' => false, 'markClean' => true]);
             $result[$versionId] = $version;
         }
         $options = ['setter' => false, 'guard' => false];
         $row->set('_versions', $result, $options);
         unset($row['__version']);
         $row->clean();
         return $row;
     });
 }