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


PHP Collection\Collection类代码示例

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


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

示例1: getBlocksForColumn

 /**
  * Return all blocks to render in the given row column
  *
  * @param int $column Numeric column index, starting with 1
  * @return array
  */
 public function getBlocksForColumn($column)
 {
     $blocks = new \Cake\Collection\Collection($this->cms_blocks);
     return $blocks->filter(function ($block) use($column) {
         return $block->column_index == $column;
     })->toArray();
 }
开发者ID:scherersoftware,项目名称:cake-cms,代码行数:13,代码来源:CmsRow.php

示例2: index

 /**
  * Index method
  *
  * @return \Cake\Network\Response|null
  */
 public function index()
 {
     $releases = $this->Releases->find('all')->all();
     $collection = new Collection($releases);
     $attribute_names = array_unique($collection->extract('attribute_name')->toArray());
     $idps = array_unique($collection->extract('idp')->toArray());
     $releasesByIdp = $collection->groupBy('idp')->toArray();
     foreach ($idps as $idp) {
         foreach ($attribute_names as $attribute) {
             $releasesByIdPbyAttribute = $collection->match(['idp' => $idp, 'attribute_name' => $attribute]);
             $temp_result = $releasesByIdPbyAttribute->countBy(function ($result) {
                 return strtolower($result->validated) == 'fail' ? 'fail' : 'pass';
             });
             $results[$idp][$attribute] = $temp_result->toArray();
         }
     }
     # My attributes
     $persistentid_array = preg_split('/!/', $this->request->env('persistent-id'));
     $persistentid = end($persistentid_array);
     $myAttributesTemp = $this->Releases->find()->andWhere(['idp' => $this->request->env('Shib-Identity-Provider'), 'persistentid' => $persistentid])->all();
     $myAttributesCollection = new Collection($myAttributesTemp);
     $myAttributes = $myAttributesCollection->groupBy('attribute_name')->toArray();
     $this->set(compact('myAttributes'));
     $this->set('_serialize', ['myAttributes']);
     $this->set(compact('results'));
     $this->set('_serialize', ['results']);
     $this->set(compact('idps'));
     $this->set('_serialize', ['idps']);
     $this->set(compact('attribute_names'));
     $this->set('_serialize', ['attribute_names']);
 }
开发者ID:csc-it-center-for-science,项目名称:attribute-test-service,代码行数:36,代码来源:ReleasesController.php

示例3: index

 /**
  * Index method
  *
  * @return void
  */
 public function index()
 {
     //$this->set('categorias', $this->paginate($this->Categorias));
     $find = $this->Categorias->find('all', ['fields' => ['id', 'categoria_id', 'nome']])->toArray();
     $collection = new Collection($find);
     $categorias = $collection->nest('id', 'categoria_id')->toArray();
     $this->set('categorias', $categorias);
     $this->set('_serialize', ['categorias']);
 }
开发者ID:QuielSimoes,项目名称:meugarangau,代码行数:14,代码来源:CategoriasController.php

示例4: getNextRowPosition

 /**
  * Returns the next highest position for adding a new row
  *
  * @return int
  */
 public function getNextRowPosition()
 {
     $rows = new Collection($this->cms_rows);
     $highestRow = $rows->max('position');
     $maxPosition = 0;
     if ($highestRow) {
         $maxPosition = $highestRow->position;
     }
     return $maxPosition + 1;
 }
开发者ID:scherersoftware,项目名称:cake-cms,代码行数:15,代码来源:CmsPage.php

示例5: getPhotosSorted

 public function getPhotosSorted()
 {
     if (isset($this->photos) and !empty($this->photos)) {
         $photosCollection = new Collection($this->photos);
         return $photosCollection->sortBy(function ($photo) {
             return $photo->sort_order;
         }, SORT_ASC)->toArray();
     }
     return [];
 }
开发者ID:mswagencia,项目名称:photo-gallery,代码行数:10,代码来源:Gallery.php

