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

File diff suppressed because one or more lines are too long

View File

@ -1,9 +1,9 @@
/*eslint no-var: "error"*/ /* eslint no-var: "error"*/
/*eslint no-console: "off"*/ /* eslint no-console: "off"*/
/*eslint no-unused-vars: warn */ /* eslint no-unused-vars: warn */
/*eslint max-len: ["error", { "code": 160 }] */ /* eslint max-len: ["error", { "code": 160 }] */
/*eslint-disable no-trailing-spaces */ /* eslint-disable no-trailing-spaces */
/*eslint-env es6*/ /* eslint-env es6*/
// Put this file in path/to/plugin/amd/src // Put this file in path/to/plugin/amd/src
import {SimpleLine} from "./simpleline/simpleline"; import {SimpleLine} from "./simpleline/simpleline";
@ -17,7 +17,7 @@ import Debugger from './util/debugger';
import Config from 'core/config'; import Config from 'core/config';
import {download,upload} from './downloader'; import {download,upload} from './downloader';
import {ProcessStudyplan, ProcessStudyplanPage} from './studyplan-processor'; import {ProcessStudyplan, ProcessStudyplanPage} from './studyplan-processor';
/*import {eventTypes as editSwEventTypes} from 'core/edit_switch';*/ /* import {eventTypes as editSwEventTypes} from 'core/edit_switch'; */
import { premiumenabled } from "./util/premium"; import { premiumenabled } from "./util/premium";
import { settings } from "./util/settings"; import { settings } from "./util/settings";
import TSComponents from './treestudyplan-components'; import TSComponents from './treestudyplan-components';
@ -30,7 +30,7 @@ import {Drag, Drop, DropList} from './vue-easy-dnd/vue-easy-dnd.esm';
const STUDYPLAN_EDITOR_FIELDS = const STUDYPLAN_EDITOR_FIELDS =
['name','shortname','description','idnumber','context_id', 'aggregation','aggregation_config']; ['name','shortname','description','idnumber','context_id', 'aggregation','aggregation_config'];
const STUDYPLAN_EDITOR_PAGE_FIELDS = //TODO: Add 'fullname', 'shortname' and 'description' when implementing proper page management const STUDYPLAN_EDITOR_PAGE_FIELDS = // TODO: Add 'fullname', 'shortname' and 'description' when implementing proper page management
['context_id', 'periods','startdate','enddate']; ['context_id', 'periods','startdate','enddate'];
const PERIOD_EDITOR_FIELDS = const PERIOD_EDITOR_FIELDS =
['fullname','shortname','startdate','enddate']; ['fullname','shortname','startdate','enddate'];
@ -44,7 +44,7 @@ const datechanger_globals = {
}; };
export default { export default {
STUDYPLAN_EDITOR_FIELDS: STUDYPLAN_EDITOR_FIELDS, // make copy available in plugin STUDYPLAN_EDITOR_FIELDS: STUDYPLAN_EDITOR_FIELDS, // make copy available in plugin
install(Vue/*,options*/){ install(Vue/* ,options */) {
Vue.component('drag',Drag); Vue.component('drag',Drag);
Vue.component('drop',Drop); Vue.component('drop',Drop);
Vue.component('drop-list',DropList); Vue.component('drop-list',DropList);
@ -63,7 +63,7 @@ export default {
* @param {Object} elem The element to check * @param {Object} elem The element to check
* @returns {boolean} True if visible * @returns {boolean} True if visible
*/ */
function isVisible(elem){ function isVisible(elem) {
return !!( elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length ); return !!( elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length );
} }

View File

@ -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

View File

@ -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";