本文整理汇总了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;
}
示例2: getExpenses
/**
* @return Collection
*/
public function getExpenses()
{
$set = $this->expenses->sortBy(function (stdClass $object) {
return $object->amount;
});
return $set;
}
示例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);
}
}
示例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;
}
示例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;
}
示例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();
}
}
}
示例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();
}
}
示例8: sortWidgets
/**
* @return $this
*/
protected function sortWidgets()
{
$this->registeredWidgets = $this->registeredWidgets->sortBy(function (WidgetCollectionItem $widget) {
return $widget->getPosition();
});
return $this;
}
示例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');
});
}
示例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;
}
示例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();
}
示例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();
}
}
}
}
示例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();
}
}
}
示例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]);
}
示例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]);
}