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


PHP Collection::sortBy方法代码示例

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


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

示例1: getCategories

 /**
  * @return Collection
  */
 public function getCategories() : Collection
 {
     $set = $this->categories->sortBy(function (CategoryModel $category) {
         return $category->spent;
     });
     return $set;
 }
开发者ID:roberthorlings,项目名称:firefly-iii,代码行数:10,代码来源:Category.php

示例2: getExpenses

 /**
  * @return Collection
  */
 public function getExpenses()
 {
     $set = $this->expenses->sortBy(function (stdClass $object) {
         return $object->amount;
     });
     return $set;
 }
开发者ID:leander091,项目名称:firefly-iii,代码行数:10,代码来源:Expense.php

示例3: ordering

 /**
  * Perform ordering
  *
  * @return mixed
  */
 public function ordering()
 {
     foreach ($this->request->getOrder() as $key => $reverse) {
         $this->collection = $this->collection->sortBy(function ($row) use($key) {
             return $row[$key];
         }, SORT_NATURAL, $reverse);
     }
 }
开发者ID:mikelmi,项目名称:mks-smart-table,代码行数:13,代码来源:CollectionEngine.php

示例4: getBills

 /**
  * @return Collection
  */
 public function getBills()
 {
     $set = $this->bills->sortBy(function (BillLine $bill) {
         $active = intval($bill->getBill()->active) == 0 ? 1 : 0;
         $name = $bill->getBill()->name;
         return $active . $name;
     });
     return $set;
 }
开发者ID:webenhanced,项目名称:firefly-iii,代码行数:12,代码来源:Bill.php

示例5: orderBy

 /**
  * Adds a OrderBy to the query
  *
  * @param  string
  * @param  string
  * @return $this
  */
 public function orderBy($column, $direction = 'asc')
 {
     if ($column != null) {
         if ($direction === 'asc') {
             $this->collection = $this->collection->sortBy($column);
         } elseif ($direction === 'desc') {
             $this->collection = $this->collection->sortByDesc($column);
         }
     }
     return $this;
 }
开发者ID:lykegenes,项目名称:laravel-api-response,代码行数:18,代码来源:EloquentCollectionStrategy.php

示例6: ordering

 /**
  * @inheritdoc
  */
 public function ordering()
 {
     foreach ($this->request->orderableColumns() as $orderable) {
         $column = $this->getColumnName($orderable['column']);
         $this->collection = $this->collection->sortBy(function ($row) use($column) {
             return $row[$column];
         });
         if ($orderable['direction'] == 'desc') {
             $this->collection = $this->collection->reverse();
         }
     }
 }
开发者ID:rayhan0421,项目名称:laravel-datatables,代码行数:15,代码来源:CollectionEngine.php

示例7: doInternalOrder

 private function doInternalOrder()
 {
     if (is_null($this->orderColumn)) {
         return;
     }
     $column = $this->orderColumn[0];
     $stripOrder = $this->options['stripOrder'];
     $self = $this;
     $this->workingCollection = $this->workingCollection->sortBy(function ($row) use($column, $stripOrder, $self) {
         if ($self->getAliasMapping()) {
             $column = $self->getNameByIndex($column);
         }
         if ($stripOrder) {
             if (is_callable($stripOrder)) {
                 return $stripOrder($row, $column);
             } else {
                 return strip_tags($row[$column]);
             }
         } else {
             return $row[$column];
         }
     }, SORT_NATURAL);
     if ($this->orderDirection == BaseEngine::ORDER_DESC) {
         $this->workingCollection = $this->workingCollection->reverse();
     }
 }
开发者ID:MehmetNuri,项目名称:faveo-helpdesk,代码行数:26,代码来源:CollectionEngine.php

示例8: sortWidgets

 /**
  * @return $this
  */
 protected function sortWidgets()
 {
     $this->registeredWidgets = $this->registeredWidgets->sortBy(function (WidgetCollectionItem $widget) {
         return $widget->getPosition();
     });
     return $this;
 }
开发者ID:KodiComponents,项目名称:module-widgets,代码行数:10,代码来源:WidgetCollection.php

示例9: getExtensions

 /**
  * @return Collection
  */
 public function getExtensions()
 {
     $extensionsDir = $this->getExtensionsDir();
     $dirs = array_diff(scandir($extensionsDir), ['.', '..']);
     $extensions = new Collection();
     $installed = json_decode(file_get_contents(public_path('vendor/composer/installed.json')), true);
     foreach ($dirs as $dir) {
         if (file_exists($manifest = $extensionsDir . '/' . $dir . '/composer.json')) {
             $extension = new Extension($extensionsDir . '/' . $dir, json_decode(file_get_contents($manifest), true));
             if (empty($extension->name)) {
                 continue;
             }
             foreach ($installed as $package) {
                 if ($package['name'] === $extension->name) {
                     $extension->setInstalled(true);
                     $extension->setVersion($package['version']);
                     $extension->setEnabled($this->isEnabled($dir));
                 }
             }
             $extensions->put($dir, $extension);
         }
     }
     return $extensions->sortBy(function ($extension, $name) {
         return $extension->composerJsonAttribute('extra.flarum-extension.title');
     });
 }
