From b6c6b80ee512dc95086b292aa784eddeb0e5c045 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raimund=20Schl=C3=BC=C3=9Fler?= Date: Sat, 7 Feb 2015 16:55:01 +0100 Subject: [PATCH] Sort results by completed --- controller/searchcontroller.php | 10 ++++++++++ controller/task.php | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/controller/searchcontroller.php b/controller/searchcontroller.php index 50b95740..1ad4c30f 100644 --- a/controller/searchcontroller.php +++ b/controller/searchcontroller.php @@ -73,6 +73,16 @@ class SearchController extends \OCP\Search\Provider { } } } + usort($results, array($this, 'sort_completed')); return $results; } + + private static function sort_completed($a, $b){ + $t1 = $a->completed; + $t2 = $b->completed; + if ($t1 == $t2) { + return 0; + } + return $t1 > $t2 ? 1 : -1; + } } diff --git a/controller/task.php b/controller/task.php index ec0fab09..b368d7c3 100644 --- a/controller/task.php +++ b/controller/task.php @@ -39,6 +39,13 @@ class Task extends \OCP\Search\Result { */ public $calendarID; + /** + * Is Task completed + * + * @var string + */ + public $completed; + /** * Used by the client JS to display additional information under the event summary * @@ -71,6 +78,7 @@ class Task extends \OCP\Search\Result { $this->id = $taskId; $this->calendarID = $calendarId; $this->name = $vtodo->getAsString('SUMMARY'); + $this->completed = $vtodo->COMPLETED ? true : false; $this->link = \OCP\Util::linkToRoute('tasks.page.index') . '#/lists/' . $calendarId . '/tasks/' . $taskId; $l = new \OC_l10n('tasks'); switch($reason){