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


PHP Collection::combine方法代码示例

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


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

示例1: groupTranslations

 /**
  * 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;
     });
 }
开发者ID:wepbunny,项目名称:cake2,代码行数:28,代码来源:TranslateBehavior.php

示例2: testTranslationsHasManyWithOverride

 /**
  * Tests that it is possible to both override fields with a translation and
  * also find separately other translations
  *
  * @return void
  */
 public function testTranslationsHasManyWithOverride()
 {
     $table = TableRegistry::get('Articles');
     $table->addBehavior('Translate', ['fields' => ['title', 'body']]);
     $table->hasMany('Comments');
     $comments = $table->hasMany('Comments')->target();
     $comments->addBehavior('Translate', ['fields' => ['comment']]);
     $table->locale('cze');
     $comments->locale('eng');
     $results = $table->find('translations')->contain(['Comments' => function ($q) {
         return $q->find('translations')->select(['id', 'comment', 'article_id']);
     }]);
     $comments = $results->first()->comments;
     $expected = [1 => 'Comment #1', 2 => 'Comment #2', 3 => 'Comment #3', 4 => 'Comment #4'];
     $list = new Collection($comments);
     $this->assertEquals($expected, $list->combine('id', 'comment')->toArray());
     $expected = [['eng' => ['comment' => 'Comment #1', 'locale' => 'eng']], ['eng' => ['comment' => 'Comment #2', 'locale' => 'eng']], ['eng' => ['comment' => 'Comment #3', 'locale' => 'eng']], ['eng' => ['comment' => 'Comment #4', 'locale' => 'eng'], 'spa' => ['comment' => 'Comentario #4', 'locale' => 'spa']]];
     $translations = $this->_extractTranslations($comments);
     $this->assertEquals($expected, $translations->toArray());
     $this->assertEquals('Titulek #1', $results->first()->title);
     $this->assertEquals('Obsah #1', $results->first()->body);
 }
开发者ID:alexunique0519,项目名称:Blog_Cakephp_association,代码行数:28,代码来源:TranslateBehaviorTest.php

示例3: getDataNorth

 public function getDataNorth()
 {
     // Init table
     $resultsTable = TableRegistry::get('Results');
     $query = $resultsTable->find('all', ['fields' => ['date_result'], 'conditions' => ['area' => Configure::read('Area.north.code')], 'order' => ['date_result' => 'DESC']]);
     $newestDate = $query->first()->date_result->modify('+1 days')->i18nFormat('YYYY-MM-dd');
     $endDate = date('H', strtotime('+7 hour')) > 18 ? 0 : 1;
     //Init variable
     $http = new Client();
     $begin = new \DateTime($newestDate);
     $end = new \DateTime();
     $end->modify("-{$endDate} day");
     $interval = new \DateInterval('P1D');
     $daterange = new \DatePeriod($begin, $interval, $end);
     // Get list city
     $collection = new Collection(Configure::read('City'));
     $arrCity = $collection->combine('w', 'code')->toArray();
     foreach ($daterange as $date) {
         $dateFormat = $date->format("d-m-Y");
         $wday = $date->format("w");
         $dateResult = $date->format("Ymd");
         $url = "http://www.xoso.net/getkqxs/mien-bac/{$dateFormat}.js";
         $response = $http->get($url);
         preg_match_all("|'(.*)'|", $response->body(), $match);
         $dom = new \DOMDocument();
         $dom->loadHTML($match[1][2]);
         foreach ($dom->getElementsByTagName('td') as $node) {
             $class = $node->getAttribute('class');
             $value = preg_replace('/\\s+/', '', $node->nodeValue);
             if (preg_match('/^giai(\\d|db)+$/', $class) && $value !== '') {
                 $arrContent = explode('-', $value);
                 foreach ($arrContent as $content) {
                     $result = $resultsTable->newEntity();
                     $result->date_result = $dateResult;
                     $result->level = Configure::read("Result_Level.{$class}");
                     $result->content = $content;
                     $result->area = 1;
                     $result->city = $arrCity[$wday];
                     $result->created_date = $end->format("YmdHis");
                     $result->modified_date = $end->format("YmdHis");
                     $resultsTable->save($result);
                 }
             }
         }
     }
 }
开发者ID:philliptan,项目名称:lode,代码行数:46,代码来源:PagesController.php

示例4: groupVersions

 /**
  * 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;
     });
 }
开发者ID:josegonzalez,项目名称:cakephp-version,代码行数:27,代码来源:VersionBehavior.php

示例5: groupVersions

 /**
  * 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;
     });
 }
开发者ID:chris48s,项目名称:cakephp-version,代码行数:24,代码来源:VersionBehavior.php


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