MDL-51034 tool_lp: List competencies in a user's plan

This commit is contained in:
Frederic Massart
2016-04-18 10:58:40 +08:00
parent 58405003f8
commit 1d8f0a6f50
13 changed files with 489 additions and 7 deletions
+107
View File
@@ -865,6 +865,69 @@ class external extends external_api {
return new external_single_structure($returns);
}
/**
* Returns the external structure of a full user_competency record.
*
* @return \external_single_structure
*/
protected static function get_user_competency_external_structure() {
$id = new external_value(
PARAM_INT,
'Database record id'
);
$userid = new external_value(
PARAM_INT,
'User to whom this record belongs to'
);
$competencyid = new external_value(
PARAM_INT,
'The competency associated with this record'
);
$status = new external_value(
PARAM_INT,
'The status of the user competency'
);
$reviewerid = new external_value(
PARAM_INT,
'The reviewer ID'
);
$proficiency = new external_value(
PARAM_BOOL,
'Whether or not the user is proficient'
);
$grade = new external_value(
PARAM_INT,
'The scale grade'
);
$timecreated = new external_value(
PARAM_INT,
'Timestamp this record was created'
);
$timemodified = new external_value(
PARAM_INT,
'Timestamp this record was modified'
);
$usermodified = new external_value(
PARAM_INT,
'User who modified this record last'
);
$returns = array(
'id' => $id,
'userid' => $userid,
'competencyid' => $competencyid,
'status' => $status,
'reviewerid' => $reviewerid,
'proficiency' => $proficiency,
'grade' => $grade,
'timecreated' => $timecreated,
'timemodified' => $timemodified,
'usermodified' => $usermodified,
);
return new external_single_structure($returns);
}
/**
* Returns description of create_competency() parameters.
*
@@ -3356,6 +3419,50 @@ class external extends external_api {
));
}
/**
* External function parameters structure.
*
* @return \external_description
*/
public static function list_plan_competencies_parameters() {
return new external_single_structure(array(
'id' => new external_value(PARAM_INT, 'The plan ID.')
));
}
/**
* List plan competencies.
* @param int $id The plan ID.
* @return array
*/
public static function list_plan_competencies($id) {
$params = self::validate_parameters(self::list_plan_competencies_parameters(), array('id' => $id));
$id = $params['id'];
$plan = api::read_plan($id);
$result = api::list_plan_competencies($plan);
foreach ($result as $key => $r) {
$r->competency = $r->competency->to_record();
$r->competency->descriptionformatted = format_text($r->competency->description,
$r->competency->descriptionformat, array('context' => $plan->get_context()));
$r->usercompetency = $r->usercompetency->to_record();
}
return $result;
}
/**
* External function return structure.
*
* @return \external_description
*/
public static function list_plan_competencies_returns() {
return new external_multiple_structure(
new external_single_structure(array(
'competency' => self::get_competency_external_structure(),
'usercompetency' => self::get_user_competency_external_structure(),
)
));
}
/**
* Returns the description of the get_scale_values() parameters.
*