Skip to content

Commit

Permalink
Fix indentation of search results.
Browse files Browse the repository at this point in the history
Parent/Child relationship correctly shown now. Tasks whose parents
do not match the search will be shown as root-level.
  • Loading branch information
mrubinsk committed Oct 19, 2015
1 parent 5c92355 commit a6668c6
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions nag/lib/Search.php
Expand Up @@ -165,6 +165,9 @@ protected function _search($page, $perpage)
}
$tasks->reset();
while ($task = $tasks->each()) {
// Need to empty the children since they might not be in the results
$task = clone $task;
$task->orphan();
if (!empty($date)) {
if (empty($task->due) || $task->due > $date) {
continue;
Expand All @@ -186,10 +189,28 @@ protected function _search($page, $perpage)
}
}

// Now that we have filtered results, load all tags at once.
$search_results->loadTags();
// Now try to maintain parent/child relationships when they are both
// in the result set.
$search_results->reset();
$search_results_copy = clone $search_results;
$processed_results = new Nag_Task();

return $search_results;
while ($result = $search_results_copy->each()) {
if ($result->parent_id &&
($parent_task = $search_results->hasTask($result->parent_id))) {
$parent_task->add($result, true);
$processed_results->add($parent_task, true);
} else {
$result->parent_id = '';
$processed_results->add($result);
}
}

// Now that we have filtered results, load all tags at once.
$processed_results->loadTags();
$processed_results->process();

return $processed_results;
}

/**
Expand Down

0 comments on commit a6668c6

Please sign in to comment.