mirror of
				https://github.com/firefly-iii/firefly-iii.git
				synced 2025-10-31 02:36:28 +00:00 
			
		
		
		
	Various bug fixes.
This commit is contained in:
		| @@ -8,6 +8,8 @@ | ||||
|  | ||||
| namespace Firefly\Helper\Controllers; | ||||
|  | ||||
| use Illuminate\Support\Collection; | ||||
|  | ||||
| /** | ||||
|  * Class Search | ||||
|  * | ||||
| @@ -18,26 +20,89 @@ class Search implements SearchInterface | ||||
|  | ||||
|     /** | ||||
|      * @param array $words | ||||
|      * | ||||
|      * @return Collection | ||||
|      */ | ||||
|     public function transactions(array $words) | ||||
|     public function searchTransactions(array $words) | ||||
|     { | ||||
|         $query = \TransactionJournal::withRelevantData(); | ||||
|  | ||||
|         $fullCount = $query->count(); | ||||
|  | ||||
|         $query->where( | ||||
|         return \Auth::user()->transactionjournals()->withRelevantData()->where( | ||||
|             function ($q) use ($words) { | ||||
|                 foreach ($words as $word) { | ||||
|                     $q->orWhere('description', 'LIKE', '%' . e($word) . '%'); | ||||
|                 } | ||||
|             } | ||||
|         ); | ||||
|         $count = $query->count(); | ||||
|         $set = $query->get(); | ||||
|         /* | ||||
|          * Build something with JSON? | ||||
|          */ | ||||
|         return $set; | ||||
|         )->get(); | ||||
|     } | ||||
|  | ||||
| }  | ||||
|     /** | ||||
|      * @param array $words | ||||
|      * | ||||
|      * @return Collection | ||||
|      */ | ||||
|     public function searchAccounts(array $words) | ||||
|     { | ||||
|         return \Auth::user()->accounts()->with('accounttype')->where( | ||||
|             function ($q) use ($words) { | ||||
|                 foreach ($words as $word) { | ||||
|                     $q->orWhere('name', 'LIKE', '%' . e($word) . '%'); | ||||
|                 } | ||||
|             } | ||||
|         )->get(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param array $words | ||||
|      * | ||||
|      * @return Collection | ||||
|      */ | ||||
|     public function searchCategories(array $words) | ||||
|     { | ||||
|         /** @var Collection $set */ | ||||
|         $set = \Auth::user()->categories()->get(); | ||||
|         $newSet = $set->filter( | ||||
|             function (\Category $c) use ($words) { | ||||
|                 $found = 0; | ||||
|                 foreach ($words as $word) { | ||||
|                     if (!(strpos(strtolower($c->name), strtolower($word)) === false)) { | ||||
|                         $found++; | ||||
|                     } | ||||
|                 } | ||||
|                 return $found > 0; | ||||
|             } | ||||
|         ); | ||||
|         return $newSet; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param array $words | ||||
|      * | ||||
|      * @return Collection | ||||
|      */ | ||||
|     public function searchBudgets(array $words) | ||||
|     { | ||||
|         /** @var Collection $set */ | ||||
|         $set = \Auth::user()->budgets()->get(); | ||||
|         $newSet = $set->filter( | ||||
|             function (\Budget $b) use ($words) { | ||||
|                 $found = 0; | ||||
|                 foreach ($words as $word) { | ||||
|                     if (!(strpos(strtolower($b->name), strtolower($word)) === false)) { | ||||
|                         $found++; | ||||
|                     } | ||||
|                 } | ||||
|                 return $found > 0; | ||||
|             } | ||||
|         ); | ||||
|         return $newSet; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param array $words | ||||
|      * | ||||
|      * @return Collection | ||||
|      */ | ||||
|     public function searchTags(array $words) | ||||
|     { | ||||
|         return new Collection; | ||||
|     } | ||||
| } | ||||
| @@ -18,5 +18,26 @@ interface SearchInterface | ||||
|     /** | ||||
|      * @param array $words | ||||
|      */ | ||||
|     public function transactions(array $words); | ||||
| }  | ||||
|     public function searchTransactions(array $words); | ||||
|  | ||||
|     /** | ||||
|      * @param array $words | ||||
|      */ | ||||
|     public function searchAccounts(array $words); | ||||
|  | ||||
|     /** | ||||
|      * @param array $words | ||||
|      */ | ||||
|     public function searchCategories(array $words); | ||||
|  | ||||
|     /** | ||||
|      * @param array $words | ||||
|      */ | ||||
|     public function searchBudgets(array $words); | ||||
|  | ||||
|     /** | ||||
|      * @param array $words | ||||
|      */ | ||||
|     public function searchTags(array $words); | ||||
|  | ||||
| } | ||||
		Reference in New Issue
	
	Block a user