當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。