Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Categories display option, small improvements #10

Closed
Closed
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
60 changes: 44 additions & 16 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 @@ -236,27 +238,51 @@ private function create_duration(stdClass $course): stdClass {
$enddate = get_string('noenddate', 'block_overviewmyrolesincourses') . ' ';
}

$cssselectordurationstatusofcourse = '';
$result = new stdClass();
$result->duration = "$startdate - $enddate";
// 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;
}
$result = new stdClass();
$result->duration = "$startdate - $enddate";
$result->cssselectordurationstatusofcourse = $cssselectordurationstatusofcourse;
$result->durationstatus = $durationstatus;
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 ($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]]);
if ($topcategory->visible == 1 || has_capability('moodle/category:viewhiddencategories', $coursecontext)) {
return $topcategory->name;
} else {
return get_string('categoryhidden');
}
} else {
return get_string('categoryhidden');
}
}

/**
* Generates the html code to explain the used colors for past, in progress and courses that start in the future.
*
Expand Down Expand Up @@ -325,6 +351,8 @@ 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);
return true;
Expand Down
8 changes: 8 additions & 0 deletions edit_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,13 @@ 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('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' => 7], [0, 1]);
$mform->setDefault('config_usecategories', 0);
}
}
6 changes: 6 additions & 0 deletions lang/en/block_overviewmyrolesincourses.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +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['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['usetimeranges'] = 'Show course duration';
$string['usecategories'] = 'Show course category';
$string['overviewmyrolesincourses:myaddinstance'] = 'myaddinstance';
$string['overviewmyrolesincourses:addinstance'] = 'addinstance';
$string['overviewmyrolesincourses:viewcontent'] = 'viewcontent';
Expand Down
12 changes: 12 additions & 0 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,16 @@
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'),
get_string('defaultusecategories_desc', 'block_overviewmyrolesincourses'),
0
));
}
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
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';