Added IDNumber getter and did some polishing

This commit is contained in:
PMKuipers 2024-05-15 22:57:54 +02:00
parent c938b994a1
commit 9a1b32855f
4 changed files with 75 additions and 16 deletions

View File

@ -117,6 +117,14 @@ class studyplan {
return $this->r->shortname;
}
/**
* Return idnumber
* @return string
*/
public function idnumber() {
return $this->r->idnumber;
}
/**
* Return full name
* @return string
@ -561,17 +569,20 @@ class studyplan {
* Find all studyplans in a given context or the system context with a specific short name
* (Used in generating random grades for development)
* @param string $shortname Shortname to match
* @param int $contextid Optional contextid to search in. System context used if left empty
* @param int $contextid Optional contextid to search in. All contexts searched if empty.
* @return studyplan[]
*/
public static function find_by_shortname($shortname, $contextid = 0): array {
global $DB;
$list = [];
$where = "shortname = :shortname AND context_id = :contextid";
if ($contextid == 0) {
$where .= "OR context_id IS NULL";
$where = "shortname = :shortname ";
if ($contextid == 1) {
$where .= " AND (context_id = :contextid OR context_id IS NULL)";
} else if ($contextid > 1) {
$where .= " AND context_id = :contextid";
}
$ids = $DB->get_fieldset_select(self::TABLE, "id", $where, ["shortname" => $shortname, "contextid" => $contextid]);
foreach ($ids as $id) {
$list[] = self::find_by_id($id);
@ -579,6 +590,54 @@ class studyplan {
return $list;
}
/**
* Find all studyplans in a given context or the system context with a specific idnumber
* @param string $idnumber IDNumber to match
* @param int $contextid Optional contextid to search in. All contexts searched if empty.
* @return studyplan[]
*/
public static function find_by_idnumber($idnumber, $contextid = 0): array {
global $DB;
$list = [];
$where = "idnumber = :idnumber ";
if ($contextid == 1) {
$where .= " AND (context_id = :contextid OR context_id IS NULL)";
} else if ($contextid > 1) {
$where .= " AND context_id = :contextid";
}
$ids = $DB->get_fieldset_select(self::TABLE, "id", $where, ["idnumber" => $idnumber, "contextid" => $contextid]);
foreach ($ids as $id) {
$list[] = self::find_by_id($id);
}
return $list;
}
/**
* Find all studyplans in a given context or the system context with a specific full name
* @param string $name Full name to match
* @param int $contextid Optional contextid to search in. All contexts searched if empty.
* @return studyplan[]
*/
public static function find_by_fullname($name, $contextid = 0): array {
global $DB;
$list = [];
$where = "name = :name ";
if ($contextid == 1) {
$where .= " AND (context_id = :contextid OR context_id IS NULL)";
} else if ($contextid > 1) {
$where .= " AND context_id = :contextid";
}
$ids = $DB->get_fieldset_select(self::TABLE, "id", $where, ["name" => $name, "contextid" => $contextid]);
foreach ($ids as $id) {
$list[] = self::find_by_id($id);
}
return $list;
}
/**
* Find all studyplans for a given user
* @param int $userid Id of the user to search for

View File

@ -22,7 +22,7 @@
defined('MOODLE_INTERNAL') || die();
$plugin->component = 'local_treestudyplan'; // Recommended since 2.0.2 (MDL-26035). Required since 3.0 (MDL-48494).
$plugin->version = 2024051000; // YYYYMMDDHH (year, month, day, iteration).
$plugin->version = 2024051400; // YYYYMMDDHH (year, month, day, iteration).
$plugin->requires = 2021051700; // YYYYMMDDHH (This is the release version for Moodle 3.11).
$plugin->release = "1.2.0";