开发者ID:RobR8,项目名称:core,代码行数:29,代码来源:ExtensionManager.php

示例10: sortModules

 /**
  * Sorts the modules in an order that will suite the natural defaults
  * for their menu presence.
  *
  * @return $this
  */
 protected function sortModules()
 {
     $this->modules = $this->modules->sortBy(function (ModuleInterface $module) {
         return $module->getName();
     });
     return $this;
 }
开发者ID:czim,项目名称:laravel-cms-core,代码行数:13,代码来源:ModuleManager.php

示例11: run

 /**
  * @param string $name
  * @param array  $params
  */
 public function run($name, array $params = [])
 {
     $widgets = static::getWidgetsByBlock($name, $params);
     $collection = new Collection($widgets);
     $collection->sortBy(function ($widget) {
         return $widget->getPosition();
     });
     echo view('pages::pages.wysiwyg.block_placeholder', ['widgets' => $collection, 'name' => $name, 'page' => $this->page])->render();
 }
开发者ID:KodiComponents,项目名称:module-pages,代码行数:13,代码来源:BlockWysiwyg.php

示例12: doOrdering

 /**
  * @inheritdoc
  */
 public function doOrdering()
 {
     if (array_key_exists('order', $this->input) && count($this->input['order']) > 0) {
         for ($i = 0, $c = count($this->input['order']); $i < $c; $i++) {
             $order_col = (int) $this->input['order'][$i]['column'];
             $order_dir = $this->input['order'][$i]['dir'];
             if (!$this->isColumnOrderable($this->input['columns'][$order_col])) {
                 continue;
             }
             $column = $this->getOrderColumnName($order_col);
             $this->collection = $this->collection->sortBy(function ($row) use($column) {
                 return $row[$column];
             });
             if ($order_dir == 'desc') {
                 $this->collection = $this->collection->reverse();
             }
         }
     }
 }
开发者ID:Kirylka,项目名称:Scaffold,代码行数:22,代码来源:CollectionEngine.php

示例13: ordering

 /**
  * @inheritdoc
  */
 public function ordering()
 {
     foreach ($this->request->orderableColumns() as $orderable) {
         $column = $this->getColumnName($orderable['column']);
         $this->collection = $this->collection->sortBy(function ($row) use($column) {
             $row = Helper::castToArray($row);
             return Arr::get($row, $column);
         });
         if ($orderable['direction'] == 'desc') {
             $this->collection = $this->collection->reverse();
         }
     }
 }
开发者ID:nmardones,项目名称:laravel-datatables,代码行数:16,代码来源:CollectionEngine.php

示例14: edit

 /**
  * Show the form for editing the specified resource.
  *
  * @param int $id
  *
  * @return Response
  */
 public function edit($id)
 {
     if (!($user = $this->userRepositoryInterface->getByIdWith($id, 'roles'))) {
         Flash::error(trans('dashboard::dashboard.errors.user.found'));
         return redirect()->route('users.index');
     }
     $currentRoles = $user->getRoles()->lists('name');
     if (empty($currentRoles)) {
         $currentRoles = new Collection(['name' => 'Not Available']);
     }
     $currentRoles->sortBy('name');
     $currentRoles = implode(', ', $currentRoles->toArray());
     $roles = $this->roleRepositoryInterface->getAll()->lists('name', 'slug');
     return $this->view('users.edit')->with(['user' => $user, 'currentRoles' => $currentRoles, 'roles' => $roles]);
 }
开发者ID:laraflock,项目名称:dashboard,代码行数:22,代码来源:UsersController.php

示例15: getRegistrationsFull

 /**
  * Display the screen for picking the report
  *
  * @return Response
  */
 public function getRegistrationsFull()
 {
     // get orgs and beneficiaries
     $user = Auth::user();
     if (Auth::user()->access(UserType::SITE_ADMIN_LEVEL)) {
         $orgs = $this->organization->all();
     } else {
         $orgs = new Collection($user->organization->thisAndAllDescendentOrganizations());
     }
     // get weekly start and end dates
     $now = new Carbon();
     $start = Carbon::MONDAY == $now->dayOfWeek ? $now : $now->next(Carbon::MONDAY);
     $end = clone $start;
     $end->addWeeks(2);
     // display page
     return View::make($this->package . '::backend.' . $this->modelName . '.registrations-full', ['page_title' => 'Full Export', 'orgs' => $orgs->sortBy('name'), 'start' => $start, 'end' => $end]);
 }
开发者ID:npmweb,项目名称:service-opportunities,代码行数:22,代码来源:ReportsController.php


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