MDL-51602 tool_lp: Add ability to duplicate a competency framework

This commit is contained in:
Issam Taboubi
2016-04-18 10:58:36 +08:00
committed by Frederic Massart
parent 03c6665894
commit c61db7bb6a
11 changed files with 334 additions and 8 deletions
@@ -343,4 +343,25 @@ class competency_framework extends persistent {
return $list;
}
/**
* Get a uniq idnumber.
*
* @param string $idnumber the framework idnumber
* @return string
*/
public static function get_unused_idnumber($idnumber) {
global $DB;
$currentidnumber = $idnumber;
$counter = 0;
// Iteratere while the idnumber exists.
while ($DB->record_exists_select(static::TABLE, 'idnumber = ?', array($currentidnumber))) {
$suffixidnumber = '_' . ++$counter;
$currentidnumber = substr($idnumber, 0, 100 - strlen($suffixidnumber)).$suffixidnumber;
}
// Return the uniq idnumber.
return $currentidnumber;
}
}