| 
									
										
										
										
											2018-04-11 19:49:35 +02:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace Grocy\Controllers; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class BatteriesController extends BaseController | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-08-31 20:40:31 +02:00
										 |  |  | 	public function BatteriesList(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args) | 
					
						
							| 
									
										
										
										
											2018-04-11 19:49:35 +02:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2020-08-31 20:40:31 +02:00
										 |  |  | 		return $this->renderPage($response, 'batteries', [ | 
					
						
							| 
									
										
										
										
											2020-03-01 23:47:47 +07:00
										 |  |  | 			'batteries' => $this->getDatabase()->batteries()->orderBy('name'), | 
					
						
							|  |  |  | 			'userfields' => $this->getUserfieldsService()->GetFields('batteries'), | 
					
						
							|  |  |  | 			'userfieldValues' => $this->getUserfieldsService()->GetAllValues('batteries') | 
					
						
							| 
									
										
										
										
											2018-04-11 19:49:35 +02:00
										 |  |  | 		]); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-31 20:40:31 +02:00
										 |  |  | 	public function BatteriesSettings(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args) | 
					
						
							| 
									
										
										
										
											2018-04-11 19:49:35 +02:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2020-08-31 20:40:31 +02:00
										 |  |  | 		return $this->renderPage($response, 'batteriessettings'); | 
					
						
							| 
									
										
										
										
											2018-04-11 19:49:35 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-11 17:42:03 +01:00
										 |  |  | 	public function BatteryEditForm(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args) | 
					
						
							| 
									
										
										
										
											2018-04-11 19:49:35 +02:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		if ($args['batteryId'] == 'new') | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2020-03-01 23:47:47 +07:00
										 |  |  | 			return $this->renderPage($response, 'batteryform', [ | 
					
						
							| 
									
										
										
										
											2019-04-22 22:16:35 +02:00
										 |  |  | 				'mode' => 'create', | 
					
						
							| 
									
										
										
										
											2020-03-01 23:47:47 +07:00
										 |  |  | 				'userfields' => $this->getUserfieldsService()->GetFields('batteries') | 
					
						
							| 
									
										
										
										
											2018-04-11 19:49:35 +02:00
										 |  |  | 			]); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2020-03-01 23:47:47 +07:00
										 |  |  | 			return $this->renderPage($response, 'batteryform', [ | 
					
						
							| 
									
										
										
										
											2020-08-31 20:40:31 +02:00
										 |  |  | 				'battery' => $this->getDatabase()->batteries($args['batteryId']), | 
					
						
							| 
									
										
										
										
											2019-04-22 22:16:35 +02:00
										 |  |  | 				'mode' => 'edit', | 
					
						
							| 
									
										
										
										
											2020-03-01 23:47:47 +07:00
										 |  |  | 				'userfields' => $this->getUserfieldsService()->GetFields('batteries') | 
					
						
							| 
									
										
										
										
											2018-04-11 19:49:35 +02:00
										 |  |  | 			]); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-10-27 17:26:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-11 17:42:03 +01:00
										 |  |  | 	public function Journal(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args) | 
					
						
							| 
									
										
										
										
											2018-10-27 17:26:00 +02:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2020-03-01 23:47:47 +07:00
										 |  |  | 		return $this->renderPage($response, 'batteriesjournal', [ | 
					
						
							|  |  |  | 			'chargeCycles' => $this->getDatabase()->battery_charge_cycles()->orderBy('tracked_time', 'DESC'), | 
					
						
							|  |  |  | 			'batteries' => $this->getDatabase()->batteries()->orderBy('name') | 
					
						
							| 
									
										
										
										
											2018-10-27 17:26:00 +02:00
										 |  |  | 		]); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-04-20 15:30:45 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-31 20:40:31 +02:00
										 |  |  | 	public function Overview(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args) | 
					
						
							| 
									
										
										
										
											2019-04-20 15:30:45 +02:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2020-08-31 20:40:31 +02:00
										 |  |  | 		$usersService = $this->getUsersService(); | 
					
						
							|  |  |  | 		$nextXDays = $usersService->GetUserSettings(GROCY_USER_ID)['batteries_due_soon_days']; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return $this->renderPage($response, 'batteriesoverview', [ | 
					
						
							|  |  |  | 			'batteries' => $this->getDatabase()->batteries()->orderBy('name'), | 
					
						
							|  |  |  | 			'current' => $this->getBatteriesService()->GetCurrent(), | 
					
						
							|  |  |  | 			'nextXDays' => $nextXDays, | 
					
						
							|  |  |  | 			'userfields' => $this->getUserfieldsService()->GetFields('batteries'), | 
					
						
							|  |  |  | 			'userfieldValues' => $this->getUserfieldsService()->GetAllValues('batteries') | 
					
						
							|  |  |  | 		]); | 
					
						
							| 
									
										
										
										
											2019-04-20 15:30:45 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-08-31 20:40:31 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	public function TrackChargeCycle(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		return $this->renderPage($response, 'batterytracking', [ | 
					
						
							|  |  |  | 			'batteries' => $this->getDatabase()->batteries()->orderBy('name') | 
					
						
							|  |  |  | 		]); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	public function __construct(\DI\Container $container) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		parent::__construct($container); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-04-11 19:49:35 +02:00
										 |  |  | } |