2018-04-11 19:49:35 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Grocy\Controllers;
|
|
|
|
|
2018-04-12 21:13:38 +02:00
|
|
|
use \Grocy\Services\HabitsService;
|
2018-04-11 19:49:35 +02:00
|
|
|
|
|
|
|
class HabitsController extends BaseController
|
|
|
|
{
|
|
|
|
public function __construct(\Slim\Container $container)
|
|
|
|
{
|
|
|
|
parent::__construct($container);
|
|
|
|
$this->HabitsService = new HabitsService();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected $HabitsService;
|
|
|
|
|
2018-04-12 21:13:38 +02:00
|
|
|
public function Overview(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
2018-04-11 19:49:35 +02:00
|
|
|
{
|
|
|
|
return $this->AppContainer->view->render($response, 'habitsoverview', [
|
2018-07-08 13:59:42 +02:00
|
|
|
'habits' => $this->Database->habits()->orderBy('name'),
|
2018-08-04 15:44:58 +02:00
|
|
|
'currentHabits' => $this->HabitsService->GetCurrent(),
|
|
|
|
'nextXDays' => 5
|
2018-04-11 19:49:35 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2018-04-12 21:13:38 +02:00
|
|
|
public function TrackHabitExecution(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
2018-04-11 19:49:35 +02:00
|
|
|
{
|
|
|
|
return $this->AppContainer->view->render($response, 'habittracking', [
|
2018-07-24 20:45:14 +02:00
|
|
|
'habits' => $this->Database->habits()->orderBy('name'),
|
|
|
|
'users' => $this->Database->users()->orderBy('username')
|
2018-04-11 19:49:35 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2018-04-12 21:13:38 +02:00
|
|
|
public function HabitsList(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
2018-04-11 19:49:35 +02:00
|
|
|
{
|
|
|
|
return $this->AppContainer->view->render($response, 'habits', [
|
2018-07-08 13:59:42 +02:00
|
|
|
'habits' => $this->Database->habits()->orderBy('name')
|
2018-04-11 19:49:35 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2018-07-25 20:01:58 +02:00
|
|
|
public function Analysis(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
|
|
|
{
|
|
|
|
return $this->AppContainer->view->render($response, 'habitsanalysis', [
|
|
|
|
'habitsLog' => $this->Database->habits_log()->orderBy('tracked_time', 'DESC'),
|
|
|
|
'habits' => $this->Database->habits()->orderBy('name'),
|
|
|
|
'users' => $this->Database->users()->orderBy('username')
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2018-04-12 21:13:38 +02:00
|
|
|
public function HabitEditForm(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
2018-04-11 19:49:35 +02:00
|
|
|
{
|
|
|
|
if ($args['habitId'] == 'new')
|
|
|
|
{
|
|
|
|
return $this->AppContainer->view->render($response, 'habitform', [
|
2018-04-12 21:13:38 +02:00
|
|
|
'periodTypes' => GetClassConstants('\Grocy\Services\HabitsService'),
|
2018-04-11 19:49:35 +02:00
|
|
|
'mode' => 'create'
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return $this->AppContainer->view->render($response, 'habitform', [
|
|
|
|
'habit' => $this->Database->habits($args['habitId']),
|
2018-04-12 21:13:38 +02:00
|
|
|
'periodTypes' => GetClassConstants('\Grocy\Services\HabitsService'),
|
2018-04-11 19:49:35 +02:00
|
|
|
'mode' => 'edit'
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|