示例6: _getLastFiveComments

 public function _getLastFiveComments()
 {
     $alias = Inflector::classify($this->source());
     $comment = TableRegistry::get('Social.Comments');
     $comments = $comment->find()->where(['Comments.object_id' => $this->id, 'Comments.object' => $alias])->limit(__MAX_COMMENTS_LISTED)->order('Comments.created DESC')->contain(['Authors' => ['fields' => ['id', 'first_name', 'last_name', 'avatar']]]);
     // Reorder the Comments by creation order
     // (even though we got them by descending order)
     $collection = new Collection($comments);
     $comments = $collection->sortBy('Comment.created');
     return $comments->toArray();
 }
开发者ID:eripoll,项目名称:webiplan,代码行数:11,代码来源:CommentableTrait.php

示例7: _getSelectOptions

 /**
  * Method that retrieves select input options by list name.
  *
  * @param string $listName list name
  * @param string $spacer The string to use for prefixing the values according to
  * their depth in the tree
  * @param bool $flatten flat list flag
  * @return array list options
  */
 protected function _getSelectOptions($listName, $spacer = ' - ', $flatten = true)
 {
     $result = $this->__getListFieldOptions($listName);
     $result = $this->__filterOptions($result);
     if (!$flatten) {
         return $result;
     }
     // flatten list options
     $collection = new Collection($result);
     $result = $collection->listNested()->printer('name', 'id', $spacer)->toArray();
     return $result;
 }
开发者ID:QoboLtd,项目名称:cakephp-csv-migrations,代码行数:21,代码来源:ListTrait.php

示例8: _getTagString

 protected function _getTagString()
 {
     if (isset($this->_properties['tag_string'])) {
         return $this->_properties['tag_string'];
     }
     if (empty($this->tags)) {
         return '';
     }
     $tags = new Collection($this->tags);
     $str = $tags->reduce(function ($string, $tag) {
         return $string . $tag->label . ', ';
     }, '');
     return trim($str, ', ');
 }
开发者ID:robisacommonusername,项目名称:rran-site,代码行数:14,代码来源:Uploadedfile.php

示例9: filterPrimaryKey

 /**
  * This method is called in case a primary key was defined using the addPrimaryKey() method.
  * It currently does something only if using SQLite.
  * If a column is an auto-increment key in SQLite, it has to be a primary key and it has to defined
  * when defining the column. Phinx takes care of that so we have to make sure columns defined as autoincrement were
  * not added with the addPrimaryKey method, otherwise, SQL queries will be wrong.
  *
  * @return void
  */
 protected function filterPrimaryKey()
 {
     if ($this->getAdapter()->getAdapterType() !== 'sqlite' || empty($this->options['primary_key'])) {
         return;
     }
     $primaryKey = $this->options['primary_key'];
     if (!is_array($primaryKey)) {
         $primaryKey = [$primaryKey];
     }
     $primaryKey = array_flip($primaryKey);
     $columnsCollection = new Collection($this->columns);
     $primaryKeyColumns = $columnsCollection->filter(function ($columnDef, $key) use($primaryKey) {
         return isset($primaryKey[$columnDef->getName()]);
     })->toArray();
     if (empty($primaryKeyColumns)) {
         return;
     }
     foreach ($primaryKeyColumns as $primaryKeyColumn) {
         if ($primaryKeyColumn->isIdentity()) {
             unset($primaryKey[$primaryKeyColumn->getName()]);
         }
     }
     $primaryKey = array_flip($primaryKey);
     if (!empty($primaryKey)) {
         $this->options['primary_key'] = $primaryKey;
     } else {
         unset($this->options['primary_key']);
     }
 }
开发者ID:JoHein,项目名称:LeBonCoup,代码行数:38,代码来源:Table.php

