Display subtask estimates in the user calendar according to the timetable

This commit is contained in:
Frederic Guillot 2015-03-26 20:49:37 -04:00
parent 626ad566f7
commit d3ae8d2acb
25 changed files with 161 additions and 5 deletions

View File

@ -82,7 +82,9 @@ class Calendar extends Base
$subtask_timeslots = $this->subtaskTimeTracking->getUserCalendarEvents($user_id, $start, $end);
$this->response->json(array_merge($due_tasks, $subtask_timeslots));
$subtask_forcast = $this->config->get('subtask_forecast') == 1 ? $this->subtaskForecast->getCalendarEvents($user_id, $end) : array();
$this->response->json(array_merge($due_tasks, $subtask_timeslots, $subtask_forcast));
}
/**

View File

@ -41,7 +41,7 @@ class Config extends Base
$values = $this->request->getValues();
if ($redirect === 'board') {
$values += array('subtask_restriction' => 0, 'subtask_time_tracking' => 0);
$values += array('subtask_restriction' => 0, 'subtask_time_tracking' => 0, 'subtask_forecast' => 0);
}
if ($this->config->save($values)) {

View File

@ -808,4 +808,5 @@ return array(
// 'Move the task to another column when assigned to a user' => '',
// 'Move the task to another column when assignee is cleared' => '',
// 'Source column' => '',
// 'Show subtask estimates in the user calendar' => '',
);

View File

@ -808,4 +808,5 @@ return array(
// 'Move the task to another column when assigned to a user' => '',
// 'Move the task to another column when assignee is cleared' => '',
// 'Source column' => '',
// 'Show subtask estimates in the user calendar' => '',
);

View File

@ -808,4 +808,5 @@ return array(
// 'Move the task to another column when assigned to a user' => '',
// 'Move the task to another column when assignee is cleared' => '',
// 'Source column' => '',
// 'Show subtask estimates in the user calendar' => '',
);

View File

@ -808,4 +808,5 @@ return array(
// 'Move the task to another column when assigned to a user' => '',
// 'Move the task to another column when assignee is cleared' => '',
// 'Source column' => '',
// 'Show subtask estimates in the user calendar' => '',
);

View File

@ -810,4 +810,5 @@ return array(
'Move the task to another column when assigned to a user' => 'Déplacer la tâche dans une autre colonne lorsque celle-ci est assignée à quelqu\'un',
'Move the task to another column when assignee is cleared' => 'Déplacer la tâche dans une autre colonne lorsque celle-ci n\'est plus assignée',
'Source column' => 'Colonne d\'origine',
'Show subtask estimates in the user calendar' => 'Afficher le temps estimé des sous-tâches dans le calendrier utilisateur',
);

View File

@ -808,4 +808,5 @@ return array(
// 'Move the task to another column when assigned to a user' => '',
// 'Move the task to another column when assignee is cleared' => '',
// 'Source column' => '',
// 'Show subtask estimates in the user calendar' => '',
);

View File

@ -808,4 +808,5 @@ return array(
// 'Move the task to another column when assigned to a user' => '',
// 'Move the task to another column when assignee is cleared' => '',
// 'Source column' => '',
// 'Show subtask estimates in the user calendar' => '',
);

View File

@ -808,4 +808,5 @@ return array(
// 'Move the task to another column when assigned to a user' => '',
// 'Move the task to another column when assignee is cleared' => '',
// 'Source column' => '',
// 'Show subtask estimates in the user calendar' => '',
);

View File

@ -808,4 +808,5 @@ return array(
// 'Move the task to another column when assigned to a user' => '',
// 'Move the task to another column when assignee is cleared' => '',
// 'Source column' => '',
// 'Show subtask estimates in the user calendar' => '',
);

View File

@ -808,4 +808,5 @@ return array(
// 'Move the task to another column when assigned to a user' => '',
// 'Move the task to another column when assignee is cleared' => '',
// 'Source column' => '',
// 'Show subtask estimates in the user calendar' => '',
);

View File

@ -808,4 +808,5 @@ return array(
// 'Move the task to another column when assigned to a user' => '',
// 'Move the task to another column when assignee is cleared' => '',
// 'Source column' => '',
// 'Show subtask estimates in the user calendar' => '',
);

View File

@ -808,4 +808,5 @@ return array(
// 'Move the task to another column when assigned to a user' => '',
// 'Move the task to another column when assignee is cleared' => '',
// 'Source column' => '',
// 'Show subtask estimates in the user calendar' => '',
);

View File

@ -808,4 +808,5 @@ return array(
// 'Move the task to another column when assigned to a user' => '',
// 'Move the task to another column when assignee is cleared' => '',
// 'Source column' => '',
// 'Show subtask estimates in the user calendar' => '',
);

View File

@ -808,4 +808,5 @@ return array(
// 'Move the task to another column when assigned to a user' => '',
// 'Move the task to another column when assignee is cleared' => '',
// 'Source column' => '',
// 'Show subtask estimates in the user calendar' => '',
);

View File

@ -808,4 +808,5 @@ return array(
// 'Move the task to another column when assigned to a user' => '',
// 'Move the task to another column when assignee is cleared' => '',
// 'Source column' => '',
// 'Show subtask estimates in the user calendar' => '',
);

View File

@ -808,4 +808,5 @@ return array(
// 'Move the task to another column when assigned to a user' => '',
// 'Move the task to another column when assignee is cleared' => '',
// 'Source column' => '',
// 'Show subtask estimates in the user calendar' => '',
);

View File

@ -808,4 +808,5 @@ return array(
// 'Move the task to another column when assigned to a user' => '',
// 'Move the task to another column when assignee is cleared' => '',
// 'Source column' => '',
// 'Show subtask estimates in the user calendar' => '',
);

View File

@ -0,0 +1,117 @@
<?php
namespace Model;
use DateTime;
use DateInterval;
/**
* Subtask Forecast
*
* @package model
* @author Frederic Guillot
*/
class SubtaskForecast extends Base
{
/**
* Get not completed subtasks with an estimate sorted by postition
*
* @access public
* @param integer $user_id
* @return array
*/
public function getSubtasks($user_id)
{
return $this->db
->table(Subtask::TABLE)
->columns(Subtask::TABLE.'.id', Task::TABLE.'.project_id', Subtask::TABLE.'.task_id', Subtask::TABLE.'.title', Subtask::TABLE.'.time_estimated')
->join(Task::TABLE, 'id', 'task_id')
->asc(Task::TABLE.'.position')
->asc(Subtask::TABLE.'.position')
->gt(Subtask::TABLE.'.time_estimated', 0)
->eq(Subtask::TABLE.'.user_id', $user_id)
->findAll();
}
/**
* Get the start date for the forecast
*
* @access public
* @param integer $user_id
* @return array
*/
public function getStartDate($user_id)
{
$subtask = $this->db->table(Subtask::TABLE)
->columns(Subtask::TABLE.'.time_estimated', SubtaskTimeTracking::TABLE.'.start')
->eq(SubtaskTimeTracking::TABLE.'.user_id', $user_id)
->eq(SubtaskTimeTracking::TABLE.'.end', 0)
->status('status', Subtask::STATUS_INPROGRESS)
->join(SubtaskTimeTracking::TABLE, 'subtask_id', 'id')
->findOne();
if ($subtask && $subtask['time_estimated'] && $subtask['start']) {
return date('Y-m-d H:i', $subtask['start'] + $subtask['time_estimated'] * 3600);
}
return date('Y-m-d H:i');
}
/**
* Get all calendar events according to the user timetable and the subtasks estimates
*
* @access public
* @param integer $user_id
* @param string $end End date of the calendar
* @return array
*/
public function getCalendarEvents($user_id, $end)
{
$events = array();
$start_date = new DateTime($this->getStartDate($user_id));
$timetable = $this->timetable->calculate($user_id, $start_date, new DateTime($end));
$subtasks = $this->getSubtasks($user_id);
$total = count($subtasks);
$offset = 0;
foreach ($timetable as $slot) {
$interval = $this->dateParser->getHours($slot[0], $slot[1]);
$start = $slot[0]->getTimestamp();
if ($slot[0] < $start_date) {
continue;
}
while ($offset < $total) {
$event = array(
'id' => $subtasks[$offset]['id'].'-'.$subtasks[$offset]['task_id'].'-'.$offset,
'subtask_id' => $subtasks[$offset]['id'],
'title' => t('#%d', $subtasks[$offset]['task_id']).' '.$subtasks[$offset]['title'],
'url' => $this->helper->url('task', 'show', array('task_id' => $subtasks[$offset]['task_id'], 'project_id' => $subtasks[$offset]['project_id'])),
'editable' => false,
'start' => date('Y-m-d\TH:i:s', $start),
);
if ($subtasks[$offset]['time_estimated'] <= $interval) {
$start += $subtasks[$offset]['time_estimated'] * 3600;
$interval -= $subtasks[$offset]['time_estimated'];
$offset++;
$event['end'] = date('Y-m-d\TH:i:s', $start);
$events[] = $event;
}
else {
$subtasks[$offset]['time_estimated'] -= $interval;
$event['end'] = $slot[1]->format('Y-m-d\TH:i:s');
$events[] = $event;
break;
}
}
}
return $events;
}
}

