moodle-an-hochschulen / moodle-theme_boost_campus

Moodle 3.x Boost child theme which is intended to meet the needs of university campuses and adds several features and improvements ––– for Moodle 4.x please use our Theme Boost Union
GNU General Public License v3.0
38 stars 25 forks source link

Feature: Course Manager List #6

Closed sennewood closed 6 years ago

sennewood commented 7 years ago

In our old 2.7 custom theme we created a section to show some roles which people are managing a specific course section:

kursverwalter

Here is our 2.7 code of _../ourtheme/renderers/courserenderer.php:

        $user_string = "";
        $list_container = [];
        $list_con_counter = 0;
        $chelper = new coursecat_helper();
        $set_flag = FALSE;
        $userroles = Array();
        if ($category != null || $category != 0) {
            $coursecontext = context_coursecat::instance($category); //aktueller context
            if (has_capability('moodle/course:create', $coursecontext)) {
                $category_information = $DB->get_records('course_categories', array('id' => $category)); //informationen aus dem aktuellen context
                  if ($category_information[$category]->parent != 0) {
                    $userroles_current = $DB->get_records('role_assignments', array('contextid' => $coursecontext->id));
                    if (empty($userroles_current) != true){ array_push($userroles, $userroles_current); }
                    $_category = $category;
                    do {
                        $course_context_parent = context_coursecat::instance($category_information[$_category]->parent);
                        $userroles_parent = $DB->get_records('role_assignments', array('contextid' => $course_context_parent->id));
                        if (empty($userroles_parent) != true) { array_push($userroles, $userroles_parent); }
                        $_category = $category_information[$_category]->parent;
                        $category_information = $DB->get_records('course_categories', array('id' => $_category));
                    } while ($category_information[$_category]->parent != 0);
                    if ($userroles != NULL) {
                        $set_flag = TRUE;
                        $user_string .= "<div class='cate_info_wrapper'><h2>Kursverwalter/-innen:</h2><div class='cate_info_content'><ul>";
                            foreach ($userroles as $user1) {
                                foreach ($user1 as $user) {
                                $user_query = $DB->get_record('user', array('id'=> $user->userid));
                                $user_string .= '<li>' . get_string('name') . ': '. $user_query->firstname . ' '. $user_query->lastname . ' -- '. get_string('username') . 
                                ': ' . $user_query->username . ' -- '. get_string('email') . ": <a href='mailto:" . $user_query->email . "'>" . $user_query->email . '</a></li>';
                                }
                            }
                        $user_string .= "</ul></div></div>";
                     }
                }
                else {
                    $userroles = $DB->get_records('role_assignments', array('contextid' => $coursecontext->id));
                    if ($userroles != NULL) {
                        $set_flag = TRUE;
                        $user_string .= "<div class='cate_info_wrapper'><h2>Kursverwalter/-innen:</h2><div class='cate_info_content'><ul>";

                        foreach ($userroles as $user) {
                            $user_query = $DB->get_record('user', array('id'=> $user->userid));
                            $user_string .= '<li>' . get_string('name') . ': '. $user_query->firstname . ' '. $user_query->lastname . ' -- '. get_string('username') . 
                                ': ' . $user_query->username . ' -- '. get_string('email') . ": <a href='mailto:" . $user_query->email . "'>" . $user_query->email . '</a></li>';
                        }
                        $user_string .= "</ul></div></div>";
                    }
               }
           }
           if ($chelper->get_category_formatted_description($coursecat)) {
               $description = $chelper->get_category_formatted_description($coursecat);
               if ($set_flag == TRUE) {
                   $description .= $user_string;
               }
               $output .= $this->box($description, array('class' => 'generalbox info '));
            }
            else {
                if ($set_flag == TRUE) {
                    $description = $chelper->get_category_formatted_description($coursecat);
                    $description .= $user_string;
                    $output .= $this->box($description, array('class' => 'generalbox info '));
                }

            }
        }

(I didn't wrote this code, don't blame me for hard coded strings ^^)

I now try to port this code into 3.3 and boost, but if you have any ideas to improve this feature, please write a comment.

Kathrin84 commented 7 years ago

Hi Sebastian, do you mean the list of "Dozent/innen" with this issue? I'm not quite sure, because you wrote course section. Sections created within the course. But I assume that you mean whole courses.

I don't think that this is a Boost Campus related issue, but I can point you to our block "People": https://moodle.org/plugins/block_people Maybe this could be a solution for your Moodle instance, too? So you don't have to change the code on the course page. Best, Kathrin

Kathrin84 commented 6 years ago

As there was no reply for half a year now I'll close this issue. Nevertheless, feel free to add further information though if you have any.

sennewood commented 6 years ago

I wrote a plugin for our issue instead: https://github.com/buwzim/moodle-category-manager ;)