Added IDNumber getter and did some polishing
This commit is contained in:
parent
c938b994a1
commit
9a1b32855f
|
@ -117,6 +117,14 @@ class studyplan {
|
||||||
return $this->r->shortname;
|
return $this->r->shortname;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return idnumber
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function idnumber() {
|
||||||
|
return $this->r->idnumber;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return full name
|
* Return full name
|
||||||
* @return string
|
* @return string
|
||||||
|
@ -561,17 +569,20 @@ class studyplan {
|
||||||
* Find all studyplans in a given context or the system context with a specific short name
|
* Find all studyplans in a given context or the system context with a specific short name
|
||||||
* (Used in generating random grades for development)
|
* (Used in generating random grades for development)
|
||||||
* @param string $shortname Shortname to match
|
* @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[]
|
* @return studyplan[]
|
||||||
*/
|
*/
|
||||||
public static function find_by_shortname($shortname, $contextid = 0): array {
|
public static function find_by_shortname($shortname, $contextid = 0): array {
|
||||||
global $DB;
|
global $DB;
|
||||||
$list = [];
|
$list = [];
|
||||||
|
|
||||||
$where = "shortname = :shortname AND context_id = :contextid";
|
$where = "shortname = :shortname ";
|
||||||
if ($contextid == 0) {
|
if ($contextid == 1) {
|
||||||
$where .= "OR context_id IS NULL";
|
$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]);
|
$ids = $DB->get_fieldset_select(self::TABLE, "id", $where, ["shortname" => $shortname, "contextid" => $contextid]);
|
||||||
foreach ($ids as $id) {
|
foreach ($ids as $id) {
|
||||||
$list[] = self::find_by_id($id);
|
$list[] = self::find_by_id($id);
|
||||||
|
@ -579,6 +590,54 @@ class studyplan {
|
||||||
return $list;
|
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
|
* Find all studyplans for a given user
|
||||||
* @param int $userid Id of the user to search for
|
* @param int $userid Id of the user to search for
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
defined('MOODLE_INTERNAL') || die();
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
$plugin->component = 'local_treestudyplan'; // Recommended since 2.0.2 (MDL-26035). Required since 3.0 (MDL-48494).
|
$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->requires = 2021051700; // YYYYMMDDHH (This is the release version for Moodle 3.11).
|
||||||
|
|
||||||
$plugin->release = "1.2.0";
|
$plugin->release = "1.2.0";
|
||||||
|
|
Loading…
Reference in New Issue
Block a user