Skip to content

Commit 8477b39

Browse files
committed
Tool timetable plugin support improved - TIME-55.
1 parent 7eaafbd commit 8477b39

File tree

5 files changed

+40
-25
lines changed

5 files changed

+40
-25
lines changed

classes/options.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -263,16 +263,23 @@ public static function get_file_areas($structure='module') {
263263
}
264264

265265
/**
266-
* Get timemanagement tools due date for the module.
266+
* Get tool timetable due date for the module.
267267
*
268268
* @param cm_info $cm
269269
* @return int|bool Mod due date if available otherwiser returns false.
270270
*/
271271
public static function timetool_duedate($cm) {
272-
global $USER;
273-
if (format_designer_timemanagement_installed() && function_exists('ltool_timemanagement_get_mod_user_info')) {
274-
$data = ltool_timemanagement_get_mod_user_info($cm, $USER->id);
275-
return $data['duedate'] ?? false;
272+
global $USER, $DB;
273+
if (format_designer_timetable_installed()) {
274+
$record = $DB->get_record('tool_timetable_modules', ['cmid' => $cm->id ?? 0]);
275+
if ($record) {
276+
$timemanagement = new \tool_timetable\time_management($cm->course);
277+
$userenrolments = $timemanagement->get_course_user_enrollment($USER->id, $cm->course);
278+
$timestarted = $userenrolments[0]['timestart'] ?? 0;
279+
$timeended = $userenrolments[0]['timeend'] ?? 0;
280+
$moduledates = $timemanagement->calculate_coursemodule_managedates($record, $timestarted, $timeended);
281+
return $moduledates['duedate'] ?? false;
282+
}
276283
}
277284
return false;
278285
}

classes/output/renderer.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -504,11 +504,16 @@ public function course_header_metadata_details(\stdClass $course, bool $dataonly
504504
];
505505
}
506506

507-
// Find the course due date. only if the timemanagement installed.
508-
if (format_designer_timemanagement_installed() && function_exists('ltool_timemanagement_cal_course_duedate')) {
509-
$coursedatesinfo = $DB->get_record('ltool_timemanagement_course', ['course' => $course->id]);
510-
if ($courseduedate && $coursedatesinfo) {
511-
$data['courseduedate'] = ltool_timemanagement_cal_course_duedate($coursedatesinfo, $enrolstartdate);
507+
// Find the course due date. only if the timetable installed.
508+
if (format_designer_timetable_installed()) {
509+
if ($courseduedate && ($timecourse = $DB->get_record('tool_timetable_course', ['course' => $course->id]))) {
510+
$timemanagement = new \tool_timetable\time_management($timecourse->course);
511+
// Get user enrolment info in course.
512+
$usercourseenrollinfo = $timemanagement->get_course_user_enrollment($USER->id);
513+
$startdate = $usercourseenrollinfo[0]['timestart'] ?? 0;
514+
$enddate = $usercourseenrollinfo[0]['timeend'] ?? 0;
515+
$coursedue = $timemanagement->calculate_course_duedate($startdate, $enddate, $USER->id);
516+
$data['courseduedate'] = $coursedue ?? false;
512517
}
513518
}
514519

lang/en/format_designer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@
460460
$string['timeagosecond'] = 'second';
461461
$string['timeagoweek'] = 'week';
462462
$string['timeagoyear'] = 'year';
463-
$string['timemanagementmissing'] = 'Learning Tools Pro required for this feature. <a href="https://bdecent.de/product/learning-tools-pro/">Learn more</a>.';
463+
$string['timemanagementmissing'] = 'Tools timetable required for this feature.';
464464
$string['title'] = "Title";
465465
$string['todaydue'] = '{$a->due} due today';
466466
$string['trimmed'] = 'Trimmed';

lib.php

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,7 @@ public static function course_format_options_list($foreditform = false) {
824824
];
825825
}
826826

827-
if (format_designer_timemanagement_installed()) {
827+
if (format_designer_timetable_installed()) {
828828
$courseformatoptionsedit['courseduedateinfo'] = [
829829
'element_type' => 'hidden',
830830
];
@@ -2053,21 +2053,24 @@ function format_designer_coursemodule_edit_post_actions($data, $course) {
20532053
}
20542054

20552055
/**
2056-
* Find the time management tool installed and enabled in the learningtools.
2056+
* Find the timetable tool installed.
20572057
*
2058-
* @return bool result of the time management plugin availability.
2058+
* @return bool result of the timetable plugin availability.
20592059
*/
2060-
function format_designer_timemanagement_installed() {
2061-
global $DB, $CFG;
2062-
$tools = \core_plugin_manager::instance()->get_subplugins_of_plugin('local_learningtools');
2063-
if (in_array('ltool_timemanagement', array_keys($tools))) {
2064-
$status = $DB->get_field('local_learningtools_products', 'status', ['shortname' => 'timemanagement']);
2065-
if ($status) {
2066-
require_once($CFG->dirroot.'/local/learningtools/ltool/timemanagement/lib.php');
2060+
function format_designer_timetable_installed() {
2061+
global $CFG;
2062+
static $result;
2063+
2064+
if ($result == null) {
2065+
if (array_key_exists('timetable', \core_component::get_plugin_list('tool'))) {
2066+
require_once($CFG->dirroot.'/admin/tool/timetable/classes/time_management.php');
2067+
$result = true;
2068+
} else {
2069+
$result = false;
2070+
}
20672071
}
2068-
return ($status) ? true : false;
2069-
}
2070-
return false;
2072+
2073+
return $result;
20712074
}
20722075

20732076

version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
defined('MOODLE_INTERNAL') || die();
2626

27-
$plugin->version = 2025080200; // The current plugin version (Date: YYYYMMDDXX).
27+
$plugin->version = 2025080201; // The current plugin version (Date: YYYYMMDDXX).
2828
$plugin->requires = 2020061500; // Requires this Moodle version.
2929
$plugin->component = 'format_designer'; // Full name of the plugin (used for diagnostics).
3030
$plugin->release = 'Version 1.7';

0 commit comments

Comments
 (0)