diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/Console/Base.php | 57 | ||||
-rw-r--r-- | app/Console/ProjectDailySummaryCalculation.php | 29 | ||||
-rw-r--r-- | app/Console/ProjectDailySummaryExport.php | 35 | ||||
-rw-r--r-- | app/Console/TaskExport.php | 35 | ||||
-rw-r--r-- | app/Console/TaskOverdueNotification.php | 69 | ||||
-rw-r--r-- | app/Core/Cli.php | 75 |
6 files changed, 225 insertions, 75 deletions
diff --git a/app/Console/Base.php b/app/Console/Base.php new file mode 100644 index 00000000..f955b428 --- /dev/null +++ b/app/Console/Base.php @@ -0,0 +1,57 @@ +<?php + +namespace Console; + +use Core\Tool; +use Pimple\Container; +use Symfony\Component\Console\Command\Command; + +/** + * Base command class + * + * @package console + * @author Frederic Guillot + * + * @property \Model\Notification $notification + * @property \Model\Project $project + * @property \Model\ProjectPermission $projectPermission + * @property \Model\ProjectAnalytic $projectAnalytic + * @property \Model\ProjectDailySummary $projectDailySummary + * @property \Model\Task $task + * @property \Model\TaskExport $taskExport + * @property \Model\TaskFinder $taskFinder + */ +abstract class Base extends Command +{ + /** + * Container instance + * + * @access protected + * @var \Pimple\Container + */ + protected $container; + + /** + * Constructor + * + * @access public + * @param \Pimple\Container $container + */ + public function __construct(Container $container) + { + parent::__construct(); + $this->container = $container; + } + + /** + * Load automatically models + * + * @access public + * @param string $name Model name + * @return mixed + */ + public function __get($name) + { + return Tool::loadModel($this->container, $name); + } +} diff --git a/app/Console/ProjectDailySummaryCalculation.php b/app/Console/ProjectDailySummaryCalculation.php new file mode 100644 index 00000000..04c4083d --- /dev/null +++ b/app/Console/ProjectDailySummaryCalculation.php @@ -0,0 +1,29 @@ +<?php + +namespace Console; + +use Model\Project; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; + +class ProjectDailySummaryCalculation extends Base +{ + protected function configure() + { + $this + ->setName('projects:daily-summary') + ->setDescription('Calculate daily summary data for all projects'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $projects = $this->project->getAllByStatus(Project::ACTIVE); + + foreach ($projects as $project) { + $output->writeln('Run calculation for '.$project['name']); + $this->projectDailySummary->updateTotals($project['id'], date('Y-m-d')); + } + } +} diff --git a/app/Console/ProjectDailySummaryExport.php b/app/Console/ProjectDailySummaryExport.php new file mode 100644 index 00000000..6b96fddd --- /dev/null +++ b/app/Console/ProjectDailySummaryExport.php @@ -0,0 +1,35 @@ +<?php + +namespace Console; + +use Core\Tool; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; + +class ProjectDailySummaryExport extends Base +{ + protected function configure() + { + $this + ->setName('export:daily-project-summary') + ->setDescription('Daily project summary CSV export (number of tasks per column and per day)') + ->addArgument('project_id', InputArgument::REQUIRED, 'Project id') + ->addArgument('start_date', InputArgument::REQUIRED, 'Start date (YYYY-MM-DD)') + ->addArgument('end_date', InputArgument::REQUIRED, 'End date (YYYY-MM-DD)'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $data = $this->projectDailySummary->getAggregatedMetrics( + $input->getArgument('project_id'), + $input->getArgument('start_date'), + $input->getArgument('end_date') + ); + + if (is_array($data)) { + Tool::csv($data); + } + } +} diff --git a/app/Console/TaskExport.php b/app/Console/TaskExport.php new file mode 100644 index 00000000..dea71fe6 --- /dev/null +++ b/app/Console/TaskExport.php @@ -0,0 +1,35 @@ +<?php + +namespace Console; + +use Core\Tool; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; + +class TaskExport extends Base +{ + protected function configure() + { + $this + ->setName('export:tasks') + ->setDescription('Tasks CSV export') + ->addArgument('project_id', InputArgument::REQUIRED, 'Project id') + ->addArgument('start_date', InputArgument::REQUIRED, 'Start date (YYYY-MM-DD)') + ->addArgument('end_date', InputArgument::REQUIRED, 'End date (YYYY-MM-DD)'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $data = $this->taskExport->export( + $input->getArgument('project_id'), + $input->getArgument('start_date'), + $input->getArgument('end_date') + ); + + if (is_array($data)) { + Tool::csv($data); + } + } +} diff --git a/app/Console/TaskOverdueNotification.php b/app/Console/TaskOverdueNotification.php new file mode 100644 index 00000000..aa70fd01 --- /dev/null +++ b/app/Console/TaskOverdueNotification.php @@ -0,0 +1,69 @@ +<?php + +namespace Console; + +use Symfony\Component\Console\Helper\Table; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; + +class TaskOverdueNotification extends Base +{ + protected function configure() + { + $this + ->setName('notification:overdue-tasks') + ->setDescription('Send notifications for overdue tasks') + ->addOption('show', null, InputOption::VALUE_NONE, 'Show sent overdue tasks'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $projects = array(); + $tasks = $this->taskFinder->getOverdueTasks(); + + // Group tasks by project + foreach ($tasks as $task) { + $projects[$task['project_id']][] = $task; + } + + // Send notifications for each project + foreach ($projects as $project_id => $project_tasks) { + + $users = $this->notification->getUsersList($project_id); + + $this->notification->sendEmails( + 'task_due', + $users, + array('tasks' => $project_tasks, 'project' => $project_tasks[0]['project_name']) + ); + } + + if ($input->getOption('show')) { + $this->showTable($output, $tasks); + } + } + + public function showTable(OutputInterface $output, array $tasks) + { + $rows = array(); + + foreach ($tasks as $task) { + $rows[] = array( + $task['id'], + $task['title'], + date('Y-m-d', $task['date_due']), + $task['project_id'], + $task['project_name'], + $task['assignee_name'] ?: $task['assignee_username'], + ); + } + + $table = new Table($output); + $table + ->setHeaders(array('Id', 'Title', 'Due date', 'Project Id', 'Project name', 'Assignee')) + ->setRows($rows) + ->render(); + } +} diff --git a/app/Core/Cli.php b/app/Core/Cli.php deleted file mode 100644 index 13533b9a..00000000 --- a/app/Core/Cli.php +++ /dev/null @@ -1,75 +0,0 @@ -<?php - -namespace Core; - -use Closure; - -/** - * CLI class - * - * @package core - * @author Frederic Guillot - */ -class Cli -{ - /** - * Default command name - * - * @access public - * @var string - */ - public $default_command = 'help'; - - /** - * List of registered commands - * - * @access private - * @var array - */ - private $commands = array(); - - /** - * - * - * @access public - * @param string $command Command name - * @param Closure $callback Command callback - */ - public function register($command, Closure $callback) - { - $this->commands[$command] = $callback; - } - - /** - * Execute a command - * - * @access public - * @param string $command Command name - */ - public function call($command) - { - if (isset($this->commands[$command])) { - $this->commands[$command](); - exit; - } - } - - /** - * Determine which command to execute - * - * @access public - */ - public function execute() - { - if (php_sapi_name() !== 'cli') { - die('This script work only from the command line.'); - } - - if ($GLOBALS['argc'] === 1) { - $this->call($this->default_command); - } - - $this->call($GLOBALS['argv'][1]); - $this->call($this->default_command); - } -} |