Plugin: Dashboard task default sorting change

Hey there,

after having a problem and then after some time digging into plugin stuff for Kanboard with some help, I finally came up with something maybe usful for me. Maybe it’s useful for others as well:

This is a simple plugin (without configuration yet), which makes the default sorting for tasks on the dashboard overview and tasks site sort by Due date DESC by default.

One main thing I still try to figure out is how to make tasks without due date appear still on the bottom of the list. I managed something like this with another huge project of mine, yet it used Doctrine … and Kanboard uses PicoDB, which is totally new to me. So in case somebody might be able to help here: you are welcome! :smiley:

Have fun with this little (first) plugin of mine.

2 Likes

take the query, split those without a due date out, perform your sort, merge back.

This sounds too easy. Still struggling with understanding PicoDB and how it is implemented into Kanboard. :smiley:

… if you would know more details already, I would appreciate your help. For example I am looking at this passage at the moment:

$query = $this->taskFinderModel->getUserQuery($userId);
$this->hook->reference('pagination:dashboard:task:query', $query);

return $this->paginator
    ->setUrl('DashboardController', $method, array('pagination' => 'tasks', 'user_id' => $userId))
    ->setMax($max)
    ->setOrder(TaskModel::TABLE.'.date_due')
    ->setQuery($query)
    ->setFormatter($this->taskListFormatter)
    ->calculateOnlyIf($this->request->getStringParam('pagination') === 'tasks');

And there I think about playing around by either changing the $query… e.g. with $query->asc(... or so. Or by adding additional method on the return variable.

Is this at least a good way or don’t you know either?



Edit: By the way: I try to come up with a solution so that the sorter in the frontend will still work after all!

Well, I got it. For the pagination stuff only, though. Means: for the dashboard overview and tasks view.

Next step would be to have this sorting for the projects task list as well (the one right next to the board button). Unfortunately it did not seem to work to come up with a similar solution like $this->container['taskListController'] = ..., since the controllers either cannot be replaced, or it is done differently.

Uh oh … apparently I tested it locally with only SQLite, which worked so far. Online I have MariaDB / MySQL, though … error. )=

sorry, i dozed. when i said the query, i meant the first line. thats an array of tasks.
$query = $this->taskFinderModel->getUserQuery($userId); This is an array of tasks.

i would have simply removed all the empty due dates there, then run it through your sorting logic, then merged them back in, at the end of the array. so no matter your sort, they would always be at the bottom of your sort.

something like:

$tasks_with_due_date = array();
$tasks_without_due_date = array();

foreach ($query as $task) {
  if (empty($task['due_date'])) {
    $tasks_without_due_date[] = $task;
  } else {
    $tasks_with_due_date[] = $task;
  }
}

$tasks_with_due_date becomes your new $query that runs through your logic, and when done, merge the result back with $tasks_without_due_date, and return that result.

1 Like

add some screenshots :slight_smile:

i thought I explained this already. you cannot override a controller. you need to override the template that calls the controller, and have it call your new controller instead.

make sense?

1 Like

First of all: thanks for the new replies and big sorry for my late reply. I wanted to answer yesterday, but since I am a new user in this forum, there seem to be a posting cap. :smiley:

I should have posted the error message at least, sorry! I actually fixed the problem after all: MySQL does not allow CASE WHEN ... is 1 but CASE WHEN ... = 1. This seem to work now. I also updated my repo already.

Not sure if it’s the same, but I understood it this way that this is a PicoDB object. :thinking: …I might give this a try. Maybe my plugin could work more smooth this way then. Thanks for the example as well.

Oh sorry, mustr have forgotten this. Yes, this makes sense!


You guys here in this forum are so great, wow! Just thank you a lot. This makes it easier to dig into the plugin development. I am very grateful for that. (=