MDL-53879 competency: Remove limit on framework depth

This commit is contained in:
Frederic Massart
2016-04-28 16:41:24 +08:00
parent 6bd3ab0717
commit 8ea0f17ae9
9 changed files with 117 additions and 107 deletions
+23 -4
View File
@@ -506,10 +506,6 @@ class competency extends persistent {
} else if (!preg_match('@/([0-9]+/)+@', $value)) {
// The format of the path is not correct.
return new lang_string('invaliddata', 'error');
} else if ((substr_count($value, '/') - 1) > competency_framework::get_taxonomies_max_level()) {
// Validate the depth of the path.
return new lang_string('invaliddata', 'error');
}
return true;
@@ -697,6 +693,29 @@ class competency extends persistent {
return $rules;
}
/**
* Return the current depth of a competency framework.
*
* @param int $frameworkid The framework ID.
* @return int
*/
public static function get_framework_depth($frameworkid) {
global $DB;
$totallength = $DB->sql_length('path');
$trimmedlength = $DB->sql_length("REPLACE(path, '/', '')");
$sql = "SELECT ($totallength - $trimmedlength - 1) AS depth
FROM {" . self::TABLE . "}
WHERE competencyframeworkid = :id
ORDER BY depth DESC";
$record = $DB->get_record_sql($sql, array('id' => $frameworkid), IGNORE_MULTIPLE);
if (!$record) {
$depth = 0;
} else {
$depth = $record->depth;
}
return $depth;
}
/**
* Build a framework tree with competency nodes.
*