mirror of
				https://github.com/firefly-iii/firefly-iii.git
				synced 2025-10-31 02:36:28 +00:00 
			
		
		
		
	Updated API code.
This commit is contained in:
		| @@ -53,6 +53,7 @@ use Log; | ||||
| class RecurringRepository implements RecurringRepositoryInterface | ||||
| { | ||||
|     use CalculateRangeOccurrences, CalculateXOccurrences, CalculateXOccurrencesSince, FiltersWeekends; | ||||
|  | ||||
|     private User $user; | ||||
|  | ||||
|  | ||||
| @@ -522,6 +523,7 @@ class RecurringRepository implements RecurringRepositoryInterface | ||||
|  | ||||
|         // filter out everything if "repeat_until" is set. | ||||
|         $repeatUntil = $repetition->recurrence->repeat_until; | ||||
|  | ||||
|         return $this->filterMaxDate($repeatUntil, $occurrences); | ||||
|     } | ||||
|  | ||||
| @@ -560,16 +562,16 @@ class RecurringRepository implements RecurringRepositoryInterface | ||||
|     public function totalTransactions(Recurrence $recurrence, RecurrenceRepetition $repetition): int | ||||
|     { | ||||
|         // if repeat = null just return 0. | ||||
|         if (null === $recurrence->repeat_until && 0 === (int) $recurrence->repetitions) { | ||||
|         if (null === $recurrence->repeat_until && 0 === (int)$recurrence->repetitions) { | ||||
|             return 0; | ||||
|         } | ||||
|         // expect X transactions then stop. Return that number | ||||
|         if (null === $recurrence->repeat_until && 0 !== (int) $recurrence->repetitions) { | ||||
|             return (int) $recurrence->repetitions; | ||||
|         if (null === $recurrence->repeat_until && 0 !== (int)$recurrence->repetitions) { | ||||
|             return (int)$recurrence->repetitions; | ||||
|         } | ||||
|  | ||||
|         // need to calculate, this depends on the repetition: | ||||
|         if (null !== $recurrence->repeat_until && 0 === (int) $recurrence->repetitions) { | ||||
|         if (null !== $recurrence->repeat_until && 0 === (int)$recurrence->repetitions) { | ||||
|             $occurrences = $this->getOccurrencesInRange($repetition, $recurrence->first_date ?? today(), $recurrence->repeat_until); | ||||
|  | ||||
|             return count($occurrences); | ||||
| @@ -577,4 +579,19 @@ class RecurringRepository implements RecurringRepositoryInterface | ||||
|  | ||||
|         return 0; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @inheritDoc | ||||
|      */ | ||||
|     public function searchRecurrence(string $query, int $limit): Collection | ||||
|     { | ||||
|         $search = $this->user->recurrences(); | ||||
|         if ('' !== $query) { | ||||
|             $search->where('recurrences.title', 'LIKE', sprintf('%%%s%%', $query)); | ||||
|         } | ||||
|         $search | ||||
|             ->orderBy('recurrences.title', 'ASC'); | ||||
|  | ||||
|         return $search->take($limit)->get(['id', 'title', 'description']); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -44,6 +44,14 @@ interface RecurringRepositoryInterface | ||||
|      */ | ||||
|     public function destroyAll(): void; | ||||
|  | ||||
|     /** | ||||
|      * @param string $query | ||||
|      * @param int    $limit | ||||
|      * | ||||
|      * @return Collection | ||||
|      */ | ||||
|     public function searchRecurrence(string $query, int $limit): Collection; | ||||
|  | ||||
|     /** | ||||
|      * Calculate how many transactions are to be expected from this recurrence. | ||||
|      * | ||||
|   | ||||
| @@ -565,4 +565,19 @@ class RuleRepository implements RuleRepositoryInterface | ||||
|         return implode(' ', $params); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @inheritDoc | ||||
|      */ | ||||
|     public function searchRule(string $query, int $limit): Collection | ||||
|     { | ||||
|         $search = $this->user->rules(); | ||||
|         if ('' !== $query) { | ||||
|             $search->where('rules.title', 'LIKE', sprintf('%%%s%%', $query)); | ||||
|         } | ||||
|         $search->orderBy('rules.order', 'ASC') | ||||
|                ->orderBy('rules.title', 'ASC'); | ||||
|  | ||||
|         return $search->take($limit)->get(['id','title','description']); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -39,6 +39,14 @@ interface RuleRepositoryInterface | ||||
|      */ | ||||
|     public function count(): int; | ||||
|  | ||||
|     /** | ||||
|      * @param string $query | ||||
|      * @param int    $limit | ||||
|      * | ||||
|      * @return Collection | ||||
|      */ | ||||
|     public function searchRule(string $query, int $limit): Collection; | ||||
|  | ||||
|     /** | ||||
|      * Return search query for rule. | ||||
|      * | ||||
|   | ||||
| @@ -388,4 +388,19 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface | ||||
|             $group->delete(); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @inheritDoc | ||||
|      */ | ||||
|     public function searchRuleGroup(string $query, int $limit): Collection | ||||
|     { | ||||
|         $search = $this->user->ruleGroups(); | ||||
|         if ('' !== $query) { | ||||
|             $search->where('rule_groups.title', 'LIKE', sprintf('%%%s%%', $query)); | ||||
|         } | ||||
|         $search->orderBy('rule_groups.order', 'ASC') | ||||
|                ->orderBy('rule_groups.title', 'ASC'); | ||||
|  | ||||
|         return $search->take($limit)->get(['id','title','description']); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -36,6 +36,14 @@ interface RuleGroupRepositoryInterface | ||||
|      */ | ||||
|     public function destroyAll(): void; | ||||
|  | ||||
|     /** | ||||
|      * @param string $query | ||||
|      * @param int    $limit | ||||
|      * | ||||
|      * @return Collection | ||||
|      */ | ||||
|     public function searchRuleGroup(string $query, int $limit): Collection; | ||||
|  | ||||
|     /** | ||||
|      * @return int | ||||
|      */ | ||||
| @@ -155,7 +163,7 @@ interface RuleGroupRepositoryInterface | ||||
|  | ||||
|     /** | ||||
|      * @param RuleGroup $ruleGroup | ||||
|      * @param array $data | ||||
|      * @param array     $data | ||||
|      * | ||||
|      * @return RuleGroup | ||||
|      */ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user