mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Fix #1452.
This commit is contained in:
parent
3654e75b8c
commit
4c04415e80
@ -145,27 +145,18 @@ class TagController extends Controller
|
||||
public function index(TagRepositoryInterface $repository)
|
||||
{
|
||||
// start with oldest tag
|
||||
$oldestTag = $repository->oldestTag();
|
||||
/** @var Carbon $start */
|
||||
$start = new Carbon;
|
||||
if (null !== $oldestTag) {
|
||||
/** @var Carbon $start */
|
||||
$start = $oldestTag->date; // @codeCoverageIgnore
|
||||
}
|
||||
if (null === $oldestTag) {
|
||||
/** @var Carbon $start */
|
||||
$start = clone session('first');
|
||||
}
|
||||
|
||||
$now = new Carbon;
|
||||
$oldestTagDate = null === $repository->oldestTag() ? clone session('first') : $repository->oldestTag()->date;
|
||||
$newestTagDate = null === $repository->newestTag() ? new Carbon : $repository->newestTag()->date;
|
||||
$oldestTagDate->startOfYear();
|
||||
$newestTagDate->endOfYear();
|
||||
$clouds = [];
|
||||
$clouds['no-date'] = $repository->tagCloud(null);
|
||||
|
||||
while ($now > $start) {
|
||||
$year = $now->year;
|
||||
while ($newestTagDate > $oldestTagDate) {
|
||||
$year = $newestTagDate->year;
|
||||
$clouds[$year] = $repository->tagCloud($year);
|
||||
|
||||
$now->subYear();
|
||||
$newestTagDate->subYear();
|
||||
}
|
||||
$count = $repository->count();
|
||||
|
||||
|
@ -32,9 +32,11 @@ use FireflyIII\Models\TransactionJournal;
|
||||
|
||||
/**
|
||||
* Class Tag.
|
||||
*
|
||||
* @property Collection $transactionJournals
|
||||
* @property string $tag
|
||||
* @property int $id
|
||||
* @property \Carbon\Carbon $date
|
||||
*/
|
||||
class Tag extends Model
|
||||
{
|
||||
|
@ -336,7 +336,6 @@ class TagRepository implements TagRepositoryInterface
|
||||
}
|
||||
)
|
||||
->groupBy(['tags.id', 'tags.tag']);
|
||||
|
||||
// add date range (or not):
|
||||
if (null === $year) {
|
||||
Log::debug('Get tags without a date.');
|
||||
@ -464,4 +463,13 @@ class TagRepository implements TagRepositoryInterface
|
||||
{
|
||||
return $this->user->tags()->find($tagId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Will return the newest tag (if known) or NULL.
|
||||
*
|
||||
* @return Tag|null
|
||||
*/
|
||||
public function newestTag(): ?Tag
|
||||
{
|
||||
return $this->user->tags()->whereNotNull('date')->orderBy('date', 'DESC')->first();
|
||||
}}
|
||||
|
@ -116,10 +116,16 @@ interface TagRepositoryInterface
|
||||
public function lastUseDate(Tag $tag): Carbon;
|
||||
|
||||
/**
|
||||
* Will return the newest tag (if known) or NULL.
|
||||
* @return Tag|null
|
||||
*/
|
||||
public function oldestTag(): ?Tag;
|
||||
|
||||
/**
|
||||
* Will return the newest tag (if known) or NULL.
|
||||
* @return Tag|null
|
||||
*/
|
||||
public function newestTag(): ?Tag;
|
||||
/**
|
||||
* @param User $user
|
||||
*/
|
||||
|
@ -130,6 +130,8 @@ class TagControllerTest extends TestCase
|
||||
$repository->shouldReceive('count')->andReturn(0);
|
||||
$repository->shouldReceive('tagCloud')->andReturn([]);
|
||||
$repository->shouldReceive('oldestTag')->andReturn(null)->once();
|
||||
$repository->shouldReceive('newestTag')->andReturn(null)->once();
|
||||
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('tags.index'));
|
||||
|
Loading…
Reference in New Issue
Block a user