示例10: get_for_parent

 public function get_for_parent($parent, $page)
 {
     $comments = $this->Comments->find()->where(['Comments.object_id' => $parent])->limit(__MAX_COMMENTS_LISTED)->page($page)->order('Comments.created DESC')->contain(['Authors' => ['fields' => ['id', 'first_name', 'last_name', 'avatar']]]);
     // Reorder the Comments by creation order
     // (even though we got them by descending order)
     $collection = new Collection($comments);
     $comments = $collection->sortBy('Comment.created');
     $view = new View($this->request, $this->response, null);
     $view->layout = 'ajax';
     // layout to use or false to disable
     $view->set('comments', $comments->toArray());
     $data['html'] = $view->render('Social.Comments/get_for_parent');
     $this->layout = 'ajax';
     $this->set('data', $data);
     $this->render('/Shared/json/data');
 }
开发者ID:eripoll,项目名称:webiplan,代码行数:16,代码来源:CommentsController.php

示例11: addPattern

 /**
  * addPattern
  *
  */
 public function addPattern($field, $pattern)
 {
     $pattern = new Collection((array) $pattern);
     $validationSet = $this->field($field);
     $validationPatterns = self::$validationPatterns;
     $pattern->each(function ($key) use($field, $validationSet, $validationPatterns) {
         if (empty($validationPatterns[$key])) {
             if (method_exists($this, $key)) {
                 $this->{$key}($field);
                 return;
             }
             throw new NoValidationPatternException('Not found pattern `' . $key . '`');
         }
         $rules = new Collection($validationPatterns[$key]);
         $rules->each(function ($rule, $name) use($validationSet) {
             $validationSet->add($name, $rule);
         });
     });
     return $this;
 }
开发者ID:k1low,项目名称:patternable-validator,代码行数:24,代码来源:Validator.php

示例12: getLibrary

 public function getLibrary()
 {
     $this->viewBuilder()->layout("ajax");
     $this->autoRender = false;
     $this->loadModel('Playlists');
     $this->loadModel('Tracks');
     $userId = $this->request->session()->read('user.id');
     $library = $this->Playlists->find('all')->where(['user_id' => $userId])->contain('Tracks');
     if ($library->count() == 0) {
         echo json_encode(['success' => false]);
         return;
     }
     $library = $library->toArray();
     // remove tracks from playlists
     $libraryCollection = new Collection($library);
     $playlists = $libraryCollection->extract(function ($list) {
         unset($list->tracks);
         return $list;
     });
     // if tokens is expired get new downloadUrls
     // GAUTH: is token expired
     $gotUpdatedDownloadUrls = false;
     $client = new \Google_Client();
     $client->setAuthConfigFile('../client_secret.json');
     $client->addScope(\Google_Service_Drive::DRIVE);
     if ($this->request->session()->check('user.drive_token')) {
         $client->setAccessToken($this->request->session()->read('user.drive_token'));
         if ($client->isAccessTokenExpired()) {
             $gotUpdatedDownloadUrls = true;
         }
     } else {
         $gotUpdatedDownloadUrls = true;
     }
     $driveFiles = $this->getMusicFromDrive();
     $driveFileUrlById = (new Collection($driveFiles))->combine('id', function ($entity) {
         return str_replace("?e=download&gd=true", "", $entity['downloadUrl']);
     })->toArray();
     // create tracks by playlist id, also update new download_url if gotten it
     $tracksByPlaylistId = [];
     $tracksById = [];
     foreach ($library as $list) {
         $tracksByPlaylistId[$list->id] = [];
         foreach ($list->tracks as $track) {
             if ($gotUpdatedDownloadUrls) {
                 $this->Tracks->patchEntity($track, ['download_url' => $driveFileUrlById[$track->drive_id]]);
                 $this->Tracks->save($track);
             }
             $tracksByPlaylistId[$track->playlist_id][] = $track;
             $tracksById[$track->id] = $track;
         }
     }
     echo json_encode(['playlists' => $playlists, 'tracksByPlaylistId' => $tracksByPlaylistId, 'tracksById' => $tracksById]);
 }
开发者ID:apomarinov,项目名称:cake,代码行数:53,代码来源:UsersController.php

