Skip to content
Open
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
5 changes: 5 additions & 0 deletions cal_import.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@
/**
* This page adds a hislsf calendar instance to the users calendars. It is accessible from the manage_calendars site.
* To limit the changes to original moodle-files, the call of his_add_cal() is done here.
*
* @package local_lsf_unification
* @copyright 2025 Tamaro Walter
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

require_once('../../config.php');
require_once('cal_lib.php');
require_login();
Expand Down
31 changes: 20 additions & 11 deletions cal_lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,23 @@

/**
* Functions for creating hislsf calendar instances
* @package local_lsf_unification
*
* @package local_lsf_unification
* @copyright 2025 Tamaro Walter
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
if (!defined('MOODLE_INTERNAL')) {
die('Direct access to this script is forbidden.'); // It must be included from a Moodle page
}

define("HIS_CAL_IDENTIFIER", "hislsf");
defined('MOODLE_INTERNAL') || die();

define("HIS_CAL_IDENTIFIER", "hislsf");
global $CFG;
require_once($CFG->dirroot . '/calendar/lib.php');
require_once($CFG->libdir . '/bennu/bennu.inc.php');

/**
* Returns the CURRENT (because of the event ids instead of the user id being appended this URL changes when users subscribe to new events) userspecific ICal-URL
* Returns the CURRENT (because of the event ids instead of the user id being appended this URL changes when users
* subscribe to new events) userspecific ICal-URL
*
* @param unknown_type $userid
* @package local_lsf_unification
*/
Expand Down Expand Up @@ -56,7 +60,9 @@ function create_default_his_subscription() {
}

/**
* Checks if a hislsf calendar instance already exists for the current user. If it doesn't find one, then it tries to create a new one.
* Checks if a hislsf calendar instance already exists for the current user.
* If it doesn't find one, then it tries to create a new one.
* @throws moodle_exception
* @package local_lsf_unification
*/
function his_add_cal() {
Expand All @@ -71,7 +77,7 @@ function his_add_cal() {
} catch (moodle_exception $e) {
// Delete newly added subscription and show invalid url error.
calendar_delete_subscription($subscriptionid);
print_error($e->errorcode, $e->module, $PAGE->url);
throw new moodle_exception($e->errorcode, $e->module, $PAGE->url);
}
}

