Files
firefly-iii/app/lib/FireflyIII/Database/PiggyBank/PiggyBank.php

60 lines
1.5 KiB
PHP
Raw Normal View History

<?php
2014-12-13 22:11:51 +01:00
namespace FireflyIII\Database\PiggyBank;
use Carbon\Carbon;
2015-01-02 06:05:40 +01:00
use FireflyIII\Database\CommonDatabaseCallsInterface;
use FireflyIII\Database\CUDInterface;
2014-12-06 12:12:55 +01:00
use FireflyIII\Exception\FireflyException;
2014-11-12 22:21:48 +01:00
use FireflyIII\Exception\NotImplementedException;
use Illuminate\Support\Collection;
2014-12-06 12:12:55 +01:00
/**
* Class PiggyBank
*
* @package FireflyIII\Database
*/
2015-01-02 06:05:40 +01:00
class PiggyBank extends PiggyBankShared implements CUDInterface, CommonDatabaseCallsInterface, PiggyBankInterface
{
2014-12-13 21:59:02 +01:00
/**
* @param \PiggyBank $piggyBank
2014-12-13 21:59:02 +01:00
* @param Carbon $date
*
* @return mixed
* @throws FireflyException
* @throws NotImplementedException
*/
public function findRepetitionByDate(\PiggyBank $piggyBank, Carbon $date)
{
/** @var Collection $reps */
$reps = $piggyBank->piggyBankRepetitions()->get();
if ($reps->count() == 1) {
return $reps->first();
}
// should filter the one we need:
$repetitions = $reps->filter(
function (\PiggyBankRepetition $rep) use ($date) {
if ($date->between($rep->startdate, $rep->targetdate)) {
return $rep;
}
2014-12-20 15:00:53 +01:00
2014-12-19 21:18:42 +01:00
return null;
}
);
if ($repetitions->count() == 0) {
return null;
}
return $repetitions->first();
}
/**
* Returns all objects.
*
* @return Collection
*/
public function get()
{
return $this->getUser()->piggyBanks()->where('repeats', 0)->orderBy('name')->get();
2014-11-02 14:59:09 +01:00
}
2015-01-02 06:16:49 +01:00
}