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


PHP Collection::sort方法代码示例

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


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

示例1: get

 /**
  * @param string $level
  *
  * @return \Illuminate\Support\Collection
  */
 public function get($level = '*')
 {
     $this->messages->sort(function ($a, $b) {
         return $b['sort'] - $a['sort'];
     });
     return $level !== '*' ? $this->filterNotifications($level) : $this->messages;
 }
开发者ID:znck,项目名称:flash,代码行数:12,代码来源:FlashNotifier.php

示例2: boot

 /**
  * Bootstrap the application services.
  */
 public function boot()
 {
     parent::boot();
     $this->publishMigrations();
     $app = $this->app;
     if ($app->bound('form')) {
         $app->form->macro('selectCountry', function ($name, $selected = null, $options = []) use($app) {
             $countries = Cache::rememberForever('brianfaust.countries.select.name.cca2', function () {
                 $records = Country::get(['name', 'cca2']);
                 $countries = new Collection();
                 $records->map(function ($item) use(&$countries) {
                     $countries[$item['cca2']] = $item['name']['official'];
                 });
                 return $countries->sort();
             });
             return $app->form->select($name, $countries, $selected, $options);
         });
         $app->form->macro('selectCountryWithId', function ($name, $selected = null, $options = []) use($app) {
             $countries = Cache::rememberForever('brianfaust.countries.select.id.cca2', function () {
                 $records = Country::get(['name', 'id']);
                 $countries = new Collection();
                 $records->map(function ($item) use(&$countries) {
                     $countries[$item['id']] = $item['name']['official'];
                 });
                 return $countries->sort();
             });
             return $app->form->select($name, $countries, $selected, $options);
         });
     }
 }
开发者ID:DraperStudio,项目名称:Laravel-Countries,代码行数:33,代码来源:CountriesServiceProvider.php

示例3: index

 /**
  * Show the application dashboard.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     //grab this user's bookmarks and any public bookmarks
     $bookmarks = Bookmark::where('user_id', '=', Auth::user()->id)->orWhere('private', '=', false)->orderBy('created_at', 'DESC')->orderBy('name', 'ASC')->get();
     //grab only the tags that this user has permission to see
     $tags = new Collection();
     foreach ($bookmarks as $bookmark) {
         $tags_as_string = "";
         $these_tags = new Collection();
         foreach ($bookmark->tags()->get() as $tag) {
             $tags->push($tag);
             $these_tags->push($tag->name);
         }
         $tags_as_string = rtrim(implode(', ', $these_tags->sort()->toArray()), ',');
         //$tags_as_string = $tags_as_string,',');
         $bookmark['tags'] = $bookmark['tags']->sortBy('name');
         $bookmark['tags_as_string'] = $tags_as_string;
     }
     $tags = $tags->sortBy('name')->unique('name');
     //for stats
     $untagged_count = $bookmarks->filter(function ($item) {
         return $item->tags()->count() == 0;
     })->count();
     //total count
     $all_bm_count = $bookmarks->count();
     //public only count
     $public_bm_count = Bookmark::where('private', '=', false)->count();
     //private only count
     $private_bm_count = Bookmark::where('user_id', '=', Auth::user()->id)->where('private', '=', true)->count();
     //for any actions, lets grab the messages
     $message = \Session::get('message') ? \Session::get('message') : array();
     //render with all of the necassary data
     return view('dashboard')->with(array('bookmarks' => $bookmarks, 'tags' => $tags, 'stats' => array('untagged_count' => $untagged_count, 'all_bm_count' => $all_bm_count, 'public_bm_count' => $public_bm_count, 'private_bm_count' => $private_bm_count), 'message' => $message));
 }
开发者ID:jjcosgrove,项目名称:laravel-bookmarks,代码行数:39,代码来源:BookmarksController.php

示例4: displayListOfAllCommands

 /**
  * Show a list of all available handlers.
  *
  * @param  Collection|SignatureHandler[] $handlers
  * @return Response
  */
 protected function displayListOfAllCommands(Collection $handlers) : Response
 {
     $attachmentFields = $handlers->sort(function (SignatureHandler $handlerA, SignatureHandler $handlerB) {
         return strcmp($handlerA->getFullCommand(), $handlerB->getFullCommand());
     })->map(function (SignatureHandler $handler) {
         return AttachmentField::create($handler->getFullCommand(), $handler->getDescription());
     })->all();
     return $this->respondToSlack('Available commands:')->withAttachment(Attachment::create()->setColor('good')->setFields($attachmentFields));
 }
