From 2491ada0db7a3ca7832260a9bc263bc24be300a0 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sun, 15 Feb 2015 16:34:56 -0500 Subject: Display subtask time tracking in the calendar --- app/Controller/Calendar.php | 60 ++++++++------- app/Model/Acl.php | 2 +- app/Model/SubtaskTimeTracking.php | 127 ++++++++++++++++++++++++++++++-- app/Template/calendar/show.php | 2 +- assets/js/app.js | 24 +++--- assets/js/src/base.js | 4 +- assets/js/src/calendar.js | 23 +++--- tests/units/SubtaskTimeTrackingTest.php | 70 +++++++++++++++++- 8 files changed, 250 insertions(+), 62 deletions(-) diff --git a/app/Controller/Calendar.php b/app/Controller/Calendar.php index 0e749558..1c7ac7c0 100644 --- a/app/Controller/Calendar.php +++ b/app/Controller/Calendar.php @@ -41,24 +41,27 @@ class Calendar extends Base * * @access public */ - public function events() + public function project() { - $this->response->json( - $this->taskFilter - ->create() - ->filterByProject($this->request->getIntegerParam('project_id')) - ->filterByCategory($this->request->getIntegerParam('category_id', -1)) - ->filterByOwner($this->request->getIntegerParam('owner_id', -1)) - ->filterByColumn($this->request->getIntegerParam('column_id', -1)) - ->filterBySwimlane($this->request->getIntegerParam('swimlane_id', -1)) - ->filterByColor($this->request->getStringParam('color_id')) - ->filterByStatus($this->request->getIntegerParam('is_active', -1)) - ->filterByDueDateRange( - $this->request->getStringParam('start'), - $this->request->getStringParam('end') - ) - ->toCalendarEvents() - ); + $project_id = $this->request->getIntegerParam('project_id'); + $start = $this->request->getStringParam('start'); + $end = $this->request->getStringParam('end'); + + $due_tasks = $this->taskFilter + ->create() + ->filterByProject($project_id) + ->filterByCategory($this->request->getIntegerParam('category_id', -1)) + ->filterByOwner($this->request->getIntegerParam('owner_id', -1)) + ->filterByColumn($this->request->getIntegerParam('column_id', -1)) + ->filterBySwimlane($this->request->getIntegerParam('swimlane_id', -1)) + ->filterByColor($this->request->getStringParam('color_id')) + ->filterByStatus($this->request->getIntegerParam('is_active', -1)) + ->filterByDueDateRange($start, $end) + ->toCalendarEvents(); + + $subtask_timeslots = $this->subtaskTimeTracking->getProjectCalendarEvents($project_id, $start, $end); + + $this->response->json(array_merge($due_tasks, $subtask_timeslots)); } /** @@ -69,18 +72,19 @@ class Calendar extends Base public function user() { $user_id = $this->request->getIntegerParam('user_id'); + $start = $this->request->getStringParam('start'); + $end = $this->request->getStringParam('end'); + + $due_tasks = $this->taskFilter + ->create() + ->filterByOwner($user_id) + ->filterByStatus(TaskModel::STATUS_OPEN) + ->filterByDueDateRange($start, $end) + ->toCalendarEvents(); + + $subtask_timeslots = $this->subtaskTimeTracking->getUserCalendarEvents($user_id, $start, $end); - $this->response->json( - $this->taskFilter - ->create() - ->filterByOwner($user_id) - ->filterByStatus(TaskModel::STATUS_OPEN) - ->filterByDueDateRange( - $this->request->getStringParam('start'), - $this->request->getStringParam('end') - ) - ->toCalendarEvents() - ); + $this->response->json(array_merge($due_tasks, $subtask_timeslots)); } /** diff --git a/app/Model/Acl.php b/app/Model/Acl.php index e713f2e1..4d4a22a7 100644 --- a/app/Model/Acl.php +++ b/app/Model/Acl.php @@ -39,7 +39,7 @@ class Acl extends Base 'subtask' => '*', 'task' => '*', 'tasklink' => '*', - 'calendar' => array('show', 'events', 'save'), + 'calendar' => array('show', 'project', 'save'), ); /** diff --git a/app/Model/SubtaskTimeTracking.php b/app/Model/SubtaskTimeTracking.php index 8093cf80..abd8c8fc 100644 --- a/app/Model/SubtaskTimeTracking.php +++ b/app/Model/SubtaskTimeTracking.php @@ -21,7 +21,7 @@ class SubtaskTimeTracking extends Base * Get query for user timesheet (pagination) * * @access public - * @param integer $user_id User id + * @param integer $user_id User id * @return \PicoDb\Table */ public function getUserQuery($user_id) @@ -36,7 +36,8 @@ class SubtaskTimeTracking extends Base Subtask::TABLE.'.task_id', Subtask::TABLE.'.title AS subtask_title', Task::TABLE.'.title AS task_title', - Task::TABLE.'.project_id' + Task::TABLE.'.project_id', + Task::TABLE.'.color_id' ) ->join(Subtask::TABLE, 'id', 'subtask_id') ->join(Task::TABLE, 'id', 'task_id', Subtask::TABLE) @@ -44,10 +45,10 @@ class SubtaskTimeTracking extends Base } /** - * Get query for task (pagination) + * Get query for task timesheet (pagination) * * @access public - * @param integer $task_id Task id + * @param integer $task_id Task id * @return \PicoDb\Table */ public function getTaskQuery($task_id) @@ -72,6 +73,36 @@ class SubtaskTimeTracking extends Base ->eq(Task::TABLE.'.id', $task_id); } + /** + * Get query for project timesheet (pagination) + * + * @access public + * @param integer $project_id Project id + * @return \PicoDb\Table + */ + public function getProjectQuery($project_id) + { + return $this->db + ->table(self::TABLE) + ->columns( + self::TABLE.'.id', + self::TABLE.'.subtask_id', + self::TABLE.'.end', + self::TABLE.'.start', + self::TABLE.'.user_id', + Subtask::TABLE.'.task_id', + Subtask::TABLE.'.title AS subtask_title', + Task::TABLE.'.project_id', + Task::TABLE.'.color_id', + User::TABLE.'.username', + User::TABLE.'.name AS user_fullname' + ) + ->join(Subtask::TABLE, 'id', 'subtask_id') + ->join(Task::TABLE, 'id', 'task_id', Subtask::TABLE) + ->join(User::TABLE, 'id', 'user_id', self::TABLE) + ->eq(Task::TABLE.'.project_id', $project_id); + } + /** * Get all recorded time slots for a given user * @@ -87,6 +118,92 @@ class SubtaskTimeTracking extends Base ->findAll(); } + /** + * Get user calendar events + * + * @access public + * @param integer $user_id + * @param integer $start + * @param integer $end + * @return array + */ + public function getUserCalendarEvents($user_id, $start, $end) + { + $result = $this->getUserQuery($user_id) + ->addCondition($this->getCalendarCondition($start, $end)) + ->findAll(); + + return $this->toCalendarEvents($result); + } + + /** + * Get project calendar events + * + * @access public + * @param integer $project_id + * @param integer $start + * @param integer $end + * @return array + */ + public function getProjectCalendarEvents($project_id, $start, $end) + { + $result = $this->getProjectQuery($project_id) + ->addCondition($this->getCalendarCondition($start, $end)) + ->findAll(); + + return $this->toCalendarEvents($result); + } + + /** + * Get time slots that should be displayed in the calendar time range + * + * @access private + * @param string $start ISO8601 start date + * @param string $end ISO8601 end date + * @return string + */ + private function getCalendarCondition($start, $end) + { + $start_time = $this->dateParser->getTimestampFromIsoFormat($start); + $end_time = $this->dateParser->getTimestampFromIsoFormat($end); + $start_column = $this->db->escapeIdentifier('start'); + $end_column = $this->db->escapeIdentifier('end'); + + return "(($start_column >= '$start_time' AND $start_column <= '$end_time') OR ($start_column <= '$start_time' AND $end_column >= '$start_time'))"; + } + + /** + * Convert a record set to calendar events + * + * @access private + * @param array $rows + * @return array + */ + private function toCalendarEvents(array $rows) + { + $events = array(); + + foreach ($rows as $row) { + + $user = isset($row['username']) ? ' ('.($row['user_fullname'] ?: $row['username']).')' : ''; + + $events[] = array( + 'id' => $row['id'], + 'subtask_id' => $row['subtask_id'], + 'title' => t('#%d', $row['task_id']).' '.$row['subtask_title'].$user, + 'start' => date('Y-m-d\TH:i:s', $row['start']), + 'end' => date('Y-m-d\TH:i:s', $row['end'] ?: time()), + 'backgroundColor' => $this->color->getBackgroundColor($row['color_id']), + 'borderColor' => $this->color->getBorderColor($row['color_id']), + 'textColor' => 'black', + 'url' => $this->helper->url('task', 'show', array('task_id' => $row['task_id'], 'project_id' => $row['project_id'])), + 'editable' => false, + ); + } + + return $events; + } + /** * Log start time * @@ -133,7 +250,7 @@ class SubtaskTimeTracking extends Base */ public function updateTaskTimeTracking($task_id) { - $result = $this->calculateSubtaskTime($task_id); + $result = $this->calculateSubtaskTime($task_id); if (empty($result['total_spent']) && empty($result['total_estimated'])) { return true; diff --git a/app/Template/calendar/show.php b/app/Template/calendar/show.php index b258e391..cb5a1109 100644 --- a/app/Template/calendar/show.php +++ b/app/Template/calendar/show.php @@ -35,7 +35,7 @@
diff --git a/assets/js/app.js b/assets/js/app.js index 9589b00d..103c875c 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -138,24 +138,24 @@ b[c[e].seq]=1,x(c[e].callback,d,c[e].combo,c[e].seq)):g||x(c[e].callback,d,c[e]. var Kanboard=function(){jQuery(document).ready(function(){Kanboard.Init()});return{Exists:function(a){return document.getElementById(a)?!0:!1},Popover:function(a,c){a.preventDefault();a.stopPropagation();var b=a.target.getAttribute("href");b||(b=a.target.getAttribute("data-href"));b&&Kanboard.OpenPopover(b,c)},OpenPopover:function(a,c){$.get(a,function(a){$("body").append('
'+a+"
");$("#popover-container").click(function(){$(this).remove()}); $("#popover-content").click(function(a){a.stopPropagation()});$(".close-popover").click(function(a){a.preventDefault();$("#popover-container").remove()});Mousetrap.bind("esc",function(){$("#popover-container").remove()});c&&c()})},IsVisible:function(){var a="";"undefined"!==typeof document.hidden?a="visibilityState":"undefined"!==typeof document.mozHidden?a="mozVisibilityState":"undefined"!==typeof document.msHidden?a="msVisibilityState":"undefined"!==typeof document.webkitHidden&&(a="webkitVisibilityState"); return""!=a?"visible"==document[a]:!0},SetStorageItem:function(a,c){"undefined"!==typeof Storage&&localStorage.setItem(a,c)},GetStorageItem:function(a){return"undefined"!==typeof Storage?localStorage.getItem(a):""},MarkdownPreview:function(a){a.preventDefault();var c=$(this),b=$(this).closest("ul"),d=$(".write-area"),e=$(".preview-area"),f=$("textarea");$.ajax({url:"?controller=app&action=preview",contentType:"application/json",type:"POST",processData:!1,dataType:"html",data:JSON.stringify({text:f.val()})}).done(function(a){b.find("li").removeClass("form-tab-selected"); -c.parent().addClass("form-tab-selected");e.find(".markdown").html(a);e.css("height",f.css("height"));e.css("width",f.css("width"));d.hide();e.show()})},MarkdownWriter:function(a){a.preventDefault();$(this).closest("ul").find("li").removeClass("form-tab-selected");$(this).parent().addClass("form-tab-selected");$(".write-area").show();$(".preview-area").hide()},CheckSession:function(){$(".form-login").length||$.ajax({cache:!1,url:$("body").data("status-url"),statusCode:{401:function(a){window.location= +c.parent().addClass("form-tab-selected");e.find(".markdown").html(a);e.css("height",f.css("height"));e.css("width",f.css("width"));d.hide();e.show()})},MarkdownWriter:function(a){a.preventDefault();$(this).closest("ul").find("li").removeClass("form-tab-selected");$(this).parent().addClass("form-tab-selected");$(".write-area").show();$(".preview-area").hide()},CheckSession:function(){$(".form-login").length||$.ajax({cache:!1,url:$("body").data("status-url"),statusCode:{401:function(){window.location= $("body").data("login-url")}}})},Init:function(){$("#board-selector").chosen({width:180});$("#board-selector").change(function(){window.location=$(this).attr("data-board-url").replace(/PROJECT_ID/g,$(this).val())});window.setInterval(Kanboard.CheckSession,6E4);$(".popover-subtask-restriction").click(Kanboard.Popover);$(".file-popover").click(Kanboard.Popover);Mousetrap.bind("mod+enter",function(){$("form").submit()});Mousetrap.bind("b",function(a){a.preventDefault();$("#board-selector").trigger("chosen:open")}); -$(".column-tooltip").tooltip({content:function(a){return'
'+$(this).attr("title")+"
"}});$.datepicker.setDefaults($.datepicker.regional[$("body").data("js-lang")]);Kanboard.InitAfterAjax()},InitAfterAjax:function(){$(".form-date").datepicker({showOtherMonths:!0,selectOtherMonths:!0,dateFormat:"yy-mm-dd",constrainInput:!1});$("#markdown-preview").click(Kanboard.MarkdownPreview);$("#markdown-write").click(Kanboard.MarkdownWriter);$(".auto-select").focus(function(){$(this).select()}); +$(".column-tooltip").tooltip({content:function(){return'
'+$(this).attr("title")+"
"}});$.datepicker.setDefaults($.datepicker.regional[$("body").data("js-lang")]);Kanboard.InitAfterAjax()},InitAfterAjax:function(){$(".form-date").datepicker({showOtherMonths:!0,selectOtherMonths:!0,dateFormat:"yy-mm-dd",constrainInput:!1});$("#markdown-preview").click(Kanboard.MarkdownPreview);$("#markdown-write").click(Kanboard.MarkdownWriter);$(".auto-select").focus(function(){$(this).select()}); $(".dropit-submenu").hide();$(".dropdown").not(".dropit").dropit()}}}(); Kanboard.Board=function(){function a(a){Kanboard.Popover(a,Kanboard.InitAfterAjax)}function c(){Mousetrap.bind("n",function(){Kanboard.OpenPopover($(".task-creation-popover").attr("href"),Kanboard.InitAfterAjax)});Mousetrap.bind("s",function(){"expanded"===(Kanboard.GetStorageItem(d())||"expanded")?(e(),Kanboard.SetStorageItem(d(),"collapsed")):(f(),Kanboard.SetStorageItem(d(),"expanded"))})}function b(){$(".filter-expand-link").click(function(a){a.preventDefault();f();Kanboard.SetStorageItem(d(), -"expanded")});$(".filter-collapse-link").click(function(a){a.preventDefault();e();Kanboard.SetStorageItem(d(),"collapsed")});k()}function d(){return"board_stacking_"+$("#board").data("project-id")}function e(){$(".filter-collapse").hide();$(".task-board-collapsed").show();$(".filter-expand").show();$(".task-board-expanded").hide()}function f(){$(".filter-collapse").show();$(".task-board-collapsed").hide();$(".filter-expand").hide();$(".task-board-expanded").show()}function k(){"expanded"===(Kanboard.GetStorageItem(d())|| -"expanded")?f():e()}function g(){$(".column").sortable({delay:300,distance:5,connectWith:".column",placeholder:"draggable-placeholder",stop:function(a,b){n(b.item.attr("data-task-id"),b.item.parent().attr("data-column-id"),b.item.index()+1,b.item.parent().attr("data-swimlane-id"))}});$(".assignee-popover").click(a);$(".category-popover").click(a);$(".task-edit-popover").click(a);$(".task-creation-popover").click(a);$(".task-description-popover").click(a);$(".task-board-tooltip").tooltip({track:!1, +"expanded")});$(".filter-collapse-link").click(function(a){a.preventDefault();e();Kanboard.SetStorageItem(d(),"collapsed")});h()}function d(){return"board_stacking_"+$("#board").data("project-id")}function e(){$(".filter-collapse").hide();$(".task-board-collapsed").show();$(".filter-expand").show();$(".task-board-expanded").hide()}function f(){$(".filter-collapse").show();$(".task-board-collapsed").hide();$(".filter-expand").hide();$(".task-board-expanded").show()}function h(){"expanded"===(Kanboard.GetStorageItem(d())|| +"expanded")?f():e()}function k(){$(".column").sortable({delay:300,distance:5,connectWith:".column",placeholder:"draggable-placeholder",stop:function(a,b){n(b.item.attr("data-task-id"),b.item.parent().attr("data-column-id"),b.item.index()+1,b.item.parent().attr("data-swimlane-id"))}});$(".assignee-popover").click(a);$(".category-popover").click(a);$(".task-edit-popover").click(a);$(".task-creation-popover").click(a);$(".task-description-popover").click(a);$(".task-board-tooltip").tooltip({track:!1, position:{my:"left-20 top",at:"center bottom+9",using:function(a,b){$(this).css(a);var c=b.target.left+b.target.width/2-b.element.left-20;$("
").addClass("tooltip-arrow").addClass(b.vertical).addClass(0==c?"align-left":"align-right").appendTo(this)}},content:function(a){if(a=$(this).attr("data-href")){var b=this;$.get(a,function p(a){$(".ui-tooltip-content:visible").html(a);a=$(".ui-tooltip:visible");a.css({top:"",left:""});a.children(".tooltip-arrow").remove();var c=$(b).tooltip("option","position"); c.of=$(b);a.position(c);$("#tooltip-subtasks a").click(function(a){a.preventDefault();a.stopPropagation();$(this).hasClass("popover-subtask-restriction")?(Kanboard.OpenPopover($(this).attr("href")),$(b).tooltip("close")):$.get($(this).attr("href"),p)})});return''}}}).on("mouseenter",function(){var a=this;$(this).tooltip("open");$(".ui-tooltip").on("mouseleave",function(){$(a).tooltip("close")})}).on("mouseleave focusout",function(a){a.stopImmediatePropagation(); var b=this;setTimeout(function(){$(".ui-tooltip:hover").length||$(b).tooltip("close")},100)});$("[data-task-url]").each(function(){$(this).click(function(){window.location=$(this).attr("data-task-url")})});var b=parseInt($("#board").attr("data-check-interval"));0' + $(this).attr("title") + '
'; } }); diff --git a/assets/js/src/calendar.js b/assets/js/src/calendar.js index 2f731693..d9bc9a97 100644 --- a/assets/js/src/calendar.js +++ b/assets/js/src/calendar.js @@ -4,7 +4,7 @@ Kanboard.Calendar = (function() { // Save the new due date for a moved task function move_calendar_event(calendar_event) - { + { $.ajax({ cache: false, url: $("#calendar").data("save-url"), @@ -22,12 +22,12 @@ Kanboard.Calendar = (function() { function show_user_calendar() { var calendar = $("#user-calendar"); - var translations = calendar.data("translations"); calendar.fullCalendar({ lang: $("body").data("js-lang"), editable: false, eventLimit: true, + height: Kanboard.Exists("dashboard-calendar") ? 500 : "auto", defaultView: "agendaWeek", header: { left: 'prev,next today', @@ -39,7 +39,7 @@ Kanboard.Calendar = (function() { } // Refresh the calendar events - function refresh_user_calendar(filters) + function refresh_user_calendar() { var calendar = $("#user-calendar"); var url = calendar.data("check-url"); @@ -47,7 +47,7 @@ Kanboard.Calendar = (function() { "start": calendar.fullCalendar('getView').start.format(), "end": calendar.fullCalendar('getView').end.format(), "user_id": calendar.data("user-id") - } + }; for (var key in params) { url += "&" + key + "=" + params[key]; @@ -55,7 +55,7 @@ Kanboard.Calendar = (function() { $.getJSON(url, function(events) { calendar.fullCalendar('removeEvents'); - calendar.fullCalendar('addEventSource', events); + calendar.fullCalendar('addEventSource', events); calendar.fullCalendar('rerenderEvents'); }); } @@ -64,13 +64,12 @@ Kanboard.Calendar = (function() { function show_project_calendar() { var calendar = $("#calendar"); - var translations = calendar.data("translations"); calendar.fullCalendar({ lang: $("body").data("js-lang"), editable: true, eventLimit: true, - defaultView: "agendaWeek", + defaultView: "month", header: { left: 'prev,next today', center: 'title', @@ -89,7 +88,7 @@ Kanboard.Calendar = (function() { var params = { "start": calendar.fullCalendar('getView').start.format(), "end": calendar.fullCalendar('getView').end.format() - } + }; jQuery.extend(params, filters); @@ -99,7 +98,7 @@ Kanboard.Calendar = (function() { $.getJSON(url, function(events) { calendar.fullCalendar('removeEvents'); - calendar.fullCalendar('addEventSource', events); + calendar.fullCalendar('addEventSource', events); calendar.fullCalendar('rerenderEvents'); }); } @@ -108,7 +107,7 @@ Kanboard.Calendar = (function() { function load_project_filters() { var filters = Kanboard.GetStorageItem(filter_storage_key); - + if (filters !== "") { filters = JSON.parse(filters); @@ -127,10 +126,10 @@ Kanboard.Calendar = (function() { { var filters = {}; - $('.calendar-filter').each(function(index, element) { + $('.calendar-filter').each(function() { filters[$(this).attr("name")] = $(this).val(); }); - + Kanboard.SetStorageItem(filter_storage_key, JSON.stringify(filters)); refresh_project_calendar(filters); } diff --git a/tests/units/SubtaskTimeTrackingTest.php b/tests/units/SubtaskTimeTrackingTest.php index a68d8ee1..e8e0b5d6 100644 --- a/tests/units/SubtaskTimeTrackingTest.php +++ b/tests/units/SubtaskTimeTrackingTest.php @@ -135,7 +135,7 @@ class SubtaskTimeTrackingTest extends Base $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1))); $this->assertEquals(2, $tc->create(array('title' => 'test 2', 'project_id' => 1, 'time_estimated' => 1.5, 'time_spent' => 0.5))); - $this->assertEquals(1, $s->create(array('title' => 'subtask #2', 'task_id' => 1, 'time_spent' => 2.2))); + $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1, 'time_spent' => 2.2))); $this->assertEquals(2, $s->create(array('title' => 'subtask #2', 'task_id' => 1, 'time_estimated' => 1))); $st->updateTaskTimeTracking(1); @@ -151,4 +151,72 @@ class SubtaskTimeTrackingTest extends Base $this->assertEquals(0.5, $task['time_spent'], 'Total spent', 0.01); $this->assertEquals(1.5, $task['time_estimated'], 'Total estimated', 0.01); } + + public function testGetCalendarEvents() + { + $tf = new TaskFinder($this->container); + $tc = new TaskCreation($this->container); + $s = new Subtask($this->container); + $st = new SubtaskTimeTracking($this->container); + $p = new Project($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test1'))); + $this->assertEquals(2, $p->create(array('name' => 'test2'))); + + $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1))); + $this->assertEquals(2, $tc->create(array('title' => 'test 1', 'project_id' => 2))); + + $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1))); + $this->assertEquals(2, $s->create(array('title' => 'subtask #2', 'task_id' => 1))); + $this->assertEquals(3, $s->create(array('title' => 'subtask #3', 'task_id' => 1))); + + $this->assertEquals(4, $s->create(array('title' => 'subtask #4', 'task_id' => 2))); + $this->assertEquals(5, $s->create(array('title' => 'subtask #5', 'task_id' => 2))); + $this->assertEquals(6, $s->create(array('title' => 'subtask #6', 'task_id' => 2))); + + // Create a couple of time slots + $now = time(); + + // Slot start before and finish inside the calendar time range + $this->container['db']->table(SubtaskTimeTracking::TABLE)->insert(array('user_id' => 1, 'subtask_id' => 1, 'start' => $now - 86400, 'end' => $now + 3600)); + + // Slot start inside time range and finish after the time range + $this->container['db']->table(SubtaskTimeTracking::TABLE)->insert(array('user_id' => 1, 'subtask_id' => 2, 'start' => $now + 3600, 'end' => $now + 2*86400)); + + // Start before time range and finish inside time range + $this->container['db']->table(SubtaskTimeTracking::TABLE)->insert(array('user_id' => 1, 'subtask_id' => 3, 'start' => $now - 86400, 'end' => $now + 1.5*86400)); + + // Start and finish inside time range + $this->container['db']->table(SubtaskTimeTracking::TABLE)->insert(array('user_id' => 1, 'subtask_id' => 4, 'start' => $now + 3600, 'end' => $now + 2*3600)); + + // Start and finish after the time range + $this->container['db']->table(SubtaskTimeTracking::TABLE)->insert(array('user_id' => 1, 'subtask_id' => 5, 'start' => $now + 2*86400, 'end' => $now + 3*86400)); + + // Start and finish before the time range + $this->container['db']->table(SubtaskTimeTracking::TABLE)->insert(array('user_id' => 1, 'subtask_id' => 6, 'start' => $now - 2*86400, 'end' => $now - 86400)); + + $timesheet = $st->getUserTimesheet(1); + $this->assertNotEmpty($timesheet); + $this->assertCount(6, $timesheet); + + $events = $st->getUserCalendarEvents(1, date('Y-m-d', $now), date('Y-m-d', $now + 86400)); + $this->assertNotEmpty($events); + $this->assertCount(4, $events); + $this->assertEquals(1, $events[0]['subtask_id']); + $this->assertEquals(2, $events[1]['subtask_id']); + $this->assertEquals(3, $events[2]['subtask_id']); + $this->assertEquals(4, $events[3]['subtask_id']); + + $events = $st->getProjectCalendarEvents(1, date('Y-m-d', $now), date('Y-m-d', $now + 86400)); + $this->assertNotEmpty($events); + $this->assertCount(3, $events); + $this->assertEquals(1, $events[0]['subtask_id']); + $this->assertEquals(2, $events[1]['subtask_id']); + $this->assertEquals(3, $events[2]['subtask_id']); + + $events = $st->getProjectCalendarEvents(2, date('Y-m-d', $now), date('Y-m-d', $now + 86400)); + $this->assertNotEmpty($events); + $this->assertCount(1, $events); + $this->assertEquals(4, $events[0]['subtask_id']); + } } -- cgit v1.2.3