Skip to content

Commit

Permalink
MDL-55043 core_competency: Sort by id to ensure we get expected result.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rajesh Taneja committed Jul 10, 2016
1 parent 2648ddd commit 56c5c9a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion competency/classes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -4152,7 +4152,7 @@ public static function list_evidence($userid = 0, $competencyid = 0, $planid = 0
* @param int $limit Number of records to return.
* @return \core_competency\evidence[]
*/
public static function list_evidence_in_course($userid = 0, $courseid = 0, $competencyid = 0, $sort = 'timecreated, id',
public static function list_evidence_in_course($userid = 0, $courseid = 0, $competencyid = 0, $sort = 'timecreated',
$order = 'DESC', $skip = 0, $limit = 0) {
static::require_enabled();

Expand Down
8 changes: 3 additions & 5 deletions competency/classes/evidence.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,9 @@ public static function get_records_for_usercompetency($usercompetencyid,
);

if (!empty($sort)) {
$sortcolumns = explode(',', $sort);
array_walk($sortcolumns, function(&$sortcolumn, $key, $order) {
$sortcolumn = trim($sortcolumn) . ' ' . $order;
}, $order);
$sort = ' ORDER BY e.' . implode(', e.', $sortcolumns);
$sort = ' ORDER BY e.' . $sort . ' ' . $order . ', e.id ASC';
} else {
$sort = ' ORDER BY e.id ASC';
}

$sql = 'SELECT e.*
Expand Down
6 changes: 3 additions & 3 deletions competency/tests/api_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2615,9 +2615,9 @@ public function test_list_evidence_in_course() {
$evidence2 = api::add_evidence($u1->id, $c->get_id(), $cmcontext->id, \core_competency\evidence::ACTION_LOG,
'invaliddata', 'error');

$result = api::list_evidence_in_course($u1->id, $course->id, $c->get_id());
$this->assertEquals($result[0]->get_id(), $evidence2->get_id());
$this->assertEquals($result[1]->get_id(), $evidence1->get_id());
$result = api::list_evidence_in_course($u1->id, $course->id, $c->get_id(), 'timecreated', 'ASC');
$this->assertEquals($evidence1->get_id(), $result[0]->get_id());
$this->assertEquals($evidence2->get_id(), $result[1]->get_id());
}

public function test_list_course_modules_using_competency() {
Expand Down

0 comments on commit 56c5c9a

Please sign in to comment.