Expand All @@ -87,17 +93,20 @@ function his_already_imported_cal() {

/**
* Adds a link to "cal_import.php" to the form
* @param $mform
* @param MoodleQuickForm $mform
* @return void
* @package local_lsf_unification
*/
function his_print_cal_import_form($mform) {
function his_print_cal_import_form(MoodleQuickForm $mform): void {
global $PAGE, $CFG;
if (his_already_imported_cal()) {
return;
}
if (getSSONo() < 0) {
return;
}
$href = $CFG->wwwroot . '/local/lsf_unification/cal_import.php?back=' . urlencode($PAGE->url);
$importical = get_string('importical', 'local_lsf_unification');
$mform->addElement('header', 'addhissubscriptionform', get_string('importcalendar', 'local_lsf_unification'));
$mform->addElement('html', '<a class="btn" href="' . $CFG->wwwroot . '/local/lsf_unification/cal_import.php?back=' . urlencode($PAGE->url) . '">' . get_string('importical', 'local_lsf_unification') . '</a>');
$mform->addElement('html', '<a class="btn" href="' . $href . '">' . $importical . '</a>');
}
37 changes: 34 additions & 3 deletions class_pg_lite.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,52 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.

defined('MOODLE_INTERNAL') || die;
/**
* Class for database connection.
* @package local_lsf_unification
* @copyright 2025 Tamaro Walter
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace local_lsf_unification;

/**
* Class that wraps a connection to psql.
* @package local_lsf_unification
* @copyright 2025 Tamaro Walter
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class pg_lite {
/** @var null Represents the connection. */
public $connection = null;

/**
* Connect to psql.
* @return bool|string
* @throws dml_exception
*/
public function connect() {
$config = "host='" . get_config('local_lsf_unification', 'dbhost') . "' port ='" . get_config('local_lsf_unification', 'dbport') . "' user='" . get_config('local_lsf_unification', 'dbuser') . "' password='" . get_config('local_lsf_unification', 'dbpass') . "' dbname='" . get_config('local_lsf_unification', 'dbname') . "'";
// Build the configuration of the connection to the PostgreSQL database.
$host = get_config('local_lsf_unification', 'dbhost');
$port = get_config('local_lsf_unification', 'dbport');
$user = get_config('local_lsf_unification', 'dbuser');
$pass = get_config('local_lsf_unification', 'dbpass');
$name = get_config('local_lsf_unification', 'dbname');
$config = "host='" . $host . "' port ='" . $port . "' user='" . $user . "' password='" . $pass . "' dbname='" . $name . "'";

ob_start();
$this->connection = pg_connect($config, PGSQL_CONNECT_FORCE_NEW);
$dberr = ob_get_contents();
ob_end_clean();
echo $dberr;
return ((pg_connection_status($this->connection) === false) || (pg_connection_status($this->connection) === PGSQL_CONNECTION_BAD)) ? $dberr : true;
$failedconnection = (pg_connection_status($this->connection) == false)
|| (pg_connection_status($this->connection) === PGSQL_CONNECTION_BAD);
return ($failedconnection) ? $dberr : true;
}

/**
* Dispose connection to psql.
* @return void
*/
public function dispose() {
if ($this->connection) {
pg_close($this->connection);
Expand Down
30 changes: 27 additions & 3 deletions classes/event/course_duplicated.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace local_lsf_unification\event;
defined('MOODLE_INTERNAL') || die();
/**
* The matchingtableupdated event class.
*
Expand All @@ -31,20 +30,45 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
**/
class course_duplicated extends \core\event\base {
/**
* Init function.
*
* @return void
*/
protected function init() {
$this->data['crud'] = 'c'; // c(reate), r(ead), u(pdate), d(elete)
$this->data['crud'] = 'c';
$this->data['edulevel'] = self::LEVEL_TEACHING;
$this->data['objecttable'] = 'course';
}

/**
* Return the event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventcourse_duplicated', 'local_lsf_unification');
}

/**
* Return the event description.
*
* @return string
*/
public function get_description() {
return "The user with id '{$this->userid}' duplicated contents from course with id '{$this->other}' into a course with id '{$this->objectid}'.";
$params = (object) [
'userid' => $this->userid,
'other' => $this->other,
'objectid' => $this->objectid,
];
return get_string('eventcourse_duplicated_desc', 'local_lsf_unification', $params);
}

/**
* Return the event url.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/course/view.php', ['id' => $this->objectid]);
}
Expand Down
33 changes: 30 additions & 3 deletions classes/event/course_imported.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace local_lsf_unification\event;
defined('MOODLE_INTERNAL') || die();

/**
* The matchingtableupdated event class.
*
Expand All @@ -31,20 +31,47 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
**/
class course_imported extends \core\event\base {
/**
* Init function.
*
* @return void
*/
protected function init() {
$this->data['crud'] = 'c'; // c(reate), r(ead), u(pdate), d(elete)
$this->data['crud'] = 'c';
$this->data['edulevel'] = self::LEVEL_TEACHING;
$this->data['objecttable'] = 'course';
}

/**
* Return the event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventcourse_imported', 'local_lsf_unification');
}


/**
* Return the event description.
*
* @return string
*/
public function get_description() {
return "The user with id '{$this->userid}' imported the HISLSF-course with veranstid '{$this->other}' as a new moodle course with id '{$this->objectid}'.";
$params = (object) [
'userid' => $this->userid,
'other' => $this->other,
'objectid' => $this->objectid,
];
return get_string('eventcourse_imported_desc', 'local_lsf_unification', $params);
}


/**
* Return the event url.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/course/view.php', ['id' => $this->objectid]);
}
Expand Down
42 changes: 34 additions & 8 deletions classes/event/matchingtable_updated.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace local_lsf_unification\event;
defined('MOODLE_INTERNAL') || die();
use core\exception\moodle_exception;
use moodle_url;

/**
* The matchingtableupdated event class.
*
Expand All @@ -31,21 +33,45 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
**/
class matchingtable_updated extends \core\event\base {
protected function init() {
$this->data['crud'] = 'u'; // c(reate), r(ead), u(pdate), d(elete)
/**
* Init function.
* @return void
*/
protected function init(): void {
$this->data['crud'] = 'u';
$this->data['edulevel'] = self::LEVEL_OTHER;
$this->data['objecttable'] = 'local_lsf_category';
}

public static function get_name() {
/**
* Returns the event name.
* @return string
* @throws \coding_exception
*/
public static function get_name(): string {
return get_string('eventmatchingtable_updated', 'local_lsf_unification');
}

public function get_description() {
return "The user with id '{$this->userid}' updated a his category matching with id '{$this->objectid}'. Original mapping: '{$this->other["mappingold"]}'. New mapping: '{$this->other["mappingnew"]}'.";
/**
* Returns the event description.
* @return string
*/
public function get_description(): string {
$params = (object) [
'userid' => $this->userid,
'objectid' => $this->objectid,
'mappingold' => $this->other["mappingold"],
'mappingnew' => $this->other["mappingnew"],
];
return get_string('eventmatchingtable_updated', 'local_lsf_unification', $params);
}

public function get_url() {
return new \moodle_url('/local/lsf_unification/helptablemanager.php', ['originid' => $this->other["originid"]]);
/**
* Return the event url
* @return moodle_url
* @throws moodle_exception
*/
public function get_url(): moodle_url {
return new moodle_url('/local/lsf_unification/helptablemanager.php', ['originid' => $this->other["originid"]]);
}
}
3 changes: 1 addition & 2 deletions classes/output/first_overview.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class first_overview implements renderable, templatable {

/**
* Constructor for first_overview.
*
Expand All @@ -43,7 +42,7 @@ public function __construct(

#[\Override]
public function export_for_template(renderer_base $output): stdClass {
$courselist = array_map(function($course) {
$courselist = array_map(function ($course) {
return (object) ["title" => $course->info];
}, array_values($this->courses));
$showremotecreation = get_config("local_lsf_unification", "remote_creation");
Expand Down
Loading
Loading