| 
									
										
										
										
											2021-03-07 09:46:12 +01:00
										 |  |  | <?php | 
					
						
							| 
									
										
										
										
											2021-08-10 19:31:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-07 09:46:12 +01:00
										 |  |  | /* | 
					
						
							| 
									
										
										
										
											2021-08-10 19:31:55 +02:00
										 |  |  |  * PreferenceUpdateRequest.php | 
					
						
							| 
									
										
										
										
											2021-03-07 09:46:12 +01:00
										 |  |  |  * Copyright (c) 2021 james@firefly-iii.org | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This file is part of Firefly III (https://github.com/firefly-iii). | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is free software: you can redistribute it and/or modify | 
					
						
							|  |  |  |  * it under the terms of the GNU Affero General Public License as | 
					
						
							|  |  |  |  * published by the Free Software Foundation, either version 3 of the | 
					
						
							|  |  |  |  * License, or (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU Affero General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU Affero General Public License | 
					
						
							|  |  |  |  * along with this program.  If not, see <https://www.gnu.org/licenses/>. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-10 19:31:55 +02:00
										 |  |  | declare(strict_types=1); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-07 09:46:12 +01:00
										 |  |  | namespace FireflyIII\Api\V1\Requests\User; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | use FireflyIII\Support\Request\ChecksLogin; | 
					
						
							|  |  |  | use FireflyIII\Support\Request\ConvertsDataTypes; | 
					
						
							|  |  |  | use Illuminate\Foundation\Http\FormRequest; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-04 13:29:19 +02:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Class PreferenceUpdateRequest | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2021-03-07 09:46:12 +01:00
										 |  |  | class PreferenceUpdateRequest extends FormRequest | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2022-10-30 14:23:00 +01:00
										 |  |  |     use ChecksLogin; | 
					
						
							|  |  |  |     use ConvertsDataTypes; | 
					
						
							| 
									
										
										
										
											2021-03-07 09:46:12 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     public function getAll(): array | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $array = [ | 
					
						
							| 
									
										
										
										
											2022-05-02 19:35:35 +02:00
										 |  |  |             'name' => $this->convertString('name'), | 
					
						
							| 
									
										
										
										
											2021-03-07 09:46:12 +01:00
										 |  |  |             'data' => $this->get('data'), | 
					
						
							|  |  |  |         ]; | 
					
						
							|  |  |  |         if ('true' === $array['data']) { | 
					
						
							|  |  |  |             $array['data'] = true; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if ('false' === $array['data']) { | 
					
						
							|  |  |  |             $array['data'] = false; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-03-21 09:15:40 +01:00
										 |  |  |         if (is_numeric($array['data'])) { | 
					
						
							| 
									
										
										
										
											2024-12-22 08:43:12 +01:00
										 |  |  |             $array['data'] = (float) $array['data']; // intentional float.
 | 
					
						
							| 
									
										
										
										
											2021-03-07 09:46:12 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $array; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @return string[] | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function rules(): array | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return [ | 
					
						
							|  |  |  |             'data' => 'required', | 
					
						
							|  |  |  |         ]; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-03-28 11:39:26 +02:00
										 |  |  | } |