Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions classes/task/insert_missing_helptable_entries.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,8 @@ public function get_name(): string {

#[\Override]
public function execute(): void {
global $pgdb, $CFG;
include_once($CFG->dirroot . '/local/lsf_unification/class_pg_lite.php');
include_once($CFG->dirroot . '/local/lsf_unification/lib_features.php');
$pgdb = new pg_lite();
$connected = $pgdb->connect();
$recourceid = pg_connection_status($pgdb->connection);
mtrace('! = unknown category found, ? = unknown linkage found;' . 'Verbindung: ' .
($connected ? 'ja' : 'nein') . ' (' . $recourceid . ')');
global $CFG;
require_once($CFG->dirroot . '/local/lsf_unification/lib_his.php');
insert_missing_helptable_entries(true);
$pgdb->dispose();
}
}
33 changes: 33 additions & 0 deletions classes/task/insert_missing_helptable_entries_adhoc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

namespace local_lsf_unification\task;

/**
* Ad hoc task to update the lsf unification tables.
*
* @package local_lsf_unification
* @copyright 2026 Tamaro Walter
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class insert_missing_helptable_entries_adhoc extends \core\task\adhoc_task {
#[\Override]
public function execute(): void {
global $CFG;
require_once($CFG->dirroot . '/local/lsf_unification/lib_his.php');
insert_missing_helptable_entries(true);
}
}
2 changes: 1 addition & 1 deletion db/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" COMMENT="moodle dumbness" NEXT="child"/>
<FIELD NAME="child" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" PREVIOUS="id" NEXT="parent"/>
<FIELD NAME="parent" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" PREVIOUS="child" NEXT="distance"/>
<FIELD NAME="distance" TYPE="int" LENGTH="5" NOTNULL="true" SEQUENCE="false" COMMENT="ueid-&amp;gt;parentid = 1 ueid-&amp;gt;parentid-&amp;gt;parentid = 2 ..." PREVIOUS="parent"/>
<FIELD NAME="distance" TYPE="int" LENGTH="5" NOTNULL="true" SEQUENCE="false" COMMENT="Distance in the parent chain: direct parent = 1, grandparent = 2, etc." PREVIOUS="parent"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="realkey"/>
Expand Down
170 changes: 84 additions & 86 deletions helptablemanager.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,158 +21,156 @@
* @copyright 2025 Tamaro Walter
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

use core\output\notification;
use core\task\manager;
use local_lsf_unification\task\insert_missing_helptable_entries_adhoc;

define('NO_OUTPUT_BUFFERING', true);

require_once("../../config.php");
require_once("$CFG->libdir/adminlib.php");
require_once("./lib_his.php");
require_once($CFG->dirroot . '/course/lib.php');
require_login();
admin_externalpage_setup('local_lsf_unification_helptable');

echo $OUTPUT->header();
echo $OUTPUT->heading('HISLSF Helptable Management');

$originid = optional_param('originid', -1, PARAM_INT); // HIS category origin id.
$mainid = optional_param('mainid', -1, PARAM_INT); // HIS catecory id.
$mdlid = optional_param('mdlid', -1, PARAM_INT); // Moodle category id.
$maxorigin = optional_param('maxorigin', 0, PARAM_INT); // Max (his origin ids).
$delete = optional_param('delete', 0, PARAM_INT); // Category id where to remove a matching.
$updatehelptable = optional_param('updatehelptable', 0, PARAM_BOOL);

$basepath = '/local/lsf_unification/helptablemanager.php';
$output = "";
if ($originid == -1) {
$updatetable = get_string('update_helptable', 'local_lsf_unification');
$createmappings = get_string('create_mappings', 'local_lsf_unification');
echo "<p>" . $OUTPUT->box('<a href="./update_helptable.php">' . $updatetable . '</a>') . "</p>";
echo "<p>" . $OUTPUT->box('<a href="?originid=0">' . $createmappings . '</a>') . "</p>";
require_capability('moodle/site:config', context_system::instance());
if ($updatehelptable) {
$existingtasks = \core\task\manager::get_adhoc_tasks(insert_missing_helptable_entries_adhoc::class);
if (empty($existingtasks)) {
$updatetime = time() + 60;
$task = new insert_missing_helptable_entries_adhoc();
$task->set_next_run_time($updatetime);
manager::queue_adhoc_task($task, true);
$params = ['time' => userdate($updatetime), 'link' => (new moodle_url("/admin/tool/task/adhoctasks.php"))->out()];
$info = get_string('update_helptable_notification', 'local_lsf_unification', $params);
} else {
$params = ['link' => (new moodle_url("/admin/tool/task/adhoctasks.php"))->out()];
$info = get_string('update_helptable_already_queued', 'local_lsf_unification', $params);
}
redirect(new moodle_url($basepath), $info);
}
$mustachedata = [
'isadmin' => has_capability('moodle/site:config', context_system::instance()),
'createmappings' => new moodle_url($basepath, ['originid' => 0]),
];
$output = $OUTPUT->render_from_template('local_lsf_unification/helptable_manager/overview', $mustachedata);
} else if ($mainid == -1) {
if (!empty($delete)) {
set_cat_mapping($delete, 0);
}
$prefix = "-";
if (empty($originid)) {
$origins = implode(", ", get_his_toplevel_originids());
$parents = ["" => "- Lehrveranstaltungen"];
$prefix .= "-";
$parents = ["" => "Lehrveranstaltungen"];
} else {
$origins = $originid;
$id = $originid;
$parents = [$id => " " . get_newest_element($id)->txt];
while ($parent = get_newest_parent($id)) {
foreach ($parents as $key => $txt) {
$parents[$key] = "-" . $parents[$key];
$parents[$key] = $parents[$key];
}
$prefix .= "-";
if (($id == $parent->ueid) || ($id == $parent->origin)) {
break;
}
$id = $parent->origin;
$parents[$id] = " " . $parent->txt;
}
}
$parentstxt = "";
foreach ($parents as $id => $txt) {
$parentstxt = [];
foreach (array_reverse($parents, true) as $id => $txt) {
Comment thread
TamaroWalter marked this conversation as resolved.
$navigate = get_string('navigate', 'local_lsf_unification');
$parentstxt = " [<a href='?originid=" . $id . "'>" . $navigate . "</a>] " . $txt . "<br>" . $parentstxt;
$parentstxt[] = [
'parentlink' => new moodle_url($basepath, ['originid' => $id]),
'parenttext' => $txt,
];
}
$sublevels = get_newest_sublevels($origins);
$childlist = "";
$childs = [];
foreach ($sublevels as $child) {
$child->mdlid = get_mdlid($child->origin);
$child->name = empty($child->mdlid) ? "" : get_mdlname($child->origin);
$maxorigin = ($child->origin > $maxorigin) ? $child->origin : $maxorigin;
$str = [
0 => get_string('navigate', 'local_lsf_unification'),
1 => get_string('not_mapped', 'local_lsf_unification'),
2 => get_string(empty($child->mdlid) ? 'map' : 'overwrite', 'local_lsf_unification'),
3 => get_string('delete', 'local_lsf_unification'),
$childs[] = [
'sublevels' => has_sublevels($child->ueid),
'childoriginlink' => new moodle_url($basepath, ['originid' => $child->origin]),
'idchildorigin' => "idch_" . ($child->origin),
'prefixchildtxt' => $child->txt,
'emptychildmdlid' => empty($child->mdlid),
'categorylink' => new moodle_url('/course/index.php', ['categoryid' => $child->mdlid]),
'childname' => $child->name,
'namechildorigin' => 'ch_' . ($child->origin),
'deletelink' => new moodle_url($basepath, ['originid' => $originid, 'delete' => $child->origin]),
];
$childlist .=
"<tr>" . (
(!has_sublevels($child->ueid))
? "<td>&nbsp;</td>"
: ("<td nowrap='nowrap'>&nbsp;[
<a href='?originid=" . ($child->origin) . "'>" . $str[0] . "</a>]
</td>")
) . "
<td>
<label for='idch_" . ($child->origin) . "'>" . $prefix . " " . ($child->txt) . "</label>
</td>
<td nowrap='nowrap'>&nbsp;[" .
(empty($child->mdlid)
? $str[1]
: ("<a href='../../course/category.php?id=" . ($child->mdlid) . "'>" . ($child->name) . "</a>")) . "]
</td>
<td nowrap='nowrap'>&nbsp;[
<input id='idch_" . ($child->origin) . "' type='checkbox' name='ch_" . ($child->origin) . "' value='x'>
<label for='idch_" . ($child->origin) . "'> " . $str[2] . "</label>
]
</td>" . (
(empty($child->mdlid))
? "<td>&nbsp;</td>"
: ("<td nowrap='nowrap'>&nbsp;[
<a href='?originid=" . $originid . "&delete=" . $child->origin . "'>" . $str[3] . "</a>
]
</td>")
) .
"</tr>";
}
$maincategories = get_mdl_toplevels();
$options = "";
$options = [];
foreach ($maincategories as $id => $txt) {
$options .= "<option value='" . $id . "'>" . $txt->name . "</option>";
$options[] = ['value' => $id, 'text' => $txt->name];
}
$catchoice = "<b>" . get_string('main_category', 'local_lsf_unification') . "</b>:
<select name='mainid'>" . $options . "</select> &nbsp;
<input type='submit' value='" . get_string('map', 'local_lsf_unification') . "'>
<input type='hidden' name='originid' value='" . $originid . "'>
<input type='hidden' name='maxorigin' value='" . $maxorigin . "'>";
echo "<form action='' method='get' class='mform'>
<p>" . $OUTPUT->box($parentstxt) . "</p>
<p>" . $OUTPUT->box("<table>" . $childlist . "</table>") . "</p>
<p>" . $OUTPUT->box($catchoice) . "</p>
</form>";
$mustachedata = [
'parents' => $parentstxt,
'childs' => $childs,
'options' => $options,
'originid' => $originid,
'maxorigin' => $maxorigin,
];
$output = $OUTPUT->render_from_template('local_lsf_unification/helptable_manager/childlist', $mustachedata);
} else if ($mdlid == -1) {
$hiddenfields = "";
$childlist = "";
$childs = [];
$hiddenfields = [];
for ($i = 0; $i <= $maxorigin; $i++) {
if (isset($_GET["ch_" . $i])) {
$hiddenfields .= "<input type='hidden' name='ch_" . $i . "' value='x'>";
$childlist .= (empty($childlist) ? "" : "<br>") . "-" . (get_newest_element($i)->txt) . "";
$hiddenfields[] = ['hiddenname' => 'ch_' . $i];
$childs[] = ['childtext' => get_newest_element($i)->txt];
}
}
$subcats = get_mdl_sublevels($mainid);
$displaylist = [];
$displaylist = core_course_category::make_categories_list();
$options = "";
$displaylist = core_course_category::make_categories_list();
$options = [];
foreach ($displaylist as $id => $txt) {
if (isset($subcats[$id])) {
$options .= "<option value='" . $id . "'>" . $txt . "</option>";
$options[] = ['optionid' => $id, 'optiontext' => $txt];
}
}
echo "<form action='' method='get' class='mform'>
<p>" . $OUTPUT->box("<p>" . $childlist . "</p><b>=&gt;</b>
<p>
<b>" . get_string('sub_category', 'local_lsf_unification') . "</b>:
<select name='mdlid'>" . $options . "</select>
</p>") .
"</p>
<input type='hidden' name='originid' value='" . $originid . "'>
<input type='hidden' name='mainid' value='" . $mainid . "'>
<input type='hidden' name='maxorigin' value='" . $maxorigin . "'>" .
$hiddenfields .
"<input type='submit' value='" . get_string('map', 'local_lsf_unification') . "'>
</form>";
// Additional variable if only 1 category is available for mapping.
$singlecat = count($options) == 1 ? ['category' => $options[0]['optiontext'], 'categoryid' => $options[0]['optionid']] : [];
$mustachedata = [
'childs' => $childs,
'options' => $options,
'originid' => $originid,
'mainid' => $mainid,
'maxorigin' => $maxorigin,
'hiddenfields' => $hiddenfields,
'single_category' => $singlecat,
];
$output = $OUTPUT->render_from_template('local_lsf_unification/helptable_manager/mapping_submit', $mustachedata);
} else {
$mapchilds = [];
$maptxt = "";
$count = 0;
for ($i = 0; $i <= $maxorigin; $i++) {
if (isset($_GET["ch_" . $i])) {
$maptxt .= $i . "-" . $mdlid . "<br>";
set_cat_mapping($i, $mdlid);
$count++;
}
}
echo "<p>" . $OUTPUT->box($maptxt . "<b>" . $count . " " . get_string('map_done', 'local_lsf_unification')) . "</b></p>";
echo "<p>" . $OUTPUT->box('<a href="?originid=0">' . get_string('create_mappings', 'local_lsf_unification') . '</a>') . "</p>";
$string = $count . " " . get_string('map_done', 'local_lsf_unification');
redirect(new moodle_url($basepath, ['originid' => 0]), $string);
}

echo $OUTPUT->header();
echo $OUTPUT->heading('HISLSF Helptable Management');
echo $output;
echo $OUTPUT->footer();
2 changes: 2 additions & 0 deletions lang/de/local_lsf_unification.php
Comment thread
TamaroWalter marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@
$string['main_category'] = 'Hauptkategorie';
$string['map'] = 'zuordnen';
$string['map_done'] = 'Zuordnung(en) wurde(n) festgehalten';
$string['map_list_empty'] = "Keine Elemente ausgewählt";
$string['map_submit'] = 'Folgende Veranstaltungen werden zugeordnet:';
$string['mapped'] = 'zugeordnet';
$string['max_import_age'] = 'Maximales Kurs-Alter';
$string['max_import_age_description'] = 'Maximales Alter, dass ein Kurs haben darf, danach wird er nicht mehr zur Auswahl angezeigt.';
Expand Down
5 changes: 4 additions & 1 deletion lang/en/local_lsf_unification.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@
$string['main_category'] = 'Maincateogry';
$string['map'] = 'map';
$string['map_done'] = 'mapping(s) saved';
$string['map_list_empty'] = "No items selected";
$string['map_submit'] = "You are about to map the following courses:";
$string['mapped'] = 'mapped';
$string['max_import_age'] = 'Max Import Age';
$string['max_import_age_description'] = 'The maximum age, a course may have before being imported.';
Expand Down Expand Up @@ -177,7 +179,8 @@
$string['task_missing_helptable_entries'] = 'Update table of LSF categories.';
$string['template_from_course'] = 'Alternative {$a}: Include contents from an existing course ...';
$string['update_helptable'] = 'Update Helptable With HIS-LSF data';
$string['update_helptable_notification'] = 'All tables of lsf_unification were updated';
$string['update_helptable_already_queued'] = 'Task to update tables is already queued. Click <a href="{$a->link}">here</a> for more information.';
$string['update_helptable_notification'] = 'The Tables will be updated at {$a->time}. Click <a href="{$a->link}">here</a> for more information.';
$string['warning_cannot_enrol_nologin'] = "person wasn't enrolled (no username found)";
$string['warning_cannot_enrol_nouser'] = "person wasn't enrolled (no user found)";
$string['warning_cannot_enrol_other'] = "person wasn't enrolled";
Expand Down
Loading
Loading