Fixed sorting in tags.

This commit is contained in:
James Cole 2015-07-19 13:46:20 +02:00
parent ecf61c31f1
commit fe807e23f8

View File

@ -188,22 +188,24 @@ class TagController extends Controller
/** @var Collection $tags */ /** @var Collection $tags */
$tags = Auth::user()->tags()->where('tagMode', $type)->orderBy('date', 'ASC')->get(); $tags = Auth::user()->tags()->where('tagMode', $type)->orderBy('date', 'ASC')->get();
$tags = $tags->sortBy( $tags = $tags->sortBy(
function (Tag $tag) { function (Tag $tag) {
return strtolower($tag->tag); $date = $tag->date->format('Ymd');
return strtolower($date . $tag->tag);
} }
); );
/** @var Tag $tag */ /** @var Tag $tag */
foreach ($tags as $tag) { foreach ($tags as $tag) {
$year = is_null($tag->date) ? trans('firefly.no_year') : $tag->date->year;
$month = is_null($tag->date) ? trans('firefly.no_month') : $tag->date->formatLocalized($this->monthFormat); $year = is_null($tag->date) ? trans('firefly.no_year') : $tag->date->year;
$collection[$type][$year][$month][] = $tag; $monthFormatted = is_null($tag->date) ? trans('firefly.no_month') : $tag->date->formatLocalized($this->monthFormat);
$collection[$type][$year][$monthFormatted][] = $tag;
} }
} }
return view('tags.index', compact('title', 'mainTitleIcon', 'types', 'helpHidden', 'collection')); return view('tags.index', compact('title', 'mainTitleIcon', 'types', 'helpHidden', 'collection'));
} }