Skip to content

Commit

Permalink
add an option to show course categories instead of time ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
my-curiosity committed Jan 2, 2024
1 parent 2acdee6 commit 3979461
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 13 deletions.
28 changes: 17 additions & 11 deletions block_overviewmyrolesincourses.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,24 +236,29 @@ private function create_duration(stdClass $course): stdClass {
$enddate = get_string('noenddate', 'block_overviewmyrolesincourses') . ' ';
}

$cssselectordurationstatusofcourse = '';
$result = new stdClass();
// Documentation of code: if ($course->startdate <= $now) {.
if ($courserecord->startdate <= $now) {
if ($courserecord->enddate > $now || !$courserecord->enddate) {
$cssselectordurationstatusofcourse = 'overviewmyrolesincourses-courseinprogress';
$durationstatus = self::DURATIONSTATUS_INPROGRESS;
$result->cssselectordurationstatusofcourse = 'overviewmyrolesincourses-courseinprogress';
$result->durationstatus = self::DURATIONSTATUS_INPROGRESS;
} else if ($courserecord->enddate < $now) {
$cssselectordurationstatusofcourse = 'overviewmyrolesincourses-coursefinished';
$durationstatus = self::DURATIONSTATUS_PAST;
$result->cssselectordurationstatusofcourse = 'overviewmyrolesincourses-coursefinished';
$result->durationstatus = self::DURATIONSTATUS_PAST;
}
} else {
$cssselectordurationstatusofcourse = 'overviewmyrolesincourses-coursefuture';
$durationstatus = self::DURATIONSTATUS_FUTURE;
$result->cssselectordurationstatusofcourse = 'overviewmyrolesincourses-coursefuture';
$result->durationstatus = self::DURATIONSTATUS_FUTURE;
}

if ($this->config->usecategories && $courserecord->category != 0) {
$category = $DB->get_record("course_categories", ['id' => $courserecord->category]);
$categorypatharray = explode("/", $category->path);
$topcategory = $DB->get_record("course_categories", ['id' => $categorypatharray[1]]);
$result->duration = $topcategory->name;
} else {
$result->duration = "$startdate - $enddate";
}
$result = new stdClass();
$result->duration = "$startdate - $enddate";
$result->cssselectordurationstatusofcourse = $cssselectordurationstatusofcourse;
$result->durationstatus = $durationstatus;
return $result;
}

Expand Down Expand Up @@ -325,6 +330,7 @@ public function instance_create() {
'showfuture' => get_config('block_overviewmyrolesincourses', 'defaultshowfuture'),
'onlyfavourite' => get_config('block_overviewmyrolesincourses', 'defaultonlyshowfavourite'),
'foldonstart' => get_config('block_overviewmyrolesincourses', 'defaultfoldonstart'),
'usecategories' => get_config('block_overviewmyrolesincourses', 'defaultusecategories'),
];
$this->instance_config_save($data);
return true;
Expand Down
4 changes: 4 additions & 0 deletions edit_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,9 @@ protected function specific_definition($mform) {
$name = get_string('foldonstart', 'block_overviewmyrolesincourses');
$mform->addElement('advcheckbox', 'config_foldonstart', $name, '', ['group' => 5], [0, 1]);
$mform->setDefault('config_foldonstart', 0);

$name = get_string('usecategories', 'block_overviewmyrolesincourses');
$mform->addElement('advcheckbox', 'config_usecategories', $name, '', ['group' => 6], [0, 1]);
$mform->setDefault('config_usecategories', 0);
}
}
3 changes: 3 additions & 0 deletions lang/en/block_overviewmyrolesincourses.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,16 @@
$string['defaultshowfuture_desc'] = 'By default show courses that start in future';
$string['defaultonlyshowfavourite'] = 'Default: Favorites only';
$string['defaultonlyshowfavourite_desc'] = 'By default show only favourite courses';
$string['defaultusecategories'] = 'Default: Show categories instead of time ranges';
$string['defaultusecategories_desc'] = 'By default show course categories instead of time ranges';
$string['foldonstart'] = 'Fold courselists on start';
$string['future'] = 'future';
$string['inprogress'] = 'in progress';
$string['isactiv'] = 'Activate report';
$string['isactiv_desc'] = 'If activated the block can be used if the user has the needed capabilities.';
$string['noenddate'] = 'open';
$string['onlyfavourite'] = 'Favorites only';
$string['usecategories'] = 'Show categories instead of time ranges';
$string['overviewmyrolesincourses:myaddinstance'] = 'myaddinstance';
$string['overviewmyrolesincourses:addinstance'] = 'addinstance';
$string['overviewmyrolesincourses:viewcontent'] = 'viewcontent';
Expand Down
6 changes: 6 additions & 0 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,10 @@
get_string('defaultonlyshowfavourite_desc', 'block_overviewmyrolesincourses'),
0
));
$settings->add(new admin_setting_configcheckbox(
'block_overviewmyrolesincourses/defaultusecategories',
get_string('defaultusecategories', 'block_overviewmyrolesincourses'),
get_string('defaultusecategories_desc', 'block_overviewmyrolesincourses'),
0
));
}
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
defined('MOODLE_INTERNAL') || die;

$plugin->maturity = MATURITY_STABLE;
$plugin->version = 2023031100;
$plugin->version = 2023121900;
$plugin->component = 'block_overviewmyrolesincourses';
$plugin->requires = 2017111300;
$plugin->requires = 2022041900; // Requires Moodle version 4.0 or higher.
$plugin->release = 'v1.4.1';

0 comments on commit 3979461

Please sign in to comment.