MDL-53346 competencies: Show user learning plans

On the course competencies page, show the user their learning plans
that contain each of the course competencies.
This commit is contained in:
Damyon Wiese
2019-02-06 08:33:55 +08:00
parent c092f75791
commit c0417b04ff
9 changed files with 164 additions and 5 deletions
+28
View File
@@ -3191,6 +3191,34 @@ class api {
return $plancompetency;
}
/**
* List the plans with a competency.
*
* @param int $userid The user id we want the plans for.
* @param int $competencyorid The competency, or its ID.
* @return array[plan] Array of learning plans.
*/
public static function list_plans_with_competency($userid, $competencyorid) {
global $USER;
static::require_enabled();
$competencyid = $competencyorid;
$competency = null;
if (is_object($competencyid)) {
$competency = $competencyid;
$competencyid = $competency->get('id');
}
$plans = plan::get_by_user_and_competency($userid, $competencyid);
foreach ($plans as $index => $plan) {
// Filter plans we cannot read.
if (!$plan->can_read()) {
unset($plans[$index]);
}
}
return $plans;
}
/**
* List the competencies in a user plan.
*