开发者ID:spatie,项目名称:laravel-slack-slash-command,代码行数:15,代码来源:Help.php

示例5: collect

 /**
  * @throws \InvalidArgumentException
  *
  * @return Collection|PotentialOffer[]
  */
 private function collect() : Collection
 {
     /*
      * Create buckets for each offer, keeping duplicate offers.
      * Assign each product to the first applicable bucket with spaces left.
      * Filter the buckets to those that are full.
      */
     return $this->components->sort(function (OfferComponent $a, OfferComponent $b) {
         $priceA = $a->product()->price()->asFloat();
         $priceB = $b->product()->price()->asFloat();
         return $priceA <=> $priceB;
     })->reduce(function (Collection $potentials, OfferComponent $component) {
         $potentials->first(function (PotentialOffer $potential) use($component) {
             return $potential->takeComponent($component);
         });
         return $potentials;
     }, $this->potentials())->filter(function (PotentialOffer $offer) {
         return $offer->requirementsAreMet();
     })->sort(function (PotentialOffer $offer) {
         return $offer->linePrice()->negative()->amount();
     });
 }
开发者ID:hughgrigg,项目名称:ching-shop,代码行数:27,代码来源:OfferSet.php

示例6: order

 public static function order(Collection $items)
 {
     return $items->sort(function ($item1, $item2) {
         $item1 = self::getItem($item1);
         $item2 = self::getItem($item2);
         if ($item1['weight'] > $item2['weight']) {
             return 1;
         }
         if ($item1['weight'] < $item2['weight']) {
             return -1;
         }
         return 0;
     });
 }
开发者ID:Houbsi,项目名称:Core,代码行数:14,代码来源:NavigationOrdener.php

示例7: transformArray

 public function transformArray(array $beneficiaries)
 {
     $beneficiariesByCampaign = [];
     $modelCollection = new Collection($beneficiaries);
     $modelCollection->sort(function ($a, $b) {
         return strcasecmp($a->name, $b->name);
     })->each(function (Beneficiary $o) use(&$beneficiariesByCampaign) {
         $result = ['uid' => $o->uid, 'name' => $o->name, 'logo' => $o->logo ? cdn_asset($o->logo, 'logos/beneficiaries/') : null, 'url' => $o->url, 'description' => $o->description, 'show_location' => $this->bool($o->show_location), 'organization_name' => $o->organization->name, 'ctas' => $o->beneficiaryCallsToAction ? $o->beneficiaryCallsToAction->filter(function ($o) {
             return $o->participating;
         })->map(function ($o) {
             return $o->callToAction->permalink;
         })->all() : null];
         $o->campaigns->each(function ($c) use(&$o, &$beneficiariesByCampaign, $result) {
             if (!isset($beneficiariesByCampaign[$c->permalink])) {
                 $beneficiariesByCampaign[$c->permalink] = [];
             }
             $beneficiariesByCampaign[$c->permalink][] = $result;
         });
     });
     ksort($beneficiariesByCampaign);
     return $beneficiariesByCampaign;
 }
开发者ID:npmweb,项目名称:service-opportunities,代码行数:22,代码来源:BeneficiaryDetailTransformer.php

示例8: sort

 /**
  * Sort through each item with a callback.
  *
  * @param  callable|null $callback
  * @return static
  */
 public function sort(callable $callback = null)
 {
     return parent::sort($callback ?: function (Addon $a, Addon $b) {
         if ($a->getSlug() == $b->getSlug()) {
             return 0;
         }
         return $a->getSlug() < $b->getSlug() ? -1 : 1;
     });
 }
开发者ID:jacksun101,项目名称:streams-platform,代码行数:15,代码来源:AddonCollection.php

示例9: getFilteredOrderedTasks

 /**
  * @param \Illuminate\Support\Collection $tasks
  *
  * @return \Illuminate\Support\Collection
  */
 private function getFilteredOrderedTasks(Collection $tasks)
 {
     return $tasks->sort(function ($a, $b) {
         $aProjectId = array_get($a, 'relationships.project.data.id');
         $bProjectId = array_get($b, 'relationships.project.data.id');
         if ($aProjectId === $bProjectId) {
             if ($a['id'] === $b['id']) {
                 return 0;
             }
             return $a['id'] < $b['id'] ? -1 : 1;
         }
         return $aProjectId < $bProjectId ? -1 : 1;
     });
 }
开发者ID:donepm,项目名称:cli-client,代码行数:19,代码来源:ListCommand.php


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