This commit is contained in:
James Cole 2018-06-01 13:11:10 +02:00
parent 3654e75b8c
commit 4c04415e80
5 changed files with 27 additions and 18 deletions

View File

@ -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();

View File

@ -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
{

View File

@ -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();
}}

View File

@ -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
*/

View File

@ -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'));