Commit 96c2b847 authored by Frederic Massart's avatar Frederic Massart
Browse files

MDL-53453 cbe: PHP Docs and coding style adjustments

parent 946bc0f7
......@@ -110,7 +110,6 @@ class api {
*
* Requires moodle/role:manage capability at system context.
*
* @param array $filters A list of filters to apply to the list.
* @return int
*/
public static function count_cohort_role_assignments() {
......
......@@ -39,6 +39,9 @@ require_once($CFG->libdir . '/formslib.php');
*/
class assign_role_cohort extends moodleform {
/**
* Form definition.
*/
public function definition() {
global $OUTPUT;
......
......@@ -46,7 +46,7 @@ class cohort_role_assignments_table extends table_sql {
* Sets up the table.
*
* @param string $uniqueid Unique id of table.
* @param \tool_lp\template $template The template.
* @param moodle_url $url The base URL.
*/
public function __construct($uniqueid, $url) {
global $CFG;
......@@ -70,10 +70,22 @@ class cohort_role_assignments_table extends table_sql {
$this->define_table_configs();
}
/**
* Role name column.
*
* @param array $data Row data.
* @return string
*/
protected function col_rolename($data) {
return $this->rolenames[$data->roleid]->localname;
}
/**
* Cohort name column.
*
* @param array $data Row data.
* @return string
*/
protected function col_cohortname($data) {
global $OUTPUT;
......@@ -93,6 +105,12 @@ class cohort_role_assignments_table extends table_sql {
return $html;
}
/**
* Actions column.
*
* @param array $data Row data.
* @return string
*/
protected function col_actions($data) {
global $OUTPUT;
......
......@@ -33,11 +33,19 @@ use tool_cohortroles\api;
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class cohort_role_sync extends scheduled_task {
/**
* Get name.
* @return string
*/
public function get_name() {
// Shown in admin screens.
return get_string('taskname', 'tool_cohortroles');
}
/**
* Execute.
*/
public function execute() {
mtrace('Sync cohort roles...');
$result = api::sync_all_cohort_roles();
......
......@@ -17,7 +17,7 @@
/**
* Strings for component 'tool_userroles', language 'en'
*
* @package tool_userroles
* @package tool_cohortroles
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
......
......@@ -2173,7 +2173,7 @@ class api {
* This silently ignores when the relation already existed.
*
* @param template|int $templateorid The template or its ID.
* @param stdClass|int $cohortid The cohort ot its ID.
* @param stdClass|int $cohortorid The cohort ot its ID.
* @return template_cohort
*/
public static function create_template_cohort($templateorid, $cohortorid) {
......@@ -2209,7 +2209,7 @@ class api {
* Remove a relation between a template and a cohort.
*
* @param template|int $templateorid The template or its ID.
* @param stdClass|int $cohortid The cohort ot its ID.
* @param stdClass|int $cohortorid The cohort ot its ID.
* @return boolean True on success or when the relation did not exist.
*/
public static function delete_template_cohort($templateorid, $cohortorid) {
......@@ -2335,7 +2335,8 @@ class api {
}
// TODO MDL-52243 Use core function.
list($insql, $inparams) = external::filter_users_with_capability_on_user_context_sql('tool/lp:planreview', $userid, SQL_PARAMS_NAMED);
list($insql, $inparams) = external::filter_users_with_capability_on_user_context_sql('tool/lp:planreview',
$userid, SQL_PARAMS_NAMED);
$sql .= " AND p.userid $insql";
$params += $inparams;
......@@ -3517,7 +3518,8 @@ class api {
}
$plan = new plan($ucp->get_planid());
if ($plan->get_status() != plan::STATUS_COMPLETE) {
throw new coding_exception('To log the user competency in non-completed plan use user_competency_viewed_in_plan method.');
throw new coding_exception('To log the user competency in non-completed plan use '
. 'user_competency_viewed_in_plan method.');
}
\tool_lp\event\user_competency_plan_viewed::create_from_user_competency_plan($ucp)->trigger();
......@@ -4210,7 +4212,8 @@ class api {
// Simply logging an evidence.
case evidence::ACTION_LOG:
if ($grade !== null) {
throw new coding_exception("The grade MUST NOT be set when 'logging' an evidence. Or use ACTION_SUGGEST instead.");
throw new coding_exception("The grade MUST NOT be set when 'logging' an evidence. "
. "Or use ACTION_SUGGEST instead.");
}
break;
......@@ -4290,7 +4293,7 @@ class api {
* rules and if so will see if they match. When matched it will take the required
* step to add evidence and trigger completion, etc...
*
* @param usercompetency $usercompetency The user competency recently completed.
* @param user_competency $usercompetency The user competency recently completed.
* @param competency|null $competency The competency of the user competency, useful to avoid unnecessary read.
* @return void
*/
......
......@@ -524,7 +524,7 @@ class competency extends persistent {
protected function validate_parentid($value) {
// Check that the parent exists. But only if we don't have it already, and we actually have a parent.
if (!empty($value) && !$this->newparent && !competency::record_exists($value)) {
if (!empty($value) && !$this->newparent && !self::record_exists($value)) {
return new lang_string('invaliddata', 'error');
}
......@@ -602,7 +602,6 @@ class competency extends persistent {
protected function validate_scaleid($value) {
global $DB;
// We'll
if ($value === null) {
return true;
}
......
......@@ -379,6 +379,7 @@ class competency_framework extends persistent {
* Extract the proficiency of a grade from a scale configuration.
*
* @param string $config JSON encoded config.
* @param int $grade The grade.
* @return int Representing a boolean
*/
public static function get_proficiency_of_grade_from_scale_configuration($config, $grade) {
......
......@@ -76,6 +76,7 @@ abstract class competency_rule {
/**
* Validate the rule config.
*
* @param string $value The value to validate.
* @return bool
*/
abstract public function validate_config($value);
......
......@@ -41,6 +41,7 @@ class competency_rule_all extends competency_rule {
/**
* Whether or not the rule is matched.
*
* @param user_competency $usercompetency The user competency.
* @return bool
*/
public function matches(user_competency $usercompetency) {
......@@ -73,6 +74,7 @@ class competency_rule_all extends competency_rule {
/**
* Validate the rule config.
*
* @param string $value The value to validate.
* @return bool
*/
public function validate_config($value) {
......
......@@ -53,6 +53,7 @@ class competency_rule_points extends competency_rule {
/**
* Whether or not the rule is matched.
*
* @param user_competency $usercompetency The user competency.
* @return bool
*/
public function matches(user_competency $usercompetency) {
......@@ -102,6 +103,7 @@ class competency_rule_points extends competency_rule {
/**
* Validate the rule config.
*
* @param string $value The value to validate.
* @return bool
*/
public function validate_config($value) {
......
......@@ -190,6 +190,7 @@ class course_competency extends persistent {
/**
* Validate course ID.
*
* @param int $data The course ID.
* @return true|lang_string
*/
protected function validate_courseid($data) {
......@@ -203,6 +204,7 @@ class course_competency extends persistent {
/**
* Validate competency ID.
*
* @param int $data The competency ID.
* @return true|lang_string
*/
protected function validate_competencyid($data) {
......
......@@ -136,6 +136,7 @@ class course_module_competency extends persistent {
/**
* Validate cmid ID.
*
* @param int $data The CM ID.
* @return true|lang_string
*/
protected function validate_cmid($data) {
......@@ -149,6 +150,7 @@ class course_module_competency extends persistent {
/**
* Validate competency ID.
*
* @param int $data The competency ID.
* @return true|lang_string
*/
protected function validate_competencyid($data) {
......@@ -162,6 +164,7 @@ class course_module_competency extends persistent {
* Return the module IDs and visible flags that include this competency in a single course.
*
* @param int $competencyid The competency id
* @param int $courseid The course ID.
* @return array of ints (cmids)
*/
public static function list_course_modules($competencyid, $courseid) {
......@@ -171,7 +174,8 @@ class course_module_competency extends persistent {
FROM {' . self::TABLE . '} modcomp
JOIN {course_modules} coursemodules
ON modcomp.cmid = coursemodules.id
WHERE modcomp.competencyid = ? AND coursemodules.course = ?', array($competencyid, $courseid));
WHERE modcomp.competencyid = ? AND coursemodules.course = ?',
array($competencyid, $courseid));
return array_keys($results);
}
......
......@@ -45,7 +45,7 @@ class plan_deleted extends base {
/**
* Convenience method to instantiate the event.
*
*
* @param plan $plan The plan.
* @return self
*/
......
......@@ -45,7 +45,7 @@ class template_deleted extends base {
/**
* Convenience method to instantiate the event.
*
*
* @param template $template The template.
* @return self
*/
......
......@@ -509,7 +509,6 @@ class external extends external_api {
/**
* List the existing competency frameworks
*
* @param string $filters
* @param int $sort
* @param string $order
* @param string $skip
......@@ -596,8 +595,9 @@ class external extends external_api {
/**
* Count the existing competency frameworks
*
* @param string $filters Filters to use.
* @return boolean
* @param array $context
* @param string $includes
* @return int
*/
public static function count_competency_frameworks($context, $includes) {
$params = self::validate_parameters(self::count_competency_frameworks_parameters(),
......@@ -2399,8 +2399,9 @@ class external extends external_api {
/**
* Count the existing learning plan templates
*
* @param array $filters Filters to allow.
* @return boolean
* @param array $context
* @param string $includes
* @return int
*/
public static function count_templates($context, $includes) {
$params = self::validate_parameters(self::count_templates_parameters(),
......@@ -2934,7 +2935,8 @@ class external extends external_api {
/**
* External function user_competency_cancel_review_request.
*
* @param int $id The ID description.
* @param int $userid The user ID.
* @param int $competencyid The competency ID.
* @return boolean
*/
public static function user_competency_cancel_review_request($userid, $competencyid) {
......@@ -3013,7 +3015,8 @@ class external extends external_api {
/**
* External function user_competency_start_review.
*
* @param int $id The ID description.
* @param int $userid The user ID.
* @param int $competencyid The competency ID.
* @return boolean
*/
public static function user_competency_start_review($userid, $competencyid) {
......@@ -3052,7 +3055,8 @@ class external extends external_api {
/**
* External function user_competency_stop_review.
*
* @param int $id The ID description.
* @param int $userid The user ID.
* @param int $competencyid The competency ID.
* @return boolean
*/
public static function user_competency_stop_review($userid, $competencyid) {
......@@ -4082,7 +4086,7 @@ class external extends external_api {
/**
* Loads the data required to render the user_evidence_page template.
*
* @param int $userid User id.
* @param int $id User id.
* @return boolean
*/
public static function data_for_user_evidence_page($id) {
......@@ -4442,11 +4446,11 @@ class external extends external_api {
* Function used to return a list of users where the given user has a particular capability.
* This is used e.g. to find all the users where someone is able to manage their learning plans,
* it also would be useful for mentees etc.
* @param $capability String - The capability string we are filtering for. If '' is passed,
* @param string $capability - The capability string we are filtering for. If '' is passed,
* an always matching filter is returned.
* @param $userid int - The user id we are using for the access checks. Defaults to current user.
* @param $type int - The type of named params to return (passed to $DB->get_in_or_equal).
* @param $prefix string - The type prefix for the db table (passed to $DB->get_in_or_equal).
* @param int $userid - The user id we are using for the access checks. Defaults to current user.
* @param int $type - The type of named params to return (passed to $DB->get_in_or_equal).
* @param string $prefix - The type prefix for the db table (passed to $DB->get_in_or_equal).
* @return list($sql, $params) Same as $DB->get_in_or_equal().
*/
public static function filter_users_with_capability_on_user_context_sql($capability,
......@@ -4486,7 +4490,7 @@ class external extends external_api {
$hassystem = has_capability($capability, $syscontext, $userid);
$access = get_user_access_sitewide($userid);
// Build up a list of level 2 contexts (candidates to be user context)
// Build up a list of level 2 contexts (candidates to be user context).
$filtercontexts = array();
foreach ($access['ra'] as $path => $role) {
$parts = explode('/', $path);
......@@ -4582,6 +4586,9 @@ class external extends external_api {
* Search users.
*
* @param string $query
* @param string $capability
* @param int $limitfrom
* @param int $limitnum
* @return array
*/
public static function search_users($query, $capability = '', $limitfrom = 0, $limitnum = 100) {
......@@ -4703,6 +4710,8 @@ class external extends external_api {
* TODO: MDL-52243 Move this function to cohorts/externallib.php
*
* @param string $query
* @param array $context
* @param string $includes
* @param int $limitfrom
* @param int $limitnum
* @return array
......
......@@ -37,8 +37,7 @@ use external_value;
use external_format_value;
/**
* Generic exporter to take a stdClass and prepare it for return by webservice, or as the context
* for a template.
* Generic exporter to take a stdClass and prepare it for return by webservice, or as the context for a template.
*
* templatable classes implementing export_for_template, should always use a standard exporter if it exists.
* External functions should always use a standard exporter if it exists.
......@@ -51,6 +50,7 @@ abstract class exporter {
/** @var array $related List of related objects used to avoid DB queries. */
protected $related = array();
/** @var stdClass|array The data of this exporter. */
protected $data = null;
/**
......@@ -198,6 +198,7 @@ abstract class exporter {
*
* Note: These must be defined in {@link self::define_other_properties()}.
*
* @param renderer_base $output The renderer.
* @return array Keys are the property names, values are their values.
*/
protected function get_other_values(renderer_base $output) {
......@@ -421,6 +422,9 @@ abstract class exporter {
/**
* Returns the read structure from a set of properties (recursive).
*
* @param array $properties The properties.
* @param int $required Whether is required.
* @param mixed $default The default value.
* @return external_single_structure
*/
final protected static function get_read_structure_from_properties($properties, $required = VALUE_REQUIRED, $default = null) {
......
......@@ -53,7 +53,6 @@ abstract class persistent_exporter extends exporter {
}
$this->persistent = $persistent;
if (method_exists($this->persistent, 'get_context') && !isset($this->related['context'])) {
$this->related['context'] = $this->persistent->get_context();
}
......
......@@ -90,18 +90,18 @@ class template_statistics_exporter extends exporter {
}
$linkedcompetencypercentage = 0;
if ($this->data->competencycount > 0) {
$linkedcompetencypercentage = format_float(((float) $linkedcompetencycount /
(float) $this->data->competencycount) * 100.0);
$linkedcompetencypercentage = format_float(
((float) $linkedcompetencycount / (float) $this->data->competencycount) * 100.0);
}
$completedplanpercentage = 0;
if ($this->data->plancount > 0) {
$completedplanpercentage = format_float(((float) $this->data->completedplancount /
(float) $this->data->plancount) * 100.0);
$completedplanpercentage = format_float(
((float) $this->data->completedplancount / (float) $this->data->plancount) * 100.0);
}
$proficientusercompetencyplanpercentage = 0;
if ($this->data->usercompetencyplancount > 0) {
$proficientusercompetencyplanpercentage = format_float(((float) $this->data->proficientusercompetencyplancount /
(float) $this->data->usercompetencyplancount) * 100.0);
$proficientusercompetencyplanpercentage = format_float(
((float) $this->data->proficientusercompetencyplancount / (float) $this->data->usercompetencyplancount) * 100.0);
}
$competencies = array();
$contextcache = array();
......
......@@ -110,6 +110,7 @@ class competency extends persistent {
/**
* Convert some fields.
*
* @param stdClass $data
* @return object
*/
protected static function convert_fields(stdClass $data) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment