Skip to content

Commit

Permalink
more config options + other small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
my-curiosity committed Jan 19, 2024
1 parent 2addadf commit 3e5cbcc
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 18 deletions.
41 changes: 32 additions & 9 deletions block_overviewmyrolesincourses.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,20 +183,22 @@ public function get_courses_enroled_with_roleid(
$enroledcoursewithrole->courseshortname = $enroledcourse->shortname;
$enroledcoursewithrole->coursefullname = $enroledcourse->fullname;
$enroledcoursewithrole->visible = $enroledcourse->visible;
$enroledcoursewithrole->favourite = in_array($enroledcourse->id, $favouritecourseids) ? true : false;
$enroledcoursewithrole->favourite = in_array($enroledcourse->id, $favouritecourseids);

// Add additional information like url to the course, ...
$url = new moodle_url('/course/view.php', ['id' => $enroledcourse->id]);
$urldelete = new moodle_url('/course/delete.php', ['id' => $enroledcourse->id]);
$enroledcoursewithrole->url = $url->__toString();
$enroledcoursewithrole->urldelete = $urldelete->__toString();
$enroledcoursewithrole->dimmed = $dimmed;
$enroledcoursewithrole->duration = $this->create_duration($enroledcourse)->duration;
$enroledcoursewithrole->durationstatus = $this->create_duration($enroledcourse)->durationstatus;

$cssselectordurationstatusofcourse = $this->create_duration($enroledcourse)->cssselectordurationstatusofcourse;
$enroledcoursewithrole->cssselectordurationstatusofcourse = $cssselectordurationstatusofcourse;
$enroledcoursewithrole->cssselectordurationstatusofcourse =
$this->create_duration($enroledcourse)->cssselectordurationstatusofcourse;
$enroledcoursewithrole->showdeleteicon = $showdeleteicon;
$enroledcoursewithrole->usetimeranges = $this->config->usetimeranges;
$enroledcoursewithrole->usecategories = $this->config->usecategories;
$enroledcoursewithrole->duration = $this->create_duration($enroledcourse)->duration;
$enroledcoursewithrole->category = $this->create_category($enroledcourse);

$result[] = $enroledcoursewithrole;
}
Expand Down Expand Up @@ -237,6 +239,7 @@ private function create_duration(stdClass $course): stdClass {
}

$result = new stdClass();
$result->duration = "$startdate - $enddate";
// Documentation of code: if ($course->startdate <= $now) {.
if ($courserecord->startdate <= $now) {
if ($courserecord->enddate > $now || !$courserecord->enddate) {
Expand All @@ -250,16 +253,35 @@ private function create_duration(stdClass $course): stdClass {
$result->cssselectordurationstatusofcourse = 'overviewmyrolesincourses-coursefuture';
$result->durationstatus = self::DURATIONSTATUS_FUTURE;
}
return $result;
}

/**
* Returns top level course category name as a string.
*
* @param stdClass $course course used
* @return string top level course category name
* @throws coding_exception
* @throws dml_exception
*/
private function create_category(stdClass $course): string {
global $DB;
$courserecord = $DB->get_record('course', ['id' => $course->id]);
$coursecontext = context_course::instance($course->id);

if ($this->config->usecategories && $courserecord->category != 0) {
if ($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;
if ($topcategory->visible == 1 || has_capability('moodle/category:viewhiddencategories', $coursecontext)){
return $topcategory->name;
}
else {
return get_string('categoryhidden');
}
} else {
$result->duration = "$startdate - $enddate";
return get_string('categoryhidden');
}
return $result;
}

/**
Expand Down Expand Up @@ -330,6 +352,7 @@ public function instance_create() {
'showfuture' => get_config('block_overviewmyrolesincourses', 'defaultshowfuture'),
'onlyfavourite' => get_config('block_overviewmyrolesincourses', 'defaultonlyshowfavourite'),
'foldonstart' => get_config('block_overviewmyrolesincourses', 'defaultfoldonstart'),
'usetimeranges' => get_config('block_overviewmyrolesincourses', 'defaultusetimeranges'),
'usecategories' => get_config('block_overviewmyrolesincourses', 'defaultusecategories'),
];
$this->instance_config_save($data);
Expand Down
6 changes: 5 additions & 1 deletion edit_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,12 @@ protected function specific_definition($mform) {
$mform->addElement('advcheckbox', 'config_foldonstart', $name, '', ['group' => 5], [0, 1]);
$mform->setDefault('config_foldonstart', 0);

$name = get_string('usetimeranges', 'block_overviewmyrolesincourses');
$mform->addElement('advcheckbox', 'config_usetimeranges', $name, '', ['group' => 6], [0, 1]);
$mform->setDefault('config_usetimeranges', 1);

$name = get_string('usecategories', 'block_overviewmyrolesincourses');
$mform->addElement('advcheckbox', 'config_usecategories', $name, '', ['group' => 6], [0, 1]);
$mform->addElement('advcheckbox', 'config_usecategories', $name, '', ['group' => 7], [0, 1]);
$mform->setDefault('config_usecategories', 0);
}
}
9 changes: 6 additions & 3 deletions lang/en/block_overviewmyrolesincourses.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,19 @@
$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['defaultusetimeranges'] = 'Default: Show course duration';
$string['defaultusetimeranges_desc'] = 'By default show course duration';
$string['defaultusecategories'] = 'Default: Show course category';
$string['defaultusecategories_desc'] = 'By default show course category';
$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['usetimeranges'] = 'Show course duration';
$string['usecategories'] = 'Show course category';
$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,6 +92,12 @@
get_string('defaultonlyshowfavourite_desc', 'block_overviewmyrolesincourses'),
0
));
$settings->add(new admin_setting_configcheckbox(
'block_overviewmyrolesincourses/defaultusetimeranges',
get_string('defaultusetimeranges', 'block_overviewmyrolesincourses'),
get_string('defaultusetimeranges_desc', 'block_overviewmyrolesincourses'),
1
));
$settings->add(new admin_setting_configcheckbox(
'block_overviewmyrolesincourses/defaultusecategories',
get_string('defaultusecategories', 'block_overviewmyrolesincourses'),
Expand Down
12 changes: 11 additions & 1 deletion styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
background-color: #ddd;
}

.overviewmyrolesincourses-bg-guest {
div[class*="overviewmyrolesincourses-bg-"]:not([class*="manager"]):not([class*="editingteacher"]):not([class*="teacher"]):not([class*="student"]) {
background-color: #eee;
}

Expand Down Expand Up @@ -64,6 +64,16 @@
padding-right: 10px;
}

.row.category {
margin-left: 0;
}
.row.category .col-8 {
padding-left: 0;
}
.row.category .col-4 {
padding-right: 10px;
}

.overviewmyrolesincourses-tools {
text-align: right;
}
Expand Down
40 changes: 36 additions & 4 deletions templates/overviewmyrolesincourses.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@
"dimmed": "",
"duration": "19\/08\/30 - 19\/08\/40",
"cssselectordurationstatusofcourse": "overviewmyrolesincourses-coursefuture",
"showdeleteicon": "1"
"showdeleteicon": "1",
"category": "Category 1",
"usetimeranges": true,
"usecategories": false
},
{
"roleid": "3",
Expand All @@ -52,7 +55,10 @@
"dimmed": "",
"duration": "23\/07\/21 - 24\/07\/23",
"cssselectordurationstatusofcourse": "overviewmyrolesincourses-courseinprogress",
"showdeleteicon": "1"
"showdeleteicon": "1",
"category": "Category 2",
"usetimeranges": false,
"usecategories": true
},
{
"roleid": "3",
Expand All @@ -68,7 +74,10 @@
"dimmed": "dimmed",
"duration": "23\/07\/21 - 24\/07\/22",
"cssselectordurationstatusofcourse": "overviewmyrolesincourses-coursefinished",
"showdeleteicon": "1"
"showdeleteicon": "1",
"category": "Category 3",
"usetimeranges": true,
"usecategories": true
}
]
}
Expand All @@ -82,7 +91,7 @@
}
</script>
<div class="border p-2 overviewmyrolesincourses-bg-{{roleshortname}}" onclick="myFunction{{roleshortname}}()">
{{rolelocalname}} {{counter}} {{courses}}
{{rolelocalname}} : {{counter}} {{courses}}
</div>
<div id="overviewmyrolesincourses-visibility-{{roleshortname}}"
class="{{#foldonstart}}overviewmyrolesincourses-foldonstart{{/foldonstart}}">
Expand All @@ -94,6 +103,7 @@
<i class="icon fa fa-graduation-cap fa-fw"></i>{{coursefullname}}
</a>
</div>
{{#usetimeranges}}
<div class="row duration">
<div class="{{dimmed}} col-8">
{{duration}}
Expand All @@ -111,6 +121,28 @@
{{/showdeleteicon}}
</div>
</div>
{{/usetimeranges}}
{{#usecategories}}
<div class="row category">
<div class="{{dimmed}} col-8">
{{category}}
</div>
{{^usetimeranges}}
<div class="col-4 overviewmyrolesincourses-tools">
{{#favourite}}
{{/favourite}}
{{^dimmed}}<span><i class="fa fa-eye" aria-hidden="true"></i></span>{{/dimmed}}
{{#dimmed}}<span><i class="fa fa-eye-slash" aria-hidden="true"></i></span>{{/dimmed}}
{{#showdeleteicon}}
<a href="{{urldelete}}">
<i class="fa fa-trash" aria-hidden="true"></i>
</a>
{{/showdeleteicon}}
</div>
{{/usetimeranges}}
</div>
{{/usecategories}}
</div>
</div>
{{/mylist}}
Expand Down

0 comments on commit 3e5cbcc

Please sign in to comment.