Calculate intersection between time tracking and timetable
This commit is contained in:
@@ -14,7 +14,7 @@ use Model\Task as TaskModel;
|
|||||||
class Calendar extends Base
|
class Calendar extends Base
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Show calendar view
|
* Show calendar view for projects
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
@@ -59,9 +59,7 @@ class Calendar extends Base
|
|||||||
->filterByDueDateRange($start, $end)
|
->filterByDueDateRange($start, $end)
|
||||||
->toCalendarEvents();
|
->toCalendarEvents();
|
||||||
|
|
||||||
$subtask_timeslots = $this->subtaskTimeTracking->getProjectCalendarEvents($project_id, $start, $end);
|
$this->response->json($due_tasks);
|
||||||
|
|
||||||
$this->response->json(array_merge($due_tasks, $subtask_timeslots));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -138,6 +138,8 @@ class SubtaskTimeTracking extends Base
|
|||||||
->addCondition($this->getCalendarCondition($start, $end))
|
->addCondition($this->getCalendarCondition($start, $end))
|
||||||
->findAll();
|
->findAll();
|
||||||
|
|
||||||
|
$result = $this->timetable->calculateEventsIntersect($user_id, $result, $start, $end);
|
||||||
|
|
||||||
return $this->toCalendarEvents($result);
|
return $this->toCalendarEvents($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,82 @@ class Timetable extends Base
|
|||||||
private $overtime;
|
private $overtime;
|
||||||
private $timeoff;
|
private $timeoff;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a set of events by using the intersection between the timetable and the time tracking data
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @param integer $user_id
|
||||||
|
* @param array $events Time tracking data
|
||||||
|
* @param string $start ISO8601 date
|
||||||
|
* @param string $end ISO8601 date
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function calculateEventsIntersect($user_id, array $events, $start, $end)
|
||||||
|
{
|
||||||
|
$start_dt = new DateTime($start);
|
||||||
|
$start_dt->setTime(0, 0);
|
||||||
|
|
||||||
|
$end_dt = new DateTime($end);
|
||||||
|
$end_dt->setTime(23, 59);
|
||||||
|
|
||||||
|
$timetable = $this->calculate($user_id, $start_dt, $end_dt);
|
||||||
|
|
||||||
|
// The user has no timetable
|
||||||
|
if (empty($this->week)) {
|
||||||
|
return $events;
|
||||||
|
}
|
||||||
|
|
||||||
|
$results = array();
|
||||||
|
|
||||||
|
foreach ($events as $event) {
|
||||||
|
$results = array_merge($results, $this->calculateEventIntersect($event, $timetable));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $results;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a serie of events based on the timetable and the provided event
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @param integer $user_id
|
||||||
|
* @param array $events Time tracking data
|
||||||
|
* @param string $start ISO8601 date
|
||||||
|
* @param string $end ISO8601 date
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function calculateEventIntersect(array $event, array $timetable)
|
||||||
|
{
|
||||||
|
$events = array();
|
||||||
|
|
||||||
|
foreach ($timetable as $slot) {
|
||||||
|
|
||||||
|
$start_ts = $slot[0]->getTimestamp();
|
||||||
|
$end_ts = $slot[1]->getTimestamp();
|
||||||
|
|
||||||
|
if ($start_ts > $event['end']) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($event['start'] <= $start_ts) {
|
||||||
|
$event['start'] = $start_ts;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($event['start'] >= $start_ts && $event['start'] <= $end_ts) {
|
||||||
|
|
||||||
|
if ($event['end'] >= $end_ts) {
|
||||||
|
$events[] = array_merge($event, array('end' => $end_ts));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$events[] = $event;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $events;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculate effective worked hours by taking into consideration the timetable
|
* Calculate effective worked hours by taking into consideration the timetable
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user