summaryrefslogtreecommitdiff
path: root/app/Console
diff options
context:
space:
mode:
Diffstat (limited to 'app/Console')
-rw-r--r--app/Console/Base.php58
-rw-r--r--app/Console/ProjectDailySummaryCalculation.php27
-rw-r--r--app/Console/ProjectDailySummaryExport.php34
-rw-r--r--app/Console/SubtaskExport.php34
-rw-r--r--app/Console/TaskExport.php34
-rw-r--r--app/Console/TaskOverdueNotification.php50
-rw-r--r--app/Console/TransitionExport.php34
7 files changed, 271 insertions, 0 deletions
diff --git a/app/Console/Base.php b/app/Console/Base.php
new file mode 100644
index 00000000..07243080
--- /dev/null
+++ b/app/Console/Base.php
@@ -0,0 +1,58 @@
+<?php
+
+namespace Console;
+
+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\SubtaskExport $subtaskExport
+ * @property \Model\Task $task
+ * @property \Model\TaskExport $taskExport
+ * @property \Model\TaskFinder $taskFinder
+ * @property \Model\Transition $transition
+ */
+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 $this->container[$name];
+ }
+}
diff --git a/app/Console/ProjectDailySummaryCalculation.php b/app/Console/ProjectDailySummaryCalculation.php
new file mode 100644
index 00000000..b2ada1b6
--- /dev/null
+++ b/app/Console/ProjectDailySummaryCalculation.php
@@ -0,0 +1,27 @@
+<?php
+
+namespace Console;
+
+use Model\Project;
+use Symfony\Component\Console\Input\InputInterface;
+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..07841d52
--- /dev/null
+++ b/app/Console/ProjectDailySummaryExport.php
@@ -0,0 +1,34 @@
+<?php
+
+namespace Console;
+
+use Core\Tool;
+use Symfony\Component\Console\Input\InputArgument;
+use Symfony\Component\Console\Input\InputInterface;
+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/SubtaskExport.php b/app/Console/SubtaskExport.php
new file mode 100644
index 00000000..167a9225
--- /dev/null
+++ b/app/Console/SubtaskExport.php
@@ -0,0 +1,34 @@
+<?php
+
+namespace Console;
+
+use Core\Tool;
+use Symfony\Component\Console\Input\InputArgument;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+
+class SubtaskExport extends Base
+{
+ protected function configure()
+ {
+ $this
+ ->setName('export:subtasks')
+ ->setDescription('Subtasks 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->subtaskExport->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/TaskExport.php b/app/Console/TaskExport.php
new file mode 100644
index 00000000..2ecd45e5
--- /dev/null
+++ b/app/Console/TaskExport.php
@@ -0,0 +1,34 @@
+<?php
+
+namespace Console;
+
+use Core\Tool;
+use Symfony\Component\Console\Input\InputArgument;
+use Symfony\Component\Console\Input\InputInterface;
+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..3d254ae4
--- /dev/null
+++ b/app/Console/TaskOverdueNotification.php
@@ -0,0 +1,50 @@
+<?php
+
+namespace Console;
+
+use Symfony\Component\Console\Helper\Table;
+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)
+ {
+ $tasks = $this->notification->sendOverdueTaskNotifications();
+
+ 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/Console/TransitionExport.php b/app/Console/TransitionExport.php
new file mode 100644
index 00000000..ad988c54
--- /dev/null
+++ b/app/Console/TransitionExport.php
@@ -0,0 +1,34 @@
+<?php
+
+namespace Console;
+
+use Core\Tool;
+use Symfony\Component\Console\Input\InputArgument;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+
+class TransitionExport extends Base
+{
+ protected function configure()
+ {
+ $this
+ ->setName('export:transitions')
+ ->setDescription('Task transitions 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->transition->export(
+ $input->getArgument('project_id'),
+ $input->getArgument('start_date'),
+ $input->getArgument('end_date')
+ );
+
+ if (is_array($data)) {
+ Tool::csv($data);
+ }
+ }
+}