. /** * Library of interface functions and constants. * * @package mod_timetable * @copyright 2020 Raphael Dannecker * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); /** * Return if the plugin supports $feature. * * @param string $feature Constant representing the feature. * @return true | null True if the feature is supported, null otherwise. */ function timetable_supports($feature) { switch ($feature) { case FEATURE_MOD_INTRO: return true; default: return null; } } /** * Saves a new instance of the mod_timetable into the database. * * Given an object containing all the necessary data, (defined by the form * in mod_form.php) this function will create a new instance and return the id * number of the instance. * * @param object $moduleinstance An object from the form. * @param mod_timetable_mod_form $mform The form. * @return int The id of the newly inserted record. */ function timetable_add_instance($moduleinstance, $mform = null) { global $DB; $moduleinstance->timecreated = time(); $id = $DB->insert_record('timetable', $moduleinstance); return $id; } /** * Updates an instance of the mod_timetable in the database. * * Given an object containing all the necessary data (defined in mod_form.php), * this function will update an existing instance with new data. * * @param object $moduleinstance An object from the form in mod_form.php. * @param mod_timetable_mod_form $mform The form. * @return bool True if successful, false otherwise. */ function timetable_update_instance($moduleinstance, $mform = null) { global $DB; $moduleinstance->timemodified = time(); $moduleinstance->id = $moduleinstance->instance; return $DB->update_record('timetable', $moduleinstance); } /** * Removes an instance of the mod_timetable from the database. * * @param int $id Id of the module instance. * @return bool True if successful, false on failure. */ function timetable_delete_instance($id) { global $DB; $exists = $DB->get_record('timetable', array('id' => $id)); if (!$exists) { return false; } $DB->delete_records('timetable', array('id' => $id)); return true; }