示例13: isPermitted

 public function isPermitted($permissions, $operator = OPERATOR_AND)
 {
     $session = $this->request->session()->read('Auth.User');
     if ($session['idr_admin']) {
         return true;
     }
     $acoes = new Collection($session['acoes']);
     if (is_array($permissions)) {
         if ($operator == OPERATOR_AND) {
             foreach ($permissions as $k => $p) {
                 $permitido = $acoes->filter(function ($acao, $key) use($p) {
                     return mb_strtoupper($acao['tag']) == mb_strtoupper($p);
                 });
                 if (count($permitido->toArray()) == 0) {
                     break;
                 }
             }
         } else {
             foreach ($permissions as $k => $p) {
                 $permitido = $acoes->filter(function ($acao, $key) use($p) {
                     return mb_strtoupper($acao['tag']) == mb_strtoupper($p);
                 });
                 if (count($permitido->toArray()) > 0) {
                     break;
                 }
             }
         }
     } else {
         $permitido = $acoes->filter(function ($acao, $key) use($permissions) {
             return mb_strtoupper($acao['tag']) == mb_strtoupper($permissions);
         });
     }
     if (count($permitido->toArray()) > 0) {
         return true;
     } else {
         return false;
     }
 }
开发者ID:ranzate,项目名称:security,代码行数:38,代码来源:SecurityHelper.php

示例14: anyPermitted

 private function anyPermitted($permissions, $operator = self::OPERATOR_AND)
 {
     $session = $this->request->session()->read('Auth.User');
     if ($session['idr_admin']) {
         return true;
     }
     $acoes = new Collection($session['acoes']);
     if (is_array($permissions)) {
         if ($operator == self::OPERATOR_AND) {
             foreach ($permissions as $k => $p) {
                 $permitido = $acoes->filter(function ($acao, $key) use($p) {
                     return mb_strtoupper($acao['tag']) == mb_strtoupper($p);
                 });
                 if (count($permitido->toArray()) == 0) {
                     break;
                 }
             }
         } else {
             foreach ($permissions as $k => $p) {
                 $permitido = $acoes->filter(function ($acao, $key) use($p) {
                     return mb_strtoupper($acao['tag']) == mb_strtoupper($p);
                 });
                 if (count($permitido->toArray()) > 0) {
                     break;
                 }
             }
         }
     } else {
         $permitido = $acoes->filter(function ($acao, $key) use($permissions) {
             return mb_strtoupper($acao['tag']) == mb_strtoupper($permissions);
         });
     }
     if (count($permitido->toArray()) == 0) {
         throw new UnauthorizedException("Usuário da sessão não possui permissão para acessar a ação escolhida");
     }
 }
开发者ID:ranzate,项目名称:security,代码行数:36,代码来源:SecurityComponent.php

示例15: __construct

 /**
  * Wraps this iterator around the passed items so when iterated they are returned
  * in order.
  *
  * The callback will receive as first argument each of the elements in $items,
  * the value returned in the callback will be used as the value for sorting such
  * element. Please not that the callback function could be called more than once
  * per element.
  *
  * @param array|\Traversable $items The values to sort
  * @param callable|string $callback A function used to return the actual value to
  * be compared. It can also be a string representing the path to use to fetch a
  * column or property in each element
  * @param int $dir either SORT_DESC or SORT_ASC
  * @param int $type the type of comparison to perform, either SORT_STRING
  * SORT_NUMERIC or SORT_NATURAL
  */
 public function __construct($items, $callback, $dir = SORT_DESC, $type = SORT_NUMERIC)
 {
     if (is_array($items)) {
         $items = new Collection($items);
     }
     $items = iterator_to_array($items, false);
     $callback = $this->_propertyExtractor($callback);
     $results = [];
     foreach ($items as $key => $value) {
         $results[$key] = $callback($value);
     }
     $dir === SORT_DESC ? arsort($results, $type) : asort($results, $type);
     foreach (array_keys($results) as $key) {
         $results[$key] = $items[$key];
     }
     parent::__construct($results);
 }
开发者ID:ansidev,项目名称:cakephp_blog,代码行数:34,代码来源:SortIterator.php


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