Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Hide columns on list tasks #164

Closed
wants to merge 11 commits into from
70 changes: 48 additions & 22 deletions system/modules/task/partials/actions/listtasks.php
Original file line number Diff line number Diff line change
@@ -1,30 +1,38 @@
<?php namespace System\Modules\Task;

function listtasks(\Web $w, $params = array()) {
function listtasks(\Web $w, $params = array())
{
$w->ctx("redirect", $params['redirect']);

$w->ctx("hide_filter", array_key_exists('hide_filter', $params) ? $params['hide_filter'] : false);

$w->ctx("hide_columns", array_key_exists('columns_to_hide', $params));
$w->ctx("columns_to_hide", array_key_exists('columns_to_hide', $params)? $params['columns_to_hide'] : []);

$taskgroup = null;
if (!empty($params['task_group_id'])) {
if (!empty($params['task_group_id']))
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are all the brackets of the if statements on new lines? This doesn't match our code standard... maybe the code sniffer is configured wrong?

$task_group_id = $params['task_group_id'];
$taskgroup = $w->Task->getTaskGroup($task_group_id);
}

if (!empty($params['task_status'])) {
if (!empty($params['task_status']))
{
$task_status = $params['task_status'];
}

// Look for reset
$reset = $w->request("filter_reset_task_list");
if (empty($reset)) {
if (empty($reset))
{
// Get filter values
$assignee_id = $w->request("assignee_id");
$creator_id = $w->request("creator_id");

if (empty($taskgroup)) {
if (empty($taskgroup))
{
$request_task_group_id = $w->request("task_group_id");
if (!empty($request_task_group_id)) {
if (!empty($request_task_group_id))
{
$task_group_id = $request_task_group_id;
}
}
Expand All @@ -33,7 +41,8 @@ function listtasks(\Web $w, $params = array()) {
$task_priority = $w->request('task_priority');

$request_task_status = $w->request('task_status');
if (!empty($request_task_status)) {
if (!empty($request_task_status))
{
$task_status = $request_task_status;
}

Expand All @@ -46,39 +55,50 @@ function listtasks(\Web $w, $params = array()) {
$query_object = $w->db->get("task")->leftJoin("task_group");

// We can now make ID queries directly to the task_group table because of left join
if (!empty($task_group_id)) {
if (!empty($task_group_id))
{
$query_object->where("task_group.id", $task_group_id);
}

// Repeat above for everything else
if (!empty($assignee_id)) {
if (!empty($assignee_id))
{
$query_object->where("task.assignee_id", $assignee_id);
}
if (!empty($creator_id)) {
if (!empty($creator_id))
{
// $query_object->where("task.creator_id", $creator_id);
}
if (!empty($task_type)) {
if (!empty($task_type))
{
$query_object->where("task.task_type", $task_type);
}
if (!empty($task_priority)) {
if (!empty($task_priority))
{
$query_object->where("task.priority", $task_priority);
}
if (!empty($task_status)) {
if (!empty($task_status))
{
$query_object->where("task.status", $task_status);
}
if (!empty($is_closed)) {
if (!empty($is_closed))
{
$query_object->where("task.is_closed", ((is_null($is_closed) || $is_closed == 0) ? 0 : 1));
} else {
}
else
{
$query_object->where("task.is_closed", 0);
}
//do not retrieve inactive tasks
$query_object->where("task.is_active", 1);

// This part is why we want to make our query manually
if (!empty($dt_from)) {
if (!empty($dt_from))
{
$query_object->where("task.dt_due >= ?", $dt_from);
}
if (!empty($dt_to)) {
if (!empty($dt_to))
{
$query_object->where("task_dt_due <= ?", $dt_to);
}

Expand All @@ -92,18 +112,24 @@ function listtasks(\Web $w, $params = array()) {

// Build the filter and its data
$taskgroup_data = null;
if (empty($taskgroup)) {
if (empty($taskgroup))
{
$taskgroup_data = $w->Task->getTaskGroupDetailsForUser();
} else {
}
else
{
$taskgroup_data = $w->Task->getTaskGroupDetailsForTaskGroup($task_group_id);
}
$filter_data = array();
$filter_data[] = array("Assignee", "select", "assignee_id", !empty($assignee_id) ? $assignee_id : null, $taskgroup_data["members"]);
$filter_data[] = array("Creator", "select", "creator_id", !empty($creator_id) ? $creator_id : null, $taskgroup_data["members"]);

if (empty($taskgroup)) {
if (empty($taskgroup))
{
$filter_data[] = array("Task Group", "select", "task_group_id", !empty($task_group_id) ? $task_group_id : null, $taskgroup_data["taskgroups"]);
} else {
}
else
{
$filter_data[] = array("Task Group", "static", "taskgroupname", $taskgroup->title);
$filter_data[] = array("", "hidden", "task_group_id", !empty($task_group_id) ? $task_group_id : null);
}
Expand Down
31 changes: 25 additions & 6 deletions system/modules/task/partials/templates/listtasks.tpl.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
<?php
echo (empty($hide_filter) || $hide_filter !== true) ? Html::filter("Filter Tasks", $filter_data, '/' . $redirect, "GET", "Filter", "task_list") : '';

if (!empty($tasks)) {
if (!empty($tasks))
{
$table_header = array("Title", "Created By", "Assigned To", "Group", "Type", "Priority", "Status", "Due");
$table_data = array();
if ($hide_columns)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per my comment above, this parameter is unnecessary because we can just check the existence of "columns_to_hide" to achieve the same effect.

{
if (is_array($columns_to_hide))
{
$columns_to_hide = array_combine($columns_to_hide, $columns_to_hide);
$table_header = array_diff_key($table_header, $columns_to_hide);
}
else
{
$hide_columns = false;
}
}

// Build table data
usort($tasks, array("TaskService", "sortTasksbyDue"));
foreach ($tasks as $task) {
if ($task->getCanIView()) {
foreach ($tasks as $task)
{
if ($task->getCanIView())
{
$table_line = array();
$table_line[] = Html::a("/task/edit/" . $task->id, $task->title);

Expand All @@ -23,12 +38,16 @@
$task->isTaskLate()
);

if ($hide_columns)
{
$table_line = array_diff_key($table_line, $columns_to_hide);
}
$table_data[] = $table_line;
}
}

echo Html::table($table_data, null, "tablesorter", $table_header);

} else { ?>
}
else
{ ?>
<h3><small>No tasks found.</small></h3>
<?php }