View File

@ -6,7 +6,13 @@ use PDO;
use Core\Security;
use Model\Link;
const VERSION = 54;
const VERSION = 55;
function version_55($pdo)
{
$rq = $pdo->prepare('INSERT INTO settings VALUES (?, ?)');
$rq->execute(array('subtask_forecast', '0'));
}
function version_54($pdo)
{

View File

@ -6,7 +6,13 @@ use PDO;
use Core\Security;
use Model\Link;
const VERSION = 35;
const VERSION = 36;
function version_36($pdo)
{
$rq = $pdo->prepare('INSERT INTO settings VALUES (?, ?)');
$rq->execute(array('subtask_forecast', '0'));
}
function version_35($pdo)
{

View File

@ -6,7 +6,13 @@ use Core\Security;
use PDO;
use Model\Link;
const VERSION = 53;
const VERSION = 54;
function version_54($pdo)
{
$rq = $pdo->prepare('INSERT INTO settings VALUES (?, ?)');
$rq->execute(array('subtask_forecast', '0'));
}
function version_53($pdo)
{

View File

@ -36,6 +36,7 @@ class ClassProvider implements ServiceProviderInterface
'ProjectPermission',
'Subtask',
'SubtaskExport',
'SubtaskForecast',
'SubtaskTimeTracking',
'Swimlane',
'Task',

View File

@ -28,6 +28,7 @@
<?= $this->formCheckbox('subtask_restriction', t('Allow only one subtask in progress at the same time for a user'), 1, $values['subtask_restriction'] == 1) ?>
<?= $this->formCheckbox('subtask_time_tracking', t('Enable time tracking for subtasks'), 1, $values['subtask_time_tracking'] == 1) ?>
<?= $this->formCheckbox('subtask_forecast', t('Show subtask estimates in the user calendar'), 1, $values['subtask_forecast'] == 1) ?>
<div class="form-actions">
<input type="submit" value="<?= t('Save') ?>" class="btn btn-blue"/>