Skip to content

Commit

Permalink
MDL-66075 core: various fixes & code polishing
Browse files Browse the repository at this point in the history
* Removes unnecessary comment in search_users() WS.
* Replaces DB call by get_course() in search_users() WS.
* Fix discussionids handling on export.php.
* Coding style fix in test_search_users unit test.
* Add missing version bump.
* phpDOc fixes in post vault.
* Fix in the dataformat callback to handle different data types.
  • Loading branch information
lameze committed Sep 23, 2019
1 parent 24ddc6d commit 1de4baf
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 19 deletions.
6 changes: 1 addition & 5 deletions enrol/externallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ public static function search_users(int $courseid, string $search, bool $searcha
}
course_require_view_participants($context);

$course = $DB->get_record('course', ['id' => $params['courseid']]);
$course = get_course($params['courseid']);
$manager = new course_enrolment_manager($PAGE, $course);

$users = $manager->search_users($params['search'],
Expand All @@ -654,10 +654,6 @@ public static function search_users(int $courseid, string $search, bool $searcha
get_extra_user_fields($context)
);
foreach ($users['users'] as $user) {
// Note: We pass the course here to validate that the current user can at least view user details in this course.
// The user we are looking at is not in this course yet though - but we only fetch the minimal set of
// user records, and the user has been validated to have course:enrolreview in this course. Otherwise
// there is no way to find users who aren't in the course in order to enrol them.
if ($userdetails = user_get_user_details($user, $course, $requiredfields)) {
$results[] = $userdetails;
}
Expand Down
3 changes: 2 additions & 1 deletion enrol/tests/course_enrolment_manager_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,8 @@ public function test_search_users($perpage, $returnexactcount, $expectedusers, $
true,
0,
$perpage,
$returnexactcount);
$returnexactcount
);

$this->assertCount($expectedusers, $users['users']);
$this->assertEquals($expectedmoreusers, $users['moreusers']);
Expand Down
8 changes: 4 additions & 4 deletions mod/forum/classes/local/vaults/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function get_from_discussion_id(
/**
* Get the list of posts for the given discussions.
*
* @param stdClass $user The user to check the unread count for
* @param stdClass $user The user to load posts for.
* @param int[] $discussionids The list of discussion ids to load posts for
* @param bool $canseeprivatereplies Whether this user can see all private replies or not
* @param string $orderby Order the results
Expand Down Expand Up @@ -157,11 +157,11 @@ public function get_from_discussion_ids(
}

/**
* Get the list of posts for the given users in the given discussions.
* The method returns posts made by the supplied users in the supplied discussions.
*
* @param stdClass $user The user to check the unread count for
* @param stdClass $user Only used when restricting private replies
* @param int[] $discussionids The list of discussion ids to load posts for
* @param int[] $userids The list of user ids to load posts for
* @param int[] $userids Only return posts made by these users
* @param bool $canseeprivatereplies Whether this user can see all private replies or not
* @param string $orderby Order the results
* @return post_entity[]
Expand Down
18 changes: 10 additions & 8 deletions mod/forum/export.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,16 @@

$discussionvault = $vaultfactory->get_discussion_vault();
$postvault = $vaultfactory->get_post_vault();

$discussionids = [];
if ($data->discussionids) {
$discussions = $discussionvault->get_from_ids($data->discussionids);
$discussionids = $data->discussionids;
} else {
$discussions = $discussionvault->get_all_discussions_in_forum($forum);
$discussionids = array_map(function ($discussion) {
return $discussion->get_id();
}, $discussions);
}

$discussionids = array_map(function ($discussion) {
return $discussion->get_id();
}, $discussions);

if ($data->userids) {
$posts = $postvault->get_from_discussion_ids_and_user_ids($USER,
$discussionids,
Expand All @@ -100,9 +99,12 @@
require_once($CFG->libdir . '/dataformatlib.php');
$filename = clean_filename('discussion');
download_as_dataformat($filename, $dataformat, $fields, $iterator, function($exportdata) use ($fields) {
$data = new stdClass();
$data = $exportdata;
foreach ($fields as $field) {
$data->$field = !empty($exportdata->$field) ? $exportdata->$field : '';
// Convert any boolean fields to their integer equivalent for output.
if (is_bool($data->$field)) {
$data->$field = (int) $data->$field;
}
}
return $data;
});
Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

defined('MOODLE_INTERNAL') || die();

$version = 2019092000.00; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2019092000.01; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.

Expand Down

0 comments on commit 1de4baf

Please sign in to comment.