From 52b0db704ad1249df9498cf5098e4c6c1d766c85 Mon Sep 17 00:00:00 2001 From: Howard Miller Date: Mon, 28 Aug 2017 14:35:26 +0100 Subject: [PATCH 01/29] Now works with font-awesome move icons rather than old images. Prevent javascript breaking in page --- module.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/module.js b/module.js index e900df8..d93315b 100644 --- a/module.js +++ b/module.js @@ -14,8 +14,9 @@ M.block_course_overview.add_handles = function(Y) { var list = Y.Node.all('.course_list .coursebox'); list.each(function(v, k) { // Replace move link and image with move_2d image. - var imagenode = v.one('.course_title .move a img'); - imagenode.setAttribute('src', M.util.image_url(MOVEICON.pix, MOVEICON.component)); + var imagenode = v.one('.course_title .move a .fa-arrows-v'); + imagenode.replaceClass('fa-arrows-v', 'fa-arrows'); + //imagenode.setAttribute('src', M.util.image_url(MOVEICON.pix, MOVEICON.component)); imagenode.addClass('cursor'); v.one('.course_title .move a').replace(imagenode); From d36e82ee8b9e0107d4a5f42d67604f80809612fc Mon Sep 17 00:00:00 2001 From: Howard Miller Date: Mon, 11 Sep 2017 11:36:36 +0100 Subject: [PATCH 02/29] small formatting tidy --- module.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/module.js b/module.js index d93315b..6e5eb29 100644 --- a/module.js +++ b/module.js @@ -13,10 +13,10 @@ M.block_course_overview.add_handles = function(Y) { var list = Y.Node.all('.course_list .coursebox'); list.each(function(v, k) { + // Replace move link and image with move_2d image. var imagenode = v.one('.course_title .move a .fa-arrows-v'); - imagenode.replaceClass('fa-arrows-v', 'fa-arrows'); - //imagenode.setAttribute('src', M.util.image_url(MOVEICON.pix, MOVEICON.component)); + imagenode.replaceClass('fa-arrows-v', 'fa-arrows'); imagenode.addClass('cursor'); v.one('.course_title .move a').replace(imagenode); From 7c1372c467d1013f1c26c3cf9d7bf0ec4dd29bce Mon Sep 17 00:00:00 2001 From: Howard Miller Date: Fri, 13 Oct 2017 14:22:27 +0100 Subject: [PATCH 03/29] Fixing up the behat tests so they now work as an optional plugin. Fixes #4 --- lang/en/block_course_overview.php | 2 +- tests/behat/block_course_overview.feature | 74 +++++++++---------- .../block_course_overview_student.feature | 28 +++++++ tests/behat/quiz_overview.feature | 56 ++++++++------ 4 files changed, 99 insertions(+), 61 deletions(-) create mode 100644 tests/behat/block_course_overview_student.feature diff --git a/lang/en/block_course_overview.php b/lang/en/block_course_overview.php index 4761f0c..90fea6e 100644 --- a/lang/en/block_course_overview.php +++ b/lang/en/block_course_overview.php @@ -61,7 +61,7 @@ $string['showchildrendesc'] = 'Should child courses be listed underneath the main course title?'; $string['showwelcomearea'] = 'Show welcome area'; $string['showwelcomeareadesc'] = 'Show the welcome area above the course list?'; -$string['title'] = 'Course overview'; +$string['title'] = 'Course overview (legacy)'; $string['view_edit_profile'] = '(View and edit your profile.)'; $string['welcome'] = 'Welcome {$a}'; $string['youhavemessages'] = 'You have {$a} unread '; diff --git a/tests/behat/block_course_overview.feature b/tests/behat/block_course_overview.feature index 389b6c5..45f3871 100644 --- a/tests/behat/block_course_overview.feature +++ b/tests/behat/block_course_overview.feature @@ -18,10 +18,13 @@ Feature: View the course overview block on the dashboard and test it's functiona | Course 1 | C1 | 0 | | Course 2 | C2 | CAT1 | | Course 3 | C3 | CAT2 | - - Scenario: View the block by a user without any enrolments - Given I log in as "student1" - Then I should see "No course information to show" in the "Course overview" "block" + And I log in as "student1" + When I press "Customise this page" + And I add the "Course overview (legacy)" block + And I configure the "Course overview (legacy)" block + And I set the field "Region" to "content" + And I press "Save changes" + And I log out Scenario: View the block by a user with several enrolments Given the following "course enrolments" exist: @@ -29,8 +32,8 @@ Feature: View the course overview block on the dashboard and test it's functiona | student1 | C1 | student | | student1 | C2 | student | When I log in as "student1" - Then I should see "Course 1" in the "Course overview" "block" - And I should see "Course 2" in the "Course overview" "block" + Then I should see "Course 1" in the "Course overview (legacy)" "block" + And I should see "Course 2" in the "Course overview (legacy)" "block" Scenario: View the block by a user with several enrolments and limit the number of courses. Given the following "course enrolments" exist: @@ -41,14 +44,14 @@ Feature: View the course overview block on the dashboard and test it's functiona When I log in as "student1" And I press "Customise this page" And I select "1" from the "Number of courses to display:" singleselect - Then I should see "Course 1" in the "Course overview" "block" + Then I should see "Course 1" in the "Course overview (legacy)" "block" And I should see "You have 2 hidden courses" - And I should not see "Course 2" in the "Course overview" "block" - And I should not see "Course 3" in the "Course overview" "block" + And I should not see "Course 2" in the "Course overview (legacy)" "block" + And I should not see "Course 3" in the "Course overview (legacy)" "block" And I follow "Show all courses" - And I should see "Course 1" in the "Course overview" "block" - And I should see "Course 2" in the "Course overview" "block" - And I should see "Course 3" in the "Course overview" "block" + And I should see "Course 1" in the "Course overview (legacy)" "block" + And I should see "Course 2" in the "Course overview (legacy)" "block" + And I should see "Course 3" in the "Course overview (legacy)" "block" Scenario: View the block by a user with several enrolments and an admin set default max courses. Given the following config values are set as admin: @@ -59,12 +62,12 @@ Feature: View the course overview block on the dashboard and test it's functiona | student1 | C2 | student | | student1 | C3 | student | When I log in as "student1" - Then I should see "Course 1" in the "Course overview" "block" - And I should see "Course 2" in the "Course overview" "block" + Then I should see "Course 1" in the "Course overview (legacy)" "block" + And I should see "Course 2" in the "Course overview (legacy)" "block" And I should see "You have 1 hidden course" And I press "Customise this page" And I select "Always show all" from the "Number of courses to display:" singleselect - And I should see "Course 3" in the "Course overview" "block" + And I should see "Course 3" in the "Course overview (legacy)" "block" And I should not see "You have 1 hidden course" Scenario: View the block by a user with several enrolments and an admin enforced maximum displayed courses. @@ -77,8 +80,8 @@ Feature: View the course overview block on the dashboard and test it's functiona | student1 | C2 | student | | student1 | C3 | student | When I log in as "student1" - Then I should see "Course 1" in the "Course overview" "block" - And I should see "Course 2" in the "Course overview" "block" + Then I should see "Course 1" in the "Course overview (legacy)" "block" + And I should see "Course 2" in the "Course overview (legacy)" "block" And I should see "You have 1 hidden course" And I press "Customise this page" And I should not see "Always show all" @@ -88,15 +91,15 @@ Feature: View the course overview block on the dashboard and test it's functiona | showwelcomearea | 1 | block_course_overview | | messaging | 0 | | When I log in as "student1" - Then I should see "Welcome Student" in the "Course overview" "block" - And I should not see "messages" in the "Course overview" "block" + Then I should see "Welcome Student" in the "Course overview (legacy)" "block" + And I should not see "messages" in the "Course overview (legacy)" "block" Scenario: View the block by a user with both the welcome area and messaging enabled. Given the following config values are set as admin: | showwelcomearea | 1 | block_course_overview | When I log in as "student1" - Then I should see "Welcome Student" in the "Course overview" "block" - And I should see "You have no unread messages" in the "Course overview" "block" + Then I should see "Welcome Student" in the "Course overview (legacy)" "block" + And I should see "You have no unread messages" in the "Course overview (legacy)" "block" And I follow "messages" And I should see "No messages" @@ -105,15 +108,8 @@ Feature: View the course overview block on the dashboard and test it's functiona Given the following config values are set as admin: | showwelcomearea | 1 | block_course_overview | And I log in as "student1" - And I should see "Welcome Student" in the "Course overview" "block" - And I should see "You have no unread messages" in the "Course overview" "block" - And I follow "messages" - And I send "This is message 1" message to "Teacher 1" user - And I send "This is message 2" message to "Teacher 1" user - When I log out - And I log in as "teacher1" - Then I should see "Welcome Teacher" in the "Course overview" "block" - And I should see "You have 2 unread messages" in the "Course overview" "block" + And I should see "Welcome Student" + And I should see "You have no unread messages" Scenario: View the block by a user with the parent categories displayed. Given the following config values are set as admin: @@ -124,10 +120,10 @@ Feature: View the course overview block on the dashboard and test it's functiona | student1 | C2 | student | | student1 | C3 | student | When I log in as "student1" - Then I should see "Miscellaneous" in the "Course overview" "block" - And I should see "Category 1" in the "Course overview" "block" - And I should see "Category 2" in the "Course overview" "block" - And I should not see "Category 1 / Category 1" in the "Course overview" "block" + Then I should see "Miscellaneous" in the "Course overview (legacy)" "block" + And I should see "Category 1" in the "Course overview (legacy)" "block" + And I should see "Category 2" in the "Course overview (legacy)" "block" + And I should not see "Category 1 / Category 1" in the "Course overview (legacy)" "block" Scenario: View the block by a user with the full categories displayed. Given the following config values are set as admin: @@ -138,8 +134,8 @@ Feature: View the course overview block on the dashboard and test it's functiona | student1 | C2 | student | | student1 | C3 | student | When I log in as "student1" - Then I should see "Miscellaneous" in the "Course overview" "block" - And I should see "Category 1 / Category 2" in the "Course overview" "block" + Then I should see "Miscellaneous" in the "Course overview (legacy)" "block" + And I should see "Category 1 / Category 2" in the "Course overview (legacy)" "block" @javascript Scenario: View the block by a user with the show children option enabled. @@ -157,6 +153,6 @@ Feature: View the course overview block on the dashboard and test it's functiona | Link course | C1 | And I log out When I log in as "student1" - Then I should see "Course 1" in the "Course overview" "block" - And I should see "Course 2" in the "Course overview" "block" - And I should see "Includes C1" in the "Course overview" "block" + Then I should see "Course 1" in the "Course overview (legacy)" "block" + And I should see "Course 2" in the "Course overview (legacy)" "block" + And I should see "Includes C1" in the "Course overview (legacy)" "block" diff --git a/tests/behat/block_course_overview_student.feature b/tests/behat/block_course_overview_student.feature new file mode 100644 index 0000000..5c6b66b --- /dev/null +++ b/tests/behat/block_course_overview_student.feature @@ -0,0 +1,28 @@ +@block @block_course_overview +Feature: Add the course overview (legacy) block on the dashboard and check it's there + In order to view the course overview (legacy) block on the dashboard + As a user + I can add the block to the dashboard page + + Background: + Given the following "users" exist: + | username | firstname | lastname | email | idnumber | + | student1 | Student | 1 | student1@example.com | S1 | + | teacher1 | Teacher | 1 | teacher1@example.com | T1 | + And the following "categories" exist: + | name | category | idnumber | + | Category 1 | 0 | CAT1 | + | Category 2 | CAT1 | CAT2 | + And I log in as "student1" + + Scenario: Add course overview (legacy) block to page + When I press "Customise this page" + And I add the "Course overview (legacy)" block + And I configure the "Course overview (legacy)" block + And I set the field "Region" to "content" + And I press "Save changes" + Then I should see "Course overview (legacy)" in the "Course overview (legacy)" "block" + And I should see "No course information to show" in the "Course overview (legacy)" "block" + + + diff --git a/tests/behat/quiz_overview.feature b/tests/behat/quiz_overview.feature index c91c551..900d5e3 100644 --- a/tests/behat/quiz_overview.feature +++ b/tests/behat/quiz_overview.feature @@ -52,26 +52,40 @@ Feature: View the quiz being due And quiz "Quiz 2A Future deadline" contains the following questions: | question | page | | First question | 1 | + And I log in as "student1" + When I press "Customise this page" + And I add the "Course overview (legacy)" block + And I configure the "Course overview (legacy)" block + And I set the field "Region" to "content" + And I press "Save changes" + And I log out + And I log in as "student2" + When I press "Customise this page" + And I add the "Course overview (legacy)" block + And I configure the "Course overview (legacy)" block + And I set the field "Region" to "content" + And I press "Save changes" + And I log out Scenario: View my quizzes that are due Given I log in as "student1" When I am on homepage - Then I should see "You have quizzes that are due" in the "Course overview" "block" - And I should see "Quiz 1C Future deadline" in the "Course overview" "block" - And I should see "Quiz 1D Future deadline" in the "Course overview" "block" - And I should see "Quiz 1E Future deadline" in the "Course overview" "block" - And I should not see "Quiz 1A No deadline" in the "Course overview" "block" - And I should not see "Quiz 1B Past deadline" in the "Course overview" "block" - And I should not see "Quiz 2A Future deadline" in the "Course overview" "block" + Then I should see "You have quizzes that are due" in the "Course overview (legacy)" "block" + And I should see "Quiz 1C Future deadline" in the "Course overview (legacy)" "block" + And I should see "Quiz 1D Future deadline" in the "Course overview (legacy)" "block" + And I should see "Quiz 1E Future deadline" in the "Course overview (legacy)" "block" + And I should not see "Quiz 1A No deadline" in the "Course overview (legacy)" "block" + And I should not see "Quiz 1B Past deadline" in the "Course overview (legacy)" "block" + And I should not see "Quiz 2A Future deadline" in the "Course overview (legacy)" "block" And I log out And I log in as "student2" - And I should see "You have quizzes that are due" in the "Course overview" "block" - And I should not see "Quiz 1C Future deadline" in the "Course overview" "block" - And I should not see "Quiz 1D Future deadline" in the "Course overview" "block" - And I should not see "Quiz 1E Future deadline" in the "Course overview" "block" - And I should not see "Quiz 1A No deadline" in the "Course overview" "block" - And I should not see "Quiz 1B Past deadline" in the "Course overview" "block" - And I should see "Quiz 2A Future deadline" in the "Course overview" "block" + And I should see "You have quizzes that are due" in the "Course overview (legacy)" "block" + And I should not see "Quiz 1C Future deadline" in the "Course overview (legacy)" "block" + And I should not see "Quiz 1D Future deadline" in the "Course overview (legacy)" "block" + And I should not see "Quiz 1E Future deadline" in the "Course overview (legacy)" "block" + And I should not see "Quiz 1A No deadline" in the "Course overview (legacy)" "block" + And I should not see "Quiz 1B Past deadline" in the "Course overview (legacy)" "block" + And I should see "Quiz 2A Future deadline" in the "Course overview (legacy)" "block" Scenario: View my quizzes that are due and never finished Given I log in as "student1" @@ -84,10 +98,10 @@ Feature: View the quiz being due And I follow "Quiz 1E Future deadline" And I press "Attempt quiz now" When I am on homepage - Then I should see "You have quizzes that are due" in the "Course overview" "block" - And I should see "Quiz 1C Future deadline" in the "Course overview" "block" - And I should see "Quiz 1E Future deadline" in the "Course overview" "block" - And I should not see "Quiz 1A No deadline" in the "Course overview" "block" - And I should not see "Quiz 1B Past deadline" in the "Course overview" "block" - And I should not see "Quiz 1D Future deadline" in the "Course overview" "block" - And I should not see "Quiz 2A Future deadline" in the "Course overview" "block" + Then I should see "You have quizzes that are due" in the "Course overview (legacy)" "block" + And I should see "Quiz 1C Future deadline" in the "Course overview (legacy)" "block" + And I should see "Quiz 1E Future deadline" in the "Course overview (legacy)" "block" + And I should not see "Quiz 1A No deadline" in the "Course overview (legacy)" "block" + And I should not see "Quiz 1B Past deadline" in the "Course overview (legacy)" "block" + And I should not see "Quiz 1D Future deadline" in the "Course overview (legacy)" "block" + And I should not see "Quiz 2A Future deadline" in the "Course overview (legacy)" "block" From e9736399920fc94ca401103ff4fcf375ae2e03f7 Mon Sep 17 00:00:00 2001 From: Howard Miller Date: Thu, 9 Nov 2017 15:26:36 +0000 Subject: [PATCH 04/29] Sorting functions changed from YUI to JQuery AMD --- amd/src/module.js | 35 +++++ classes/renderer.php | 349 +++++++++++++++++++++++++++++++++++++++++++ module.js | 231 ---------------------------- 3 files changed, 384 insertions(+), 231 deletions(-) create mode 100644 amd/src/module.js create mode 100644 classes/renderer.php delete mode 100644 module.js diff --git a/amd/src/module.js b/amd/src/module.js new file mode 100644 index 0000000..6d7c538 --- /dev/null +++ b/amd/src/module.js @@ -0,0 +1,35 @@ +// Javascript module to move courses around + +define(['jquery', 'jqueryui'], function($, UI) { + + return { + init: function() { + + // change non-js links to be inactive + $(".course_title .move a .fa-arrows-v").removeClass("fa-arrows-v").addClass("fa-arrows"); + $(".course_title .move a").removeAttr("href"); + + // Make the course list sort + $(".course_list").sortable({ + update: function(event, ui) { + var kids = $(".course_list").children(); + var sortorder = []; + $.each(kids, function(index, value) { + var id = value.getAttribute('id'); + sortorder[index] = id.substring(7); + }); + + // send new sortorder + var data = { + sesskey : M.cfg.sesskey, + sortorder : sortorder + }; + $.post( + M.cfg.wwwroot+'/blocks/course_overview/save.php', + data + ); + } + }); + } + }; +}); diff --git a/classes/renderer.php b/classes/renderer.php new file mode 100644 index 0000000..80db349 --- /dev/null +++ b/classes/renderer.php @@ -0,0 +1,349 @@ +. + +/** + * course_overview block rendrer + * + * @package block_course_overview + * @copyright 2012 Adam Olley + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +defined('MOODLE_INTERNAL') || die; + +/** + * Course_overview block rendrer + * + * @copyright 2012 Adam Olley + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class block_course_overview_renderer extends plugin_renderer_base { + + /** + * Construct contents of course_overview block + * + * @param array $courses list of courses in sorted order + * @param array $overviews list of course overviews + * @return string html to be displayed in course_overview block + */ + public function course_overview($courses, $overviews) { + $html = ''; + $config = get_config('block_course_overview'); + if ($config->showcategories != BLOCKS_COURSE_OVERVIEW_SHOWCATEGORIES_NONE) { + global $CFG; + require_once($CFG->libdir.'/coursecatlib.php'); + } + $ismovingcourse = false; + $courseordernumber = 0; + $maxcourses = count($courses); + $userediting = false; + // Intialise string/icon etc if user is editing and courses > 1 + if ($this->page->user_is_editing() && (count($courses) > 1)) { + $userediting = true; + //$this->page->requires->js_init_call('M.block_course_overview.add_handles'); + $this->page->requires->js_call_amd('block_course_overview/module', 'init'); + + // Check if course is moving + $ismovingcourse = optional_param('movecourse', FALSE, PARAM_BOOL); + $movingcourseid = optional_param('courseid', 0, PARAM_INT); + } + + // Render first movehere icon. + if ($ismovingcourse) { + // Remove movecourse param from url. + $this->page->ensure_param_not_in_url('movecourse'); + + // Show moving course notice, so user knows what is being moved. + $html .= $this->output->box_start('notice'); + $a = new stdClass(); + $a->fullname = $courses[$movingcourseid]->fullname; + $a->cancellink = html_writer::link($this->page->url, get_string('cancel')); + $html .= get_string('movingcourse', 'block_course_overview', $a); + $html .= $this->output->box_end(); + + $moveurl = new moodle_url('/blocks/course_overview/move.php', + array('sesskey' => sesskey(), 'moveto' => 0, 'courseid' => $movingcourseid)); + // Create move icon, so it can be used. + $name = $courses[$movingcourseid]->fullname; + $movetofirsticon = $this->output->pix_icon('movehere', get_string('movetofirst', 'block_course_overview', $name)); + $moveurl = html_writer::link($moveurl, $movetofirsticon); + $html .= html_writer::tag('div', $moveurl, array('class' => 'movehere')); + } + + foreach ($courses as $key => $course) { + // If moving course, then don't show course which needs to be moved. + if ($ismovingcourse && ($course->id == $movingcourseid)) { + continue; + } + $html .= $this->output->box_start('coursebox ui-state-default', "course-{$course->id}"); + $html .= html_writer::start_tag('div', array('class' => 'course_title')); + // If user is editing, then add move icons. + if ($userediting && !$ismovingcourse) { + $moveicon = $this->output->pix_icon('t/move', get_string('movecourse', 'block_course_overview', $course->fullname)); + $moveurl = new moodle_url($this->page->url, array('sesskey' => sesskey(), 'movecourse' => 1, 'courseid' => $course->id)); + $moveurl = html_writer::link($moveurl, $moveicon); + $html .= html_writer::tag('div', $moveurl, array('class' => 'move')); + + } + + // No need to pass title through s() here as it will be done automatically by html_writer. + $attributes = array('title' => $course->fullname); + if ($course->id > 0) { + if (empty($course->visible)) { + $attributes['class'] = 'dimmed'; + } + $courseurl = new moodle_url('/course/view.php', array('id' => $course->id)); + $coursefullname = format_string(get_course_display_name_for_list($course), true, $course->id); + $link = html_writer::link($courseurl, $coursefullname, $attributes); + $html .= $this->output->heading($link, 2, 'title'); + } else { + $html .= $this->output->heading(html_writer::link( + new moodle_url('/auth/mnet/jump.php', array('hostid' => $course->hostid, 'wantsurl' => '/course/view.php?id='.$course->remoteid)), + format_string($course->shortname, true), $attributes) . ' (' . format_string($course->hostname) . ')', 2, 'title'); + } + $html .= $this->output->container('', 'flush'); + $html .= html_writer::end_tag('div'); + + if (!empty($config->showchildren) && ($course->id > 0)) { + // List children here. + if ($children = block_course_overview_get_child_shortnames($course->id)) { + $html .= html_writer::tag('span', $children, array('class' => 'coursechildren')); + } + } + + // If user is moving courses, then down't show overview. + if (isset($overviews[$course->id]) && !$ismovingcourse) { + $html .= $this->activity_display($course->id, $overviews[$course->id]); + } + + if ($config->showcategories != BLOCKS_COURSE_OVERVIEW_SHOWCATEGORIES_NONE) { + // List category parent or categories path here. + $currentcategory = coursecat::get($course->category, IGNORE_MISSING); + if ($currentcategory !== null) { + $html .= html_writer::start_tag('div', array('class' => 'categorypath')); + if ($config->showcategories == BLOCKS_COURSE_OVERVIEW_SHOWCATEGORIES_FULL_PATH) { + foreach ($currentcategory->get_parents() as $categoryid) { + $category = coursecat::get($categoryid, IGNORE_MISSING); + if ($category !== null) { + $html .= $category->get_formatted_name().' / '; + } + } + } + $html .= $currentcategory->get_formatted_name(); + $html .= html_writer::end_tag('div'); + } + } + + $html .= $this->output->container('', 'flush'); + $html .= $this->output->box_end(); + $courseordernumber++; + if ($ismovingcourse) { + $moveurl = new moodle_url('/blocks/course_overview/move.php', + array('sesskey' => sesskey(), 'moveto' => $courseordernumber, 'courseid' => $movingcourseid)); + $a = new stdClass(); + $a->movingcoursename = $courses[$movingcourseid]->fullname; + $a->currentcoursename = $course->fullname; + $movehereicon = $this->output->pix_icon('movehere', get_string('moveafterhere', 'block_course_overview', $a)); + $moveurl = html_writer::link($moveurl, $movehereicon); + $html .= html_writer::tag('div', $moveurl, array('class' => 'movehere')); + } + } + // Wrap course list in a div and return. + return html_writer::tag('div', $html, array('class' => 'course_list')); + } + + /** + * Coustuct activities overview for a course + * + * @param int $cid course id + * @param array $overview overview of activities in course + * @return string html of activities overview + */ + protected function activity_display($cid, $overview) { + $output = html_writer::start_tag('div', array('class' => 'activity_info')); + foreach (array_keys($overview) as $module) { + $output .= html_writer::start_tag('div', array('class' => 'activity_overview')); + $url = new moodle_url("/mod/$module/index.php", array('id' => $cid)); + $modulename = get_string('modulename', $module); + $icontext = html_writer::link($url, $this->output->image_icon('icon', $modulename, 'mod_'.$module, array('class'=>'iconlarge'))); + if (get_string_manager()->string_exists("activityoverview", $module)) { + $icontext .= get_string("activityoverview", $module); + } else { + $icontext .= get_string("activityoverview", 'block_course_overview', $modulename); + } + + // Add collapsible region with overview text in it. + $output .= $this->collapsible_region($overview[$module], '', 'region_'.$cid.'_'.$module, $icontext, '', true); + + $output .= html_writer::end_tag('div'); + } + $output .= html_writer::end_tag('div'); + return $output; + } + + /** + * Constructs header in editing mode + * + * @param int $max maximum number of courses + * @return string html of header bar. + */ + public function editing_bar_head($max = 0) { + $output = $this->output->box_start('notice'); + + $options = array('0' => get_string('alwaysshowall', 'block_course_overview')); + for ($i = 1; $i <= $max; $i++) { + $options[$i] = $i; + } + $url = new moodle_url('/my/index.php', ['sesskey' => sesskey()]); + $select = new single_select($url, 'mynumber', $options, block_course_overview_get_max_user_courses(), array()); + $select->set_label(get_string('numtodisplay', 'block_course_overview')); + $output .= $this->output->render($select); + + $output .= $this->output->box_end(); + return $output; + } + + /** + * Show hidden courses count + * + * @param int $total count of hidden courses + * @return string html + */ + public function hidden_courses($total) { + if ($total <= 0) { + return; + } + $output = $this->output->box_start('notice'); + $plural = $total > 1 ? 'plural' : ''; + $config = get_config('block_course_overview'); + // Show view all course link to user if forcedefaultmaxcourses is not empty. + if (!empty($config->forcedefaultmaxcourses)) { + $output .= get_string('hiddencoursecount'.$plural, 'block_course_overview', $total); + } else { + $a = new stdClass(); + $a->coursecount = $total; + $a->showalllink = html_writer::link(new moodle_url('/my/index.php', array('mynumber' => block_course_overview::SHOW_ALL_COURSES)), + get_string('showallcourses')); + $output .= get_string('hiddencoursecountwithshowall'.$plural, 'block_course_overview', $a); + } + + $output .= $this->output->box_end(); + return $output; + } + + /** + * Creates collapsable region + * + * @param string $contents existing contents + * @param string $classes class names added to the div that is output. + * @param string $id id added to the div that is output. Must not be blank. + * @param string $caption text displayed at the top. Clicking on this will cause the region to expand or contract. + * @param string $userpref the name of the user preference that stores the user's preferred default state. + * (May be blank if you do not wish the state to be persisted. + * @param bool $default Initial collapsed state to use if the user_preference it not set. + * @return bool if true, return the HTML as a string, rather than printing it. + */ + protected function collapsible_region($contents, $classes, $id, $caption, $userpref = '', $default = false) { + $output = $this->collapsible_region_start($classes, $id, $caption, $userpref, $default); + $output .= $contents; + $output .= $this->collapsible_region_end(); + + return $output; + } + + /** + * Print (or return) the start of a collapsible region, that has a caption that can + * be clicked to expand or collapse the region. If JavaScript is off, then the region + * will always be expanded. + * + * @param string $classes class names added to the div that is output. + * @param string $id id added to the div that is output. Must not be blank. + * @param string $caption text displayed at the top. Clicking on this will cause the region to expand or contract. + * @param string $userpref the name of the user preference that stores the user's preferred default state. + * (May be blank if you do not wish the state to be persisted. + * @param bool $default Initial collapsed state to use if the user_preference it not set. + * @return bool if true, return the HTML as a string, rather than printing it. + */ + protected function collapsible_region_start($classes, $id, $caption, $userpref = '', $default = false) { + // Work out the initial state. + if (!empty($userpref) and is_string($userpref)) { + user_preference_allow_ajax_update($userpref, PARAM_BOOL); + $collapsed = get_user_preferences($userpref, $default); + } else { + $collapsed = $default; + $userpref = false; + } + + if ($collapsed) { + $classes .= ' collapsed'; + } + + $output = ''; + $output .= '
'; + $output .= '
'; + $output .= '
'; + $output .= $caption . ' '; + $output .= '
'; + $this->page->requires->js_init_call('M.block_course_overview.collapsible', array($id, $userpref, get_string('clicktohideshow'))); + + return $output; + } + + /** + * Close a region started with print_collapsible_region_start. + * + * @return string return the HTML as a string, rather than printing it. + */ + protected function collapsible_region_end() { + $output = '
'; + return $output; + } + + /** + * Cretes html for welcome area + * + * @param int $msgcount number of messages + * @return string html string for welcome area. + */ + public function welcome_area($msgcount) { + global $CFG, $USER; + $output = $this->output->box_start('welcome_area'); + + $picture = $this->output->user_picture($USER, array('size' => 75, 'class' => 'welcome_userpicture')); + $output .= html_writer::tag('div', $picture, array('class' => 'profilepicture')); + + $output .= $this->output->box_start('welcome_message'); + $output .= $this->output->heading(get_string('welcome', 'block_course_overview', $USER->firstname)); + + if (!empty($CFG->messaging)) { + $plural = 's'; + if ($msgcount > 0) { + $output .= get_string('youhavemessages', 'block_course_overview', $msgcount); + if ($msgcount == 1) { + $plural = ''; + } + } else { + $output .= get_string('youhavenomessages', 'block_course_overview'); + } + $output .= html_writer::link(new moodle_url('/message/index.php'), + get_string('message'.$plural, 'block_course_overview')); + } + $output .= $this->output->box_end(); + $output .= $this->output->container('', 'flush'); + $output .= $this->output->box_end(); + + return $output; + } +} diff --git a/module.js b/module.js deleted file mode 100644 index 6e5eb29..0000000 --- a/module.js +++ /dev/null @@ -1,231 +0,0 @@ -M.block_course_overview = {} - -M.block_course_overview.add_handles = function(Y) { - M.block_course_overview.Y = Y; - var MOVEICON = { - pix: "i/move_2d", - component: 'moodle' - }; - - YUI().use('dd-constrain', 'dd-proxy', 'dd-drop', 'dd-plugin', function(Y) { - //Static Vars - var goingUp = false, lastY = 0; - - var list = Y.Node.all('.course_list .coursebox'); - list.each(function(v, k) { - - // Replace move link and image with move_2d image. - var imagenode = v.one('.course_title .move a .fa-arrows-v'); - imagenode.replaceClass('fa-arrows-v', 'fa-arrows'); - imagenode.addClass('cursor'); - v.one('.course_title .move a').replace(imagenode); - - var dd = new Y.DD.Drag({ - node: v, - target: { - padding: '0 0 0 20' - } - }).plug(Y.Plugin.DDProxy, { - moveOnEnd: false - }).plug(Y.Plugin.DDConstrained, { - constrain2node: '.course_list' - }); - dd.addHandle('.course_title .move'); - }); - - Y.DD.DDM.on('drag:start', function(e) { - //Get our drag object - var drag = e.target; - //Set some styles here - drag.get('node').setStyle('opacity', '.25'); - drag.get('dragNode').addClass('block_course_overview'); - drag.get('dragNode').set('innerHTML', drag.get('node').get('innerHTML')); - drag.get('dragNode').setStyles({ - opacity: '.5', - borderColor: drag.get('node').getStyle('borderColor'), - backgroundColor: drag.get('node').getStyle('backgroundColor') - }); - }); - - Y.DD.DDM.on('drag:end', function(e) { - var drag = e.target; - //Put our styles back - drag.get('node').setStyles({ - visibility: '', - opacity: '1' - }); - M.block_course_overview.save(Y); - }); - - Y.DD.DDM.on('drag:drag', function(e) { - //Get the last y point - var y = e.target.lastXY[1]; - //is it greater than the lastY var? - if (y < lastY) { - //We are going up - goingUp = true; - } else { - //We are going down. - goingUp = false; - } - //Cache for next check - lastY = y; - }); - - Y.DD.DDM.on('drop:over', function(e) { - //Get a reference to our drag and drop nodes - var drag = e.drag.get('node'), - drop = e.drop.get('node'); - - //Are we dropping on a li node? - if (drop.hasClass('coursebox')) { - //Are we not going up? - if (!goingUp) { - drop = drop.get('nextSibling'); - } - //Add the node to this list - e.drop.get('node').get('parentNode').insertBefore(drag, drop); - //Resize this nodes shim, so we can drop on it later. - e.drop.sizeShim(); - } - }); - - Y.DD.DDM.on('drag:drophit', function(e) { - var drop = e.drop.get('node'), - drag = e.drag.get('node'); - - //if we are not on an li, we must have been dropped on a ul - if (!drop.hasClass('coursebox')) { - if (!drop.contains(drag)) { - drop.appendChild(drag); - } - } - }); - }); -} - -M.block_course_overview.save = function() { - var Y = M.block_course_overview.Y; - var sortorder = Y.one('.course_list').get('children').getAttribute('id'); - for (var i = 0; i < sortorder.length; i++) { - sortorder[i] = sortorder[i].substring(7); - } - var params = { - sesskey : M.cfg.sesskey, - sortorder : sortorder - }; - Y.io(M.cfg.wwwroot+'/blocks/course_overview/save.php', { - method: 'POST', - data: build_querystring(params), - context: this - }); -} - -/** - * Init a collapsible region, see print_collapsible_region in weblib.php - * @param {YUI} Y YUI3 instance with all libraries loaded - * @param {String} id the HTML id for the div. - * @param {String} userpref the user preference that records the state of this box. false if none. - * @param {String} strtooltip - */ -M.block_course_overview.collapsible = function(Y, id, userpref, strtooltip) { - if (userpref) { - M.block_course_overview.userpref = true; - } - Y.use('anim', function(Y) { - new M.block_course_overview.CollapsibleRegion(Y, id, userpref, strtooltip); - }); -}; - -/** - * Object to handle a collapsible region : instantiate and forget styled object - * - * @class - * @constructor - * @param {YUI} Y YUI3 instance with all libraries loaded - * @param {String} id The HTML id for the div. - * @param {String} userpref The user preference that records the state of this box. false if none. - * @param {String} strtooltip - */ -M.block_course_overview.CollapsibleRegion = function(Y, id, userpref, strtooltip) { - // Record the pref name - this.userpref = userpref; - - // Find the divs in the document. - this.div = Y.one('#'+id); - - // Get the caption for the collapsible region - var caption = this.div.one('#'+id + '_caption'); - caption.setAttribute('title', strtooltip); - - // Create a link - var a = Y.Node.create(''); - // Create a local scoped lamba function to move nodes to a new link - var movenode = function(node){ - node.remove(); - a.append(node); - }; - // Apply the lamba function on each of the captions child nodes - caption.get('children').each(movenode, this); - caption.prepend(a); - - // Get the height of the div at this point before we shrink it if required - var height = this.div.get('offsetHeight'); - if (this.div.hasClass('collapsed')) { - // Shrink the div as it is collapsed by default - this.div.setStyle('height', caption.get('offsetHeight')+'px'); - } - - // Create the animation. - var animation = new Y.Anim({ - node: this.div, - duration: 0.3, - easing: Y.Easing.easeBoth, - to: {height:caption.get('offsetHeight')}, - from: {height:height} - }); - - // Handler for the animation finishing. - animation.on('end', function() { - this.div.toggleClass('collapsed'); - }, this); - - // Hook up the event handler. - caption.on('click', function(e, animation) { - e.preventDefault(); - // Animate to the appropriate size. - if (animation.get('running')) { - animation.stop(); - } - animation.set('reverse', this.div.hasClass('collapsed')); - // Update the user preference. - if (this.userpref) { - M.util.set_user_preference(this.userpref, !this.div.hasClass('collapsed')); - } - animation.run(); - }, this, animation); -}; - -M.block_course_overview.userpref = false; - -/** - * The user preference that stores the state of this box. - * @property userpref - * @type String - */ -M.block_course_overview.CollapsibleRegion.prototype.userpref = null; - -/** - * The key divs that make up this - * @property div - * @type Y.Node - */ -M.block_course_overview.CollapsibleRegion.prototype.div = null; - -/** - * The key divs that make up this - * @property icon - * @type Y.Node - */ -M.block_course_overview.CollapsibleRegion.prototype.icon = null; - From 7ef01a3915cee8a38624738e199f8cf2f82d62e5 Mon Sep 17 00:00:00 2001 From: Howard Miller Date: Thu, 9 Nov 2017 15:27:08 +0000 Subject: [PATCH 05/29] renderer moved into classes directory --- renderer.php | 348 --------------------------------------------------- 1 file changed, 348 deletions(-) delete mode 100644 renderer.php diff --git a/renderer.php b/renderer.php deleted file mode 100644 index 6977eca..0000000 --- a/renderer.php +++ /dev/null @@ -1,348 +0,0 @@ -. - -/** - * course_overview block rendrer - * - * @package block_course_overview - * @copyright 2012 Adam Olley - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -defined('MOODLE_INTERNAL') || die; - -/** - * Course_overview block rendrer - * - * @copyright 2012 Adam Olley - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class block_course_overview_renderer extends plugin_renderer_base { - - /** - * Construct contents of course_overview block - * - * @param array $courses list of courses in sorted order - * @param array $overviews list of course overviews - * @return string html to be displayed in course_overview block - */ - public function course_overview($courses, $overviews) { - $html = ''; - $config = get_config('block_course_overview'); - if ($config->showcategories != BLOCKS_COURSE_OVERVIEW_SHOWCATEGORIES_NONE) { - global $CFG; - require_once($CFG->libdir.'/coursecatlib.php'); - } - $ismovingcourse = false; - $courseordernumber = 0; - $maxcourses = count($courses); - $userediting = false; - // Intialise string/icon etc if user is editing and courses > 1 - if ($this->page->user_is_editing() && (count($courses) > 1)) { - $userediting = true; - $this->page->requires->js_init_call('M.block_course_overview.add_handles'); - - // Check if course is moving - $ismovingcourse = optional_param('movecourse', FALSE, PARAM_BOOL); - $movingcourseid = optional_param('courseid', 0, PARAM_INT); - } - - // Render first movehere icon. - if ($ismovingcourse) { - // Remove movecourse param from url. - $this->page->ensure_param_not_in_url('movecourse'); - - // Show moving course notice, so user knows what is being moved. - $html .= $this->output->box_start('notice'); - $a = new stdClass(); - $a->fullname = $courses[$movingcourseid]->fullname; - $a->cancellink = html_writer::link($this->page->url, get_string('cancel')); - $html .= get_string('movingcourse', 'block_course_overview', $a); - $html .= $this->output->box_end(); - - $moveurl = new moodle_url('/blocks/course_overview/move.php', - array('sesskey' => sesskey(), 'moveto' => 0, 'courseid' => $movingcourseid)); - // Create move icon, so it can be used. - $name = $courses[$movingcourseid]->fullname; - $movetofirsticon = $this->output->pix_icon('movehere', get_string('movetofirst', 'block_course_overview', $name)); - $moveurl = html_writer::link($moveurl, $movetofirsticon); - $html .= html_writer::tag('div', $moveurl, array('class' => 'movehere')); - } - - foreach ($courses as $key => $course) { - // If moving course, then don't show course which needs to be moved. - if ($ismovingcourse && ($course->id == $movingcourseid)) { - continue; - } - $html .= $this->output->box_start('coursebox', "course-{$course->id}"); - $html .= html_writer::start_tag('div', array('class' => 'course_title')); - // If user is editing, then add move icons. - if ($userediting && !$ismovingcourse) { - $moveicon = $this->output->pix_icon('t/move', get_string('movecourse', 'block_course_overview', $course->fullname)); - $moveurl = new moodle_url($this->page->url, array('sesskey' => sesskey(), 'movecourse' => 1, 'courseid' => $course->id)); - $moveurl = html_writer::link($moveurl, $moveicon); - $html .= html_writer::tag('div', $moveurl, array('class' => 'move')); - - } - - // No need to pass title through s() here as it will be done automatically by html_writer. - $attributes = array('title' => $course->fullname); - if ($course->id > 0) { - if (empty($course->visible)) { - $attributes['class'] = 'dimmed'; - } - $courseurl = new moodle_url('/course/view.php', array('id' => $course->id)); - $coursefullname = format_string(get_course_display_name_for_list($course), true, $course->id); - $link = html_writer::link($courseurl, $coursefullname, $attributes); - $html .= $this->output->heading($link, 2, 'title'); - } else { - $html .= $this->output->heading(html_writer::link( - new moodle_url('/auth/mnet/jump.php', array('hostid' => $course->hostid, 'wantsurl' => '/course/view.php?id='.$course->remoteid)), - format_string($course->shortname, true), $attributes) . ' (' . format_string($course->hostname) . ')', 2, 'title'); - } - $html .= $this->output->container('', 'flush'); - $html .= html_writer::end_tag('div'); - - if (!empty($config->showchildren) && ($course->id > 0)) { - // List children here. - if ($children = block_course_overview_get_child_shortnames($course->id)) { - $html .= html_writer::tag('span', $children, array('class' => 'coursechildren')); - } - } - - // If user is moving courses, then down't show overview. - if (isset($overviews[$course->id]) && !$ismovingcourse) { - $html .= $this->activity_display($course->id, $overviews[$course->id]); - } - - if ($config->showcategories != BLOCKS_COURSE_OVERVIEW_SHOWCATEGORIES_NONE) { - // List category parent or categories path here. - $currentcategory = coursecat::get($course->category, IGNORE_MISSING); - if ($currentcategory !== null) { - $html .= html_writer::start_tag('div', array('class' => 'categorypath')); - if ($config->showcategories == BLOCKS_COURSE_OVERVIEW_SHOWCATEGORIES_FULL_PATH) { - foreach ($currentcategory->get_parents() as $categoryid) { - $category = coursecat::get($categoryid, IGNORE_MISSING); - if ($category !== null) { - $html .= $category->get_formatted_name().' / '; - } - } - } - $html .= $currentcategory->get_formatted_name(); - $html .= html_writer::end_tag('div'); - } - } - - $html .= $this->output->container('', 'flush'); - $html .= $this->output->box_end(); - $courseordernumber++; - if ($ismovingcourse) { - $moveurl = new moodle_url('/blocks/course_overview/move.php', - array('sesskey' => sesskey(), 'moveto' => $courseordernumber, 'courseid' => $movingcourseid)); - $a = new stdClass(); - $a->movingcoursename = $courses[$movingcourseid]->fullname; - $a->currentcoursename = $course->fullname; - $movehereicon = $this->output->pix_icon('movehere', get_string('moveafterhere', 'block_course_overview', $a)); - $moveurl = html_writer::link($moveurl, $movehereicon); - $html .= html_writer::tag('div', $moveurl, array('class' => 'movehere')); - } - } - // Wrap course list in a div and return. - return html_writer::tag('div', $html, array('class' => 'course_list')); - } - - /** - * Coustuct activities overview for a course - * - * @param int $cid course id - * @param array $overview overview of activities in course - * @return string html of activities overview - */ - protected function activity_display($cid, $overview) { - $output = html_writer::start_tag('div', array('class' => 'activity_info')); - foreach (array_keys($overview) as $module) { - $output .= html_writer::start_tag('div', array('class' => 'activity_overview')); - $url = new moodle_url("/mod/$module/index.php", array('id' => $cid)); - $modulename = get_string('modulename', $module); - $icontext = html_writer::link($url, $this->output->image_icon('icon', $modulename, 'mod_'.$module, array('class'=>'iconlarge'))); - if (get_string_manager()->string_exists("activityoverview", $module)) { - $icontext .= get_string("activityoverview", $module); - } else { - $icontext .= get_string("activityoverview", 'block_course_overview', $modulename); - } - - // Add collapsible region with overview text in it. - $output .= $this->collapsible_region($overview[$module], '', 'region_'.$cid.'_'.$module, $icontext, '', true); - - $output .= html_writer::end_tag('div'); - } - $output .= html_writer::end_tag('div'); - return $output; - } - - /** - * Constructs header in editing mode - * - * @param int $max maximum number of courses - * @return string html of header bar. - */ - public function editing_bar_head($max = 0) { - $output = $this->output->box_start('notice'); - - $options = array('0' => get_string('alwaysshowall', 'block_course_overview')); - for ($i = 1; $i <= $max; $i++) { - $options[$i] = $i; - } - $url = new moodle_url('/my/index.php', ['sesskey' => sesskey()]); - $select = new single_select($url, 'mynumber', $options, block_course_overview_get_max_user_courses(), array()); - $select->set_label(get_string('numtodisplay', 'block_course_overview')); - $output .= $this->output->render($select); - - $output .= $this->output->box_end(); - return $output; - } - - /** - * Show hidden courses count - * - * @param int $total count of hidden courses - * @return string html - */ - public function hidden_courses($total) { - if ($total <= 0) { - return; - } - $output = $this->output->box_start('notice'); - $plural = $total > 1 ? 'plural' : ''; - $config = get_config('block_course_overview'); - // Show view all course link to user if forcedefaultmaxcourses is not empty. - if (!empty($config->forcedefaultmaxcourses)) { - $output .= get_string('hiddencoursecount'.$plural, 'block_course_overview', $total); - } else { - $a = new stdClass(); - $a->coursecount = $total; - $a->showalllink = html_writer::link(new moodle_url('/my/index.php', array('mynumber' => block_course_overview::SHOW_ALL_COURSES)), - get_string('showallcourses')); - $output .= get_string('hiddencoursecountwithshowall'.$plural, 'block_course_overview', $a); - } - - $output .= $this->output->box_end(); - return $output; - } - - /** - * Creates collapsable region - * - * @param string $contents existing contents - * @param string $classes class names added to the div that is output. - * @param string $id id added to the div that is output. Must not be blank. - * @param string $caption text displayed at the top. Clicking on this will cause the region to expand or contract. - * @param string $userpref the name of the user preference that stores the user's preferred default state. - * (May be blank if you do not wish the state to be persisted. - * @param bool $default Initial collapsed state to use if the user_preference it not set. - * @return bool if true, return the HTML as a string, rather than printing it. - */ - protected function collapsible_region($contents, $classes, $id, $caption, $userpref = '', $default = false) { - $output = $this->collapsible_region_start($classes, $id, $caption, $userpref, $default); - $output .= $contents; - $output .= $this->collapsible_region_end(); - - return $output; - } - - /** - * Print (or return) the start of a collapsible region, that has a caption that can - * be clicked to expand or collapse the region. If JavaScript is off, then the region - * will always be expanded. - * - * @param string $classes class names added to the div that is output. - * @param string $id id added to the div that is output. Must not be blank. - * @param string $caption text displayed at the top. Clicking on this will cause the region to expand or contract. - * @param string $userpref the name of the user preference that stores the user's preferred default state. - * (May be blank if you do not wish the state to be persisted. - * @param bool $default Initial collapsed state to use if the user_preference it not set. - * @return bool if true, return the HTML as a string, rather than printing it. - */ - protected function collapsible_region_start($classes, $id, $caption, $userpref = '', $default = false) { - // Work out the initial state. - if (!empty($userpref) and is_string($userpref)) { - user_preference_allow_ajax_update($userpref, PARAM_BOOL); - $collapsed = get_user_preferences($userpref, $default); - } else { - $collapsed = $default; - $userpref = false; - } - - if ($collapsed) { - $classes .= ' collapsed'; - } - - $output = ''; - $output .= '
'; - $output .= '
'; - $output .= '
'; - $output .= $caption . ' '; - $output .= '
'; - $this->page->requires->js_init_call('M.block_course_overview.collapsible', array($id, $userpref, get_string('clicktohideshow'))); - - return $output; - } - - /** - * Close a region started with print_collapsible_region_start. - * - * @return string return the HTML as a string, rather than printing it. - */ - protected function collapsible_region_end() { - $output = '
'; - return $output; - } - - /** - * Cretes html for welcome area - * - * @param int $msgcount number of messages - * @return string html string for welcome area. - */ - public function welcome_area($msgcount) { - global $CFG, $USER; - $output = $this->output->box_start('welcome_area'); - - $picture = $this->output->user_picture($USER, array('size' => 75, 'class' => 'welcome_userpicture')); - $output .= html_writer::tag('div', $picture, array('class' => 'profilepicture')); - - $output .= $this->output->box_start('welcome_message'); - $output .= $this->output->heading(get_string('welcome', 'block_course_overview', $USER->firstname)); - - if (!empty($CFG->messaging)) { - $plural = 's'; - if ($msgcount > 0) { - $output .= get_string('youhavemessages', 'block_course_overview', $msgcount); - if ($msgcount == 1) { - $plural = ''; - } - } else { - $output .= get_string('youhavenomessages', 'block_course_overview'); - } - $output .= html_writer::link(new moodle_url('/message/index.php'), - get_string('message'.$plural, 'block_course_overview')); - } - $output .= $this->output->box_end(); - $output .= $this->output->container('', 'flush'); - $output .= $this->output->box_end(); - - return $output; - } -} From 1f53908aa1f051580501b55740016dbe85ca3bc7 Mon Sep 17 00:00:00 2001 From: Howard Miller Date: Tue, 21 Nov 2017 09:00:33 +0000 Subject: [PATCH 06/29] change to jquery/amd and new features --- amd/src/edit.js | 35 ++++++ amd/src/popup.js | 31 +++++ block_course_overview.php | 24 ++-- classes/output/main.php | 114 ++++++++++++++++++ .../{renderer.php => output/old_renderer.php} | 61 ++-------- classes/output/renderer.php | 45 +++++++ lang/en/block_course_overview.php | 6 +- locallib.php | 49 ++++++++ settings.php | 2 - styles.css | 104 +++++++--------- styles.old.css | 87 +++++++++++++ templates/main.mustache | 104 ++++++++++++++++ tests/behat/block_course_overview.feature | 24 ---- 13 files changed, 539 insertions(+), 147 deletions(-) create mode 100644 amd/src/edit.js create mode 100644 amd/src/popup.js create mode 100644 classes/output/main.php rename classes/{renderer.php => output/old_renderer.php} (82%) create mode 100644 classes/output/renderer.php create mode 100644 styles.old.css create mode 100644 templates/main.mustache diff --git a/amd/src/edit.js b/amd/src/edit.js new file mode 100644 index 0000000..c71420c --- /dev/null +++ b/amd/src/edit.js @@ -0,0 +1,35 @@ +// Javascript module to move courses around + +define(['jquery', 'jqueryui', 'core/config'], function($, UI, mdlconfig) { + + return { + init: function() { + + // change non-js links to be inactive + //$(".course_title .move a .fa-arrows-v").removeClass("fa-arrows-v").addClass("fa-arrows"); + $(".coursebox a").removeAttr("href"); + + // Make the course list sort + $(".course-list").sortable({ + update: function(event, ui) { + var kids = $(".course-list").children(); + var sortorder = []; + $.each(kids, function(index, value) { + var id = value.getAttribute('id'); + sortorder[index] = id.substring(7); + }); + + // send new sortorder + var data = { + sesskey : M.cfg.sesskey, + sortorder : sortorder + }; + $.post( + M.cfg.wwwroot+'/blocks/course_overview/save.php', + data + ); + } + }); + } + }; +}); diff --git a/amd/src/popup.js b/amd/src/popup.js new file mode 100644 index 0000000..8dfcc23 --- /dev/null +++ b/amd/src/popup.js @@ -0,0 +1,31 @@ +// Javascript module to popup dialogue + +define(['jquery', 'jqueryui', 'core/config'], function($, UI, mdlconfig) { + + return { + init: function() { + + // Dialogues on activity icons + $(".dialogue").dialog({ + autoOpen: false, + minWidth: 400, + classes: { + 'ui-dialog': 'course-overview-dialog' + }, + closeText: '', + modal: true + }); + + //opens the appropriate dialog + $(".overview-icon").click(function () { + + //takes the ID of appropriate dialogue + var id = $(this).data('id'); + + //open dialogue + $(id).dialog("open"); + }); + + } + }; +}); diff --git a/block_course_overview.php b/block_course_overview.php index 292a8dc..f4cc40f 100644 --- a/block_course_overview.php +++ b/block_course_overview.php @@ -63,6 +63,8 @@ public function get_content() { $content = array(); + $isediting = $this->page->user_is_editing(); + $updatemynumber = optional_param('mynumber', -1, PARAM_INT); if ($updatemynumber >= 0 && optional_param('sesskey', '', PARAM_RAW) && confirm_sesskey()) { block_course_overview_update_mynumber($updatemynumber); @@ -70,19 +72,25 @@ public function get_content() { profile_load_custom_fields($USER); + // Check if favourite added + $favourite = optional_param('favourite', 0, PARAM_INT); + if ($favourite) { + block_course_overview_add_favourite($favourite); + } + $showallcourses = ($updatemynumber === self::SHOW_ALL_COURSES); list($sortedcourses, $sitecourses, $totalcourses) = block_course_overview_get_sorted_courses($showallcourses); $overviews = block_course_overview_get_overviews($sitecourses); $renderer = $this->page->get_renderer('block_course_overview'); - if (!empty($config->showwelcomearea)) { - require_once($CFG->dirroot.'/message/lib.php'); - $msgcount = message_count_unread_messages(); - $this->content->text = $renderer->welcome_area($msgcount); - } + + // try it + $main = new block_course_overview\output\main($sortedcourses, $overviews, $totalcourses, $isediting); + $this->content->text .= $renderer->render($main); + return $this->content; // Number of sites to display. - if ($this->page->user_is_editing() && empty($config->forcedefaultmaxcourses)) { + if ($isediting && empty($config->forcedefaultmaxcourses)) { $this->content->text .= $renderer->editing_bar_head($totalcourses); } @@ -121,8 +129,6 @@ public function applicable_formats() { * @return bool if true then header will be visible. */ public function hide_header() { - // Hide header if welcome area is show. - $config = get_config('block_course_overview'); - return !empty($config->showwelcomearea); + return false; } } diff --git a/classes/output/main.php b/classes/output/main.php new file mode 100644 index 0000000..7a7bfdd --- /dev/null +++ b/classes/output/main.php @@ -0,0 +1,114 @@ +. + +/** + * Main class for course listing + * + * @package block_course_overview + * @copyright 2017 Howard Miller + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace block_course_overview\output; + +defined('MOODLE_INTERNAL') || die; + +use renderable; +use renderer_base; +use templatable; + +/** + * Class contains data for course_overview + * + * @copyright 2017 Howard Miller + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class main implements renderable, templatable { + + private $sortedcourses; + + private $overviews; + + private $totalcourses; + + private $isediting; + + /** + * Constructor + * @param array $sortedcourses + * @param array $overviews + * @param int $totalcourses + * @param boolean $isediting + */ + public function __construct($sortedcourses, $overviews, $totalcourses, $isediting) { + $this->sortedcourses = $sortedcourses; + $this->overviews = $overviews; + $this->totalcourses = $totalcourses; + $this->isediting = $isediting; + } + + /** + * Export this data so it can be used as the context for a mustache template. + * + * @param \renderer_base $output + * @return stdClass + */ + public function export_for_template(renderer_base $output) { + + // Add extra info (and make zero indexed). + $courselist = []; + foreach ($this->sortedcourses as $course) { + $course->link = new \moodle_url('/course/view.php', array('id' => $course->id)); + $course->favouritelink = new \moodle_url('/my', array('favourite' => $course->id)); + if (!empty($this->overviews[$course->id])) { + $course->hasoverviews = true; + $overviews = array(); + foreach ($this->overviews[$course->id] as $activity => $overview_text) { + $overview = new \stdClass; + $overview->coursename = $course->fullname; + $overview->activity = $activity; + $overview->text = str_replace('p-y-1', '', $overview_text); + $description = get_string('activityoverview', 'block_course_overview', get_string('pluginname', 'mod_' . $activity)); + $overviewid = $activity . '_' . $course->id; + $overview->overviewid = $overviewid; + $overview->icon = $output->pix_icon('icon', $description, 'mod_' . $activity); + $overviews[] = $overview; + } + $course->overviews = $overviews; + } else { + $course->hasoverviews = false; + } + $courselist[] = $course; + } + + // 'courses to show' select box + $options = array('0' => get_string('alwaysshowall', 'block_course_overview')); + for ($i = 1; $i <= $this->totalcourses; $i++) { + $options[$i] = $i; + } + $url = new \moodle_url('/my/index.php', ['sesskey' => sesskey()]); + $select = new \single_select($url, 'mynumber', $options, block_course_overview_get_max_user_courses(), array()); + $select->set_label(get_string('numtodisplay', 'block_course_overview')); + + return [ + 'courses' => $courselist, + 'isediting' => $this->isediting, + 'select' => $output->render($select), + 'viewingfavourites' => false, + ]; + } + +} diff --git a/classes/renderer.php b/classes/output/old_renderer.php similarity index 82% rename from classes/renderer.php rename to classes/output/old_renderer.php index 80db349..788a45a 100644 --- a/classes/renderer.php +++ b/classes/output/old_renderer.php @@ -18,18 +18,25 @@ * course_overview block rendrer * * @package block_course_overview - * @copyright 2012 Adam Olley * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ + +namespace block_course_overview\output; defined('MOODLE_INTERNAL') || die; +use plugin_renderer_base; +use renderable; +use html_writer; +use moodle_url; +use single_select; + /** * Course_overview block rendrer * * @copyright 2012 Adam Olley * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class block_course_overview_renderer extends plugin_renderer_base { +class renderer extends plugin_renderer_base { /** * Construct contents of course_overview block @@ -45,52 +52,20 @@ public function course_overview($courses, $overviews) { global $CFG; require_once($CFG->libdir.'/coursecatlib.php'); } - $ismovingcourse = false; $courseordernumber = 0; $maxcourses = count($courses); $userediting = false; // Intialise string/icon etc if user is editing and courses > 1 if ($this->page->user_is_editing() && (count($courses) > 1)) { $userediting = true; - //$this->page->requires->js_init_call('M.block_course_overview.add_handles'); $this->page->requires->js_call_amd('block_course_overview/module', 'init'); - - // Check if course is moving - $ismovingcourse = optional_param('movecourse', FALSE, PARAM_BOOL); - $movingcourseid = optional_param('courseid', 0, PARAM_INT); - } - - // Render first movehere icon. - if ($ismovingcourse) { - // Remove movecourse param from url. - $this->page->ensure_param_not_in_url('movecourse'); - - // Show moving course notice, so user knows what is being moved. - $html .= $this->output->box_start('notice'); - $a = new stdClass(); - $a->fullname = $courses[$movingcourseid]->fullname; - $a->cancellink = html_writer::link($this->page->url, get_string('cancel')); - $html .= get_string('movingcourse', 'block_course_overview', $a); - $html .= $this->output->box_end(); - - $moveurl = new moodle_url('/blocks/course_overview/move.php', - array('sesskey' => sesskey(), 'moveto' => 0, 'courseid' => $movingcourseid)); - // Create move icon, so it can be used. - $name = $courses[$movingcourseid]->fullname; - $movetofirsticon = $this->output->pix_icon('movehere', get_string('movetofirst', 'block_course_overview', $name)); - $moveurl = html_writer::link($moveurl, $movetofirsticon); - $html .= html_writer::tag('div', $moveurl, array('class' => 'movehere')); } foreach ($courses as $key => $course) { - // If moving course, then don't show course which needs to be moved. - if ($ismovingcourse && ($course->id == $movingcourseid)) { - continue; - } $html .= $this->output->box_start('coursebox ui-state-default', "course-{$course->id}"); $html .= html_writer::start_tag('div', array('class' => 'course_title')); // If user is editing, then add move icons. - if ($userediting && !$ismovingcourse) { + if ($userediting) { $moveicon = $this->output->pix_icon('t/move', get_string('movecourse', 'block_course_overview', $course->fullname)); $moveurl = new moodle_url($this->page->url, array('sesskey' => sesskey(), 'movecourse' => 1, 'courseid' => $course->id)); $moveurl = html_writer::link($moveurl, $moveicon); @@ -123,8 +98,8 @@ public function course_overview($courses, $overviews) { } } - // If user is moving courses, then down't show overview. - if (isset($overviews[$course->id]) && !$ismovingcourse) { + // Show overview + if (isset($overviews[$course->id])) { $html .= $this->activity_display($course->id, $overviews[$course->id]); } @@ -149,16 +124,6 @@ public function course_overview($courses, $overviews) { $html .= $this->output->container('', 'flush'); $html .= $this->output->box_end(); $courseordernumber++; - if ($ismovingcourse) { - $moveurl = new moodle_url('/blocks/course_overview/move.php', - array('sesskey' => sesskey(), 'moveto' => $courseordernumber, 'courseid' => $movingcourseid)); - $a = new stdClass(); - $a->movingcoursename = $courses[$movingcourseid]->fullname; - $a->currentcoursename = $course->fullname; - $movehereicon = $this->output->pix_icon('movehere', get_string('moveafterhere', 'block_course_overview', $a)); - $moveurl = html_writer::link($moveurl, $movehereicon); - $html .= html_writer::tag('div', $moveurl, array('class' => 'movehere')); - } } // Wrap course list in a div and return. return html_writer::tag('div', $html, array('class' => 'course_list')); @@ -296,7 +261,7 @@ protected function collapsible_region_start($classes, $id, $caption, $userpref = $output .= '
'; $output .= $caption . ' '; $output .= '
'; - $this->page->requires->js_init_call('M.block_course_overview.collapsible', array($id, $userpref, get_string('clicktohideshow'))); + // $this->page->requires->js_init_call('M.block_course_overview.collapsible', array($id, $userpref, get_string('clicktohideshow'))); return $output; } diff --git a/classes/output/renderer.php b/classes/output/renderer.php new file mode 100644 index 0000000..f155f63 --- /dev/null +++ b/classes/output/renderer.php @@ -0,0 +1,45 @@ +. + +/** + * course_overview block rendrer + * + * @package block_course_overview + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace block_course_overview\output; + +defined('MOODLE_INTERNAL') || die; + +use plugin_renderer_base; + +/** + * Course_overview block rendrer + * + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class renderer extends plugin_renderer_base { + + /** + * Render main part of course listing + * @param main $main + */ + public function render_main(main $main) { + return $this->render_from_template('block_course_overview/main', $main->export_for_template($this)); + } + +} diff --git a/lang/en/block_course_overview.php b/lang/en/block_course_overview.php index 90fea6e..628da92 100644 --- a/lang/en/block_course_overview.php +++ b/lang/en/block_course_overview.php @@ -23,6 +23,7 @@ */ $string['activityoverview'] = 'You have {$a}s that need attention'; +$string['addfavourite'] = 'Add favourite'; $string['alwaysshowall'] = 'Always show all'; $string['collapseall'] = 'Collapse all course lists'; $string['configotherexpanded'] = 'If enabled, other courses will be expanded by default unless overridden by user preferences.'; @@ -32,6 +33,7 @@ $string['defaultmaxcourses'] = 'Default maximum courses'; $string['defaultmaxcoursesdesc'] = 'Maximum courses which should be displayed on course overview block, 0 will show all courses'; $string['expandall'] = 'Expand all course lists'; +$string['favourites'] = 'Favourite'; $string['forcedefaultmaxcourses'] = 'Force maximum courses'; $string['forcedefaultmaxcoursesdesc'] = 'If set then user will not be able to change his/her personal setting'; $string['fullpath'] = 'All categories and subcategories'; @@ -39,6 +41,7 @@ $string['hiddencoursecountplural'] = 'You have {$a} hidden courses'; $string['hiddencoursecountwithshowall'] = 'You have {$a->coursecount} hidden course ({$a->showalllink})'; $string['hiddencoursecountwithshowallplural'] = 'You have {$a->coursecount} hidden courses ({$a->showalllink})'; +$string['makefavourite'] = 'Make favourite'; $string['message'] = 'message'; $string['messages'] = 'messages'; $string['movecourse'] = 'Move course: {$a}'; @@ -52,6 +55,7 @@ $string['otherexpanded'] = 'Other courses expanded'; $string['pluginname'] = 'Course overview (legacy)'; $string['preservestates'] = 'Preserve expanded states'; +$string['removefavourite'] = 'Remove favourite'; $string['shortnameprefix'] = 'Includes {$a}'; $string['shortnamesufixsingular'] = ' (and {$a} other)'; $string['shortnamesufixprural'] = ' (and {$a} others)'; @@ -59,8 +63,6 @@ $string['showcategoriesdesc'] = 'Should course categories be displayed below each course?'; $string['showchildren'] = 'Show children'; $string['showchildrendesc'] = 'Should child courses be listed underneath the main course title?'; -$string['showwelcomearea'] = 'Show welcome area'; -$string['showwelcomeareadesc'] = 'Show the welcome area above the course list?'; $string['title'] = 'Course overview (legacy)'; $string['view_edit_profile'] = '(View and edit your profile.)'; $string['welcome'] = 'Welcome {$a}'; diff --git a/locallib.php b/locallib.php index f681086..46bb8db 100644 --- a/locallib.php +++ b/locallib.php @@ -100,6 +100,33 @@ function block_course_overview_get_myorder() { return $order; } +/** + * Get the list of course favourites + * + * @return array list of course ids + */ +function block_course_overview_get_favourites() { + if ($value = get_user_preferences('course_overview_favourites')) { + return explode(',', $value); + } else { + return array(); + } +} + +/** + * Sets favourites + * + * @param array $favourites list of course ids + */ +function block_course_overview_update_favourites($favourites) { + $value = implode(',', $favourites); + if (core_text::strlen($value) > 1333) { + // The value won't fit into the user preference. Remove courses in the end of the list (mostly likely user won't even notice). + $value = preg_replace('/,[\d]*$/', '', core_text::substr($value, 0, 1334)); + } + set_user_preference('course_overview_favourites', $value); +} + /** * Returns shortname of activities in course * @@ -238,3 +265,25 @@ function block_course_overview_get_sorted_courses($showallcourses = false) { } return array($sortedcourses, $sitecourses, count($courses)); } + +/** + * Add a course to favourites + * @param int $favourite id of course + */ +function block_course_overview_add_favourite($favourite) { + + // Add to fabourites list + $favourites = block_course_overview_get_favourites(); + if (!in_array($favourite, $favourites)) { + array_unshift($favourites, $favourite); + } + block_course_overview_update_favourites($favourites); + + // Remove from courses list + $order = block_course_overview_get_myorder(); + $key = array_search($favourite, $order); + if ($key !== false) { + unset($order[$key]); + } + block_course_overview_update_myorder($order); +} diff --git a/settings.php b/settings.php index d1c4275..a175ea1 100644 --- a/settings.php +++ b/settings.php @@ -30,8 +30,6 @@ new lang_string('forcedefaultmaxcoursesdesc', 'block_course_overview'), 1, PARAM_INT)); $settings->add(new admin_setting_configcheckbox('block_course_overview/showchildren', new lang_string('showchildren', 'block_course_overview'), new lang_string('showchildrendesc', 'block_course_overview'), 1, PARAM_INT)); - $settings->add(new admin_setting_configcheckbox('block_course_overview/showwelcomearea', new lang_string('showwelcomearea', 'block_course_overview'), - new lang_string('showwelcomeareadesc', 'block_course_overview'), 1, PARAM_INT)); $showcategories = array( BLOCKS_COURSE_OVERVIEW_SHOWCATEGORIES_NONE => new lang_string('none', 'block_course_overview'), BLOCKS_COURSE_OVERVIEW_SHOWCATEGORIES_ONLY_PARENT_NAME => new lang_string('onlyparentname', 'block_course_overview'), diff --git a/styles.css b/styles.css index 2aab2a3..a96c49b 100644 --- a/styles.css +++ b/styles.css @@ -1,87 +1,67 @@ -.block_course_overview .coursechildren { - font-weight: normal; - font-style: italic; +.block-course-overview .courseovbox { + border-bottom: 1px solid #d3d8dc; + padding-top: 10px; + height: 50px; } -.block_course_overview .categorypath { - text-align: right; +.block-course-overview .course-list { + border-top: 1px solid #d3d8dc; } -.block_course_overview .content { - margin: 0 20px; +.overview-icon { + height: 40px; + width: 40px; + float: right; + margin-bottom: 5px; + margin-left: 15px; } -.block_course_overview .content .notice { - margin: 5px 0; +.overview-icon > img { + height: 36px; + width: 36px; } -.block_course_overview .coursebox { - padding: 15px; - width: auto; +.dialogue { } -.block_course_overview .profilepicture { - float: left; +.activity_overviews a { + color: #0075b0; } -.block_course_overview .welcome_area { - width: 100%; - padding-bottom: 5px; -} - -.block_course_overview .welcome_message { - float: left; - padding: 10px; - border-collapse: separate; - clear: none; -} - -.block_course_overview .content h2.title { - float: left; - margin: 0 0 .5em 0; - position: relative; -} - -.block_course_overview .course_title { - position: relative; -} - -.editing .block_course_overview .coursebox .cursor { - cursor: move; - margin-bottom: 2px; -} - -.editing .block_course_overview .move { - float: left; - padding: 2px 10px 0 0; -} - -.block_course_overview .course_list { - width: 100%; +.activity_overviews > .overview { + margin-bottom: 15px; } -.block_course_overview div.flush { - clear: both; +.activity_overviews > .overview > .name { + font-weight: bold; } -.block_course_overview .activity_info { - clear: both; +.course-overview-dialog { + display: none; + background-color: #fff; + padding: 20px; + border: 1px solid #d3d8dc; + z-index: 9999 !important; + box-shadow: 10px 10px 5px rgba(128, 128, 128, 0.5); } -.block_course_overview .activity_overview { - padding: 2px; +.course-overview-dialog .ui-dialog-titlebar-close { + border: 0; } -.block_course_overview .activity_overview img.iconlarge { - vertical-align: text-bottom; - margin-right: 6px; +.course-overview-dialog .ui-dialog-titlebar-close:after { + position: absolute; + font-family: FontAwesome; + font-size: 1.0em; + top:8px; + right:8px; + content: "\f00d "; } -.block_course_overview .singleselect { - text-align: left; - margin: 0; +.block-course-overview .singleselect { + margin-bottom: 10px; } -.block_course_overview .content .course_list .movehere { - margin-bottom: 15px; +a.favourite_icon:hover { + text-decoration: none; } diff --git a/styles.old.css b/styles.old.css new file mode 100644 index 0000000..2aab2a3 --- /dev/null +++ b/styles.old.css @@ -0,0 +1,87 @@ +.block_course_overview .coursechildren { + font-weight: normal; + font-style: italic; +} + +.block_course_overview .categorypath { + text-align: right; +} + +.block_course_overview .content { + margin: 0 20px; +} + +.block_course_overview .content .notice { + margin: 5px 0; +} + +.block_course_overview .coursebox { + padding: 15px; + width: auto; +} + +.block_course_overview .profilepicture { + float: left; +} + +.block_course_overview .welcome_area { + width: 100%; + padding-bottom: 5px; +} + +.block_course_overview .welcome_message { + float: left; + padding: 10px; + border-collapse: separate; + clear: none; +} + +.block_course_overview .content h2.title { + float: left; + margin: 0 0 .5em 0; + position: relative; +} + +.block_course_overview .course_title { + position: relative; +} + +.editing .block_course_overview .coursebox .cursor { + cursor: move; + margin-bottom: 2px; +} + +.editing .block_course_overview .move { + float: left; + padding: 2px 10px 0 0; +} + +.block_course_overview .course_list { + width: 100%; +} + +.block_course_overview div.flush { + clear: both; +} + +.block_course_overview .activity_info { + clear: both; +} + +.block_course_overview .activity_overview { + padding: 2px; +} + +.block_course_overview .activity_overview img.iconlarge { + vertical-align: text-bottom; + margin-right: 6px; +} + +.block_course_overview .singleselect { + text-align: left; + margin: 0; +} + +.block_course_overview .content .course_list .movehere { + margin-bottom: 15px; +} diff --git a/templates/main.mustache b/templates/main.mustache new file mode 100644 index 0000000..69422de --- /dev/null +++ b/templates/main.mustache @@ -0,0 +1,104 @@ +{{! + This file is part of Moodle - http://moodle.org/ + + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}} +{{! + @template block_course_overview/main + + This template renders the main content area for the course_overview block + + Example context (json): + {} +}} + +
+ + {{# isediting }} + {{{ select }}} + {{/ isediting }} + + + +
+ {{# courses }} +
+

+ {{# isediting }} + + {{/ isediting }} + {{^ isediting }} + + + + {{/ isediting }} + {{ fullname }} + {{# hasoverviews }} + {{# overviews }} +
+ {{{ icon }}} +
+ {{/ overviews }} + {{/ hasoverviews }} +

+
+ {{/ courses }} +
+ + {{^ isediting }} +
+ {{# courses }} + {{# hasoverviews }} + {{# overviews }} +
+

{{ coursename }}

+
+ {{{ text }}} +
+
+ {{/ overviews }} + {{/ hasoverviews }} + {{/ courses }} +
+ {{/ isediting }} + + 'Customise this page' then drag-and-drop to reorder +
+ +{{# isediting }} + {{# js }} + require(['jquery', 'block_course_overview/edit'], function($, Edit) { + Edit.init(); + }); + {{/ js }} +{{/ isediting }} +{{^ isediting }} + {{# js }} + require(['jquery', 'block_course_overview/popup'], function($, Popup) { + Popup.init(); + }); + {{/ js }} +{{/ isediting }} + diff --git a/tests/behat/block_course_overview.feature b/tests/behat/block_course_overview.feature index 45f3871..56cf833 100644 --- a/tests/behat/block_course_overview.feature +++ b/tests/behat/block_course_overview.feature @@ -86,31 +86,7 @@ Feature: View the course overview block on the dashboard and test it's functiona And I press "Customise this page" And I should not see "Always show all" - Scenario: View the block by a user with the welcome area enabled and messaging disabled. - Given the following config values are set as admin: - | showwelcomearea | 1 | block_course_overview | - | messaging | 0 | | - When I log in as "student1" - Then I should see "Welcome Student" in the "Course overview (legacy)" "block" - And I should not see "messages" in the "Course overview (legacy)" "block" - - Scenario: View the block by a user with both the welcome area and messaging enabled. - Given the following config values are set as admin: - | showwelcomearea | 1 | block_course_overview | - When I log in as "student1" - Then I should see "Welcome Student" in the "Course overview (legacy)" "block" - And I should see "You have no unread messages" in the "Course overview (legacy)" "block" - And I follow "messages" - And I should see "No messages" - @javascript - Scenario: View the block by a user with the welcome area and the user having messages. - Given the following config values are set as admin: - | showwelcomearea | 1 | block_course_overview | - And I log in as "student1" - And I should see "Welcome Student" - And I should see "You have no unread messages" - Scenario: View the block by a user with the parent categories displayed. Given the following config values are set as admin: | showcategories | Parent category only | block_course_overview | From 7d639b1d47584cd50ded764c4143209dbd2bc1b8 Mon Sep 17 00:00:00 2001 From: Howard Miller Date: Thu, 23 Nov 2017 16:17:10 +0000 Subject: [PATCH 07/29] Working version for more testing --- amd/build/edit.min.js | 1 + amd/build/popup.min.js | 1 + amd/src/edit.js | 30 +++++++++-- amd/src/module.js | 35 ------------- amd/src/popup.js | 25 ++++++++- block_course_overview.php | 34 ++++++++++-- classes/output/main.php | 77 +++++++++++++++++++-------- lang/en/block_course_overview.php | 5 +- locallib.php | 54 +++++++++++++++---- save.php | 7 ++- styles.css | 17 ++++-- styles.old.css | 87 ------------------------------- templates/courselist.mustache | 48 +++++++++++++++++ templates/main.mustache | 63 +++++++++------------- 14 files changed, 275 insertions(+), 209 deletions(-) create mode 100644 amd/build/edit.min.js create mode 100644 amd/build/popup.min.js delete mode 100644 amd/src/module.js delete mode 100644 styles.old.css create mode 100644 templates/courselist.mustache diff --git a/amd/build/edit.min.js b/amd/build/edit.min.js new file mode 100644 index 0000000..4868599 --- /dev/null +++ b/amd/build/edit.min.js @@ -0,0 +1 @@ +define(["jquery","jqueryui"],function(a,b){return{init:function(){a(".coursebox a").removeAttr("href"),a(".course-list").sortable({update:function(b,c){var d=a(".course-list").children(),e=[];a.each(d,function(a,b){var c=b.getAttribute("id");e[a]=c.substring(7)});var f=a(".block_course_overview .nav-tabs .active").data("tabname"),g={sesskey:M.cfg.sesskey,tab:f,sortorder:e};a.post(M.cfg.wwwroot+"/blocks/course_overview/save.php",g)}})}}}); \ No newline at end of file diff --git a/amd/build/popup.min.js b/amd/build/popup.min.js new file mode 100644 index 0000000..71da834 --- /dev/null +++ b/amd/build/popup.min.js @@ -0,0 +1 @@ +define(["jquery","jqueryui","core/config"],function(a,b,c){return{init:function(){a(".dialogue").dialog({autoOpen:!1,minWidth:400,classes:{"ui-dialog":"course-overview-dialog"},closeText:"",modal:!0}),a(".overview-icon").click(function(){var b=a(this).data("id");a(b).dialog("open")})}}}); \ No newline at end of file diff --git a/amd/src/edit.js b/amd/src/edit.js index c71420c..d2a2175 100644 --- a/amd/src/edit.js +++ b/amd/src/edit.js @@ -1,12 +1,34 @@ -// Javascript module to move courses around +// This file is part of Moodle - http://moodle.org/ +// +// Moodle is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Moodle is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Moodle. If not, see . -define(['jquery', 'jqueryui', 'core/config'], function($, UI, mdlconfig) { +/** + * A javascript module to allow drag-and-drop control of course order + * + * @module block_course_overview + * @class block + * @package block_course_overview + * @copyright 2017 Howard Miller + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +define(['jquery', 'jqueryui'], function($, UI) { return { init: function() { // change non-js links to be inactive - //$(".course_title .move a .fa-arrows-v").removeClass("fa-arrows-v").addClass("fa-arrows"); $(".coursebox a").removeAttr("href"); // Make the course list sort @@ -20,8 +42,10 @@ define(['jquery', 'jqueryui', 'core/config'], function($, UI, mdlconfig) { }); // send new sortorder + var activetab = $(".block_course_overview .nav-tabs .active").data("tabname"); var data = { sesskey : M.cfg.sesskey, + tab : activetab, sortorder : sortorder }; $.post( diff --git a/amd/src/module.js b/amd/src/module.js deleted file mode 100644 index 6d7c538..0000000 --- a/amd/src/module.js +++ /dev/null @@ -1,35 +0,0 @@ -// Javascript module to move courses around - -define(['jquery', 'jqueryui'], function($, UI) { - - return { - init: function() { - - // change non-js links to be inactive - $(".course_title .move a .fa-arrows-v").removeClass("fa-arrows-v").addClass("fa-arrows"); - $(".course_title .move a").removeAttr("href"); - - // Make the course list sort - $(".course_list").sortable({ - update: function(event, ui) { - var kids = $(".course_list").children(); - var sortorder = []; - $.each(kids, function(index, value) { - var id = value.getAttribute('id'); - sortorder[index] = id.substring(7); - }); - - // send new sortorder - var data = { - sesskey : M.cfg.sesskey, - sortorder : sortorder - }; - $.post( - M.cfg.wwwroot+'/blocks/course_overview/save.php', - data - ); - } - }); - } - }; -}); diff --git a/amd/src/popup.js b/amd/src/popup.js index 8dfcc23..e5a1c19 100644 --- a/amd/src/popup.js +++ b/amd/src/popup.js @@ -1,4 +1,27 @@ -// Javascript module to popup dialogue +// This file is part of Moodle - http://moodle.org/ +// +// Moodle is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Moodle is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Moodle. If not, see . + +/** + * A javascript module to popup activity overviews + * + * @module block_course_overview + * @class block + * @package block_course_overview + * @copyright 2017 Howard Miller + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ define(['jquery', 'jqueryui', 'core/config'], function($, UI, mdlconfig) { diff --git a/block_course_overview.php b/block_course_overview.php index f4cc40f..aa6a695 100644 --- a/block_course_overview.php +++ b/block_course_overview.php @@ -48,7 +48,7 @@ public function init() { * @return stdClass contents of block */ public function get_content() { - global $USER, $CFG, $DB; + global $USER, $CFG, $DB, $SESSION; require_once($CFG->dirroot.'/user/profile/lib.php'); if($this->content !== NULL) { @@ -72,20 +72,44 @@ public function get_content() { profile_load_custom_fields($USER); - // Check if favourite added + // Check if favourite added/removed $favourite = optional_param('favourite', 0, PARAM_INT); if ($favourite) { block_course_overview_add_favourite($favourite); } + $unfavourite = optional_param('unfavourite', 0, PARAM_INT); + if ($unfavourite) { + block_course_overview_remove_favourite($unfavourite); + } + + // Check if tab clicked + $tab = isset($SESSION->overviewtab) ? $SESSION->overviewtab : 'courses'; + $overviewtab = optional_param('overviewtab', '', PARAM_TEXT); + if (($overviewtab == 'favourite') || ($overviewtab == 'courses')) { + $tab = $overviewtab; + } $showallcourses = ($updatemynumber === self::SHOW_ALL_COURSES); - list($sortedcourses, $sitecourses, $totalcourses) = block_course_overview_get_sorted_courses($showallcourses); - $overviews = block_course_overview_get_overviews($sitecourses); + + // get data for favourites and course tab + $tabs = array(); + $ftab = new stdClass; + $ftab->tab = 'favourites'; + list($ftab->sortedcourses, $ftab->sitecourses, $ftab->totalcourses) = block_course_overview_get_sorted_courses(true, true); + $ftab->overviews = block_course_overview_get_overviews($ftab->sortedcourses); + $ctab = new stdClass; + $ctab->tab = 'courses'; + list($ctab->sortedcourses, $ctab->sitecourses, $ctab->totalcourses) = block_course_overview_get_sorted_courses($showallcourses, false, array_keys($ftab->sortedcourses)); + $ctab->overviews = block_course_overview_get_overviews($ctab->sortedcourses); + $tabs = array( + 'favourites' => $ftab, + 'courses' => $ctab, + ); $renderer = $this->page->get_renderer('block_course_overview'); // try it - $main = new block_course_overview\output\main($sortedcourses, $overviews, $totalcourses, $isediting); + $main = new block_course_overview\output\main($tabs, $isediting, $tab); $this->content->text .= $renderer->render($main); return $this->content; diff --git a/classes/output/main.php b/classes/output/main.php index 7a7bfdd..a67d089 100644 --- a/classes/output/main.php +++ b/classes/output/main.php @@ -38,45 +38,49 @@ */ class main implements renderable, templatable { - private $sortedcourses; - - private $overviews; - - private $totalcourses; + private $tabs; private $isediting; + private $selectedtab; + /** * Constructor - * @param array $sortedcourses - * @param array $overviews - * @param int $totalcourses + * @param array $tabs data for favourites/courses * @param boolean $isediting */ - public function __construct($sortedcourses, $overviews, $totalcourses, $isediting) { - $this->sortedcourses = $sortedcourses; - $this->overviews = $overviews; - $this->totalcourses = $totalcourses; + public function __construct($tabs, $isediting, $selectedtab) { + $this->tabs = $tabs; $this->isediting = $isediting; + $this->tab = $selectedtab; } /** - * Export this data so it can be used as the context for a mustache template. - * + * Get course data into suitable construct * @param \renderer_base $output - * @return stdClass + * @param boolean favourites (is this favourites tab) + * @param object $tab data for tab + * @return array of courses */ - public function export_for_template(renderer_base $output) { + private function process_tab($output, $favourites, $tab) { // Add extra info (and make zero indexed). $courselist = []; - foreach ($this->sortedcourses as $course) { + foreach ($tab->sortedcourses as $course) { $course->link = new \moodle_url('/course/view.php', array('id' => $course->id)); - $course->favouritelink = new \moodle_url('/my', array('favourite' => $course->id)); - if (!empty($this->overviews[$course->id])) { + if ($favourites) { + $course->favouritelink = new \moodle_url('/my', array('unfavourite' => $course->id)); + $course->favouriteicon = 'fa-star'; + $course->favouritealt = get_string('unfavourite', 'block_course_overview'); + } else { + $course->favouritelink = new \moodle_url('/my', array('favourite' => $course->id)); + $course->favouriteicon = 'fa-star-o'; + $course->favouritealt = get_string('makefavourite', 'block_course_overview'); + } + if (!empty($tab->overviews[$course->id])) { $course->hasoverviews = true; $overviews = array(); - foreach ($this->overviews[$course->id] as $activity => $overview_text) { + foreach ($tab->overviews[$course->id] as $activity => $overview_text) { $overview = new \stdClass; $overview->coursename = $course->fullname; $overview->activity = $activity; @@ -94,9 +98,34 @@ public function export_for_template(renderer_base $output) { $courselist[] = $course; } + return $courselist; + } + + /** + * Export this data so it can be used as the context for a mustache template. + * + * @param \renderer_base $output + * @return stdClass + */ + public function export_for_template(renderer_base $output) { + + // generate array for tabs 0=favs, 1=courses + $tabs = array( + 0 => (object) [ + 'tab' => 'favourites', + 'show' => '', + 'data' => $this->process_tab($output, true, $this->tabs['favourites']) + ], + 1 => (object) [ + 'tab' => 'courses', + 'show' => 'show active', + 'data' => $this->process_tab($output, false, $this->tabs['courses']) + ], + ); + // 'courses to show' select box $options = array('0' => get_string('alwaysshowall', 'block_course_overview')); - for ($i = 1; $i <= $this->totalcourses; $i++) { + for ($i = 1; $i <= $this->tabs['courses']->totalcourses; $i++) { $options[$i] = $i; } $url = new \moodle_url('/my/index.php', ['sesskey' => sesskey()]); @@ -104,10 +133,12 @@ public function export_for_template(renderer_base $output) { $select->set_label(get_string('numtodisplay', 'block_course_overview')); return [ - 'courses' => $courselist, + 'tabs' => $tabs, 'isediting' => $this->isediting, 'select' => $output->render($select), - 'viewingfavourites' => false, + 'help' => $output->help_icon('help', 'block_course_overview', true), + 'url' => $url, + 'viewingfavourites' => $this->selectedtab == 'favourites', ]; } diff --git a/lang/en/block_course_overview.php b/lang/en/block_course_overview.php index 628da92..c490f51 100644 --- a/lang/en/block_course_overview.php +++ b/lang/en/block_course_overview.php @@ -33,10 +33,12 @@ $string['defaultmaxcourses'] = 'Default maximum courses'; $string['defaultmaxcoursesdesc'] = 'Maximum courses which should be displayed on course overview block, 0 will show all courses'; $string['expandall'] = 'Expand all course lists'; -$string['favourites'] = 'Favourite'; +$string['favourites'] = 'Favourites'; $string['forcedefaultmaxcourses'] = 'Force maximum courses'; $string['forcedefaultmaxcoursesdesc'] = 'If set then user will not be able to change his/her personal setting'; $string['fullpath'] = 'All categories and subcategories'; +$string['help'] = 'Help'; +$string['help_help'] = '\'Customise this page\', then drag-and-drop to reorder courses. Click activity icons for overview'; $string['hiddencoursecount'] = 'You have {$a} hidden course'; $string['hiddencoursecountplural'] = 'You have {$a} hidden courses'; $string['hiddencoursecountwithshowall'] = 'You have {$a->coursecount} hidden course ({$a->showalllink})'; @@ -64,6 +66,7 @@ $string['showchildren'] = 'Show children'; $string['showchildrendesc'] = 'Should child courses be listed underneath the main course title?'; $string['title'] = 'Course overview (legacy)'; +$string['unfavourite'] = 'Remove favourite'; $string['view_edit_profile'] = '(View and edit your profile.)'; $string['welcome'] = 'Welcome {$a}'; $string['youhavemessages'] = 'You have {$a} unread '; diff --git a/locallib.php b/locallib.php index 46bb8db..26ef9bf 100644 --- a/locallib.php +++ b/locallib.php @@ -195,9 +195,11 @@ function block_course_overview_get_max_user_courses($showallcourses = false) { * Return sorted list of user courses * * @param bool $showallcourses if set true all courses will be visible. + * @param bool $favourites tab selected + * @param array $exlude list of courses not to include (i.e. favs in courses list) * @return array list of sorted courses and count of courses. */ -function block_course_overview_get_sorted_courses($showallcourses = false) { +function block_course_overview_get_sorted_courses($showallcourses = false, $favourites, $exclude = []) { global $USER; $limit = block_course_overview_get_max_user_courses($showallcourses); @@ -229,7 +231,11 @@ function block_course_overview_get_sorted_courses($showallcourses = false) { $courses[$remoteid] = $val; } - $order = block_course_overview_get_myorder(); + if ($favourites) { + $order = block_course_overview_get_favourites(); + } else { + $order = block_course_overview_get_myorder(); + } $sortedcourses = array(); $counter = 0; @@ -245,14 +251,20 @@ function block_course_overview_get_sorted_courses($showallcourses = false) { $counter++; } } - // Append unsorted courses if limit allows - foreach ($courses as $c) { - if (($limit != 0) && ($counter >= $limit)) { - break; - } - if (!in_array($c->id, $order)) { - $sortedcourses[$c->id] = $c; - $counter++; + + // Append unsorted courses if limit allows & not favourites + if (!$favourites) { + foreach ($courses as $c) { + if (($limit != 0) && ($counter >= $limit)) { + break; + } + if (in_array($c->id, $exclude)) { + continue; + } + if (!in_array($c->id, $order)) { + $sortedcourses[$c->id] = $c; + $counter++; + } } } @@ -287,3 +299,25 @@ function block_course_overview_add_favourite($favourite) { } block_course_overview_update_myorder($order); } + +/** + * Remove course from favourites + * @param int $favourite id of course + */ +function block_course_overview_remove_favourite($favourite) { + + // Remove from favourites list + $order = block_course_overview_get_favourites(); + $key = array_search($favourite, $order); + if ($key !== false) { + unset($order[$key]); + } + block_course_overview_update_favourites($order); + + // Add to courses list + $order = block_course_overview_get_myorder(); + if (!in_array($favourite, $order)) { + $order[] = $favourite; + } + block_course_overview_update_myorder($order); +} diff --git a/save.php b/save.php index b4bb175..4f4d930 100644 --- a/save.php +++ b/save.php @@ -30,5 +30,10 @@ require_login(); $sortorder = required_param_array('sortorder', PARAM_INT); +$activetab = required_param_array('tab', PARAM_INT); -block_course_overview_update_myorder($sortorder); +if ($tab == 'courses') { + block_course_overview_update_myorder($sortorder); +} else if ($tab = "favourites") { + block_course_overview_update_favourites($sortorder); +} diff --git a/styles.css b/styles.css index a96c49b..3d7a96b 100644 --- a/styles.css +++ b/styles.css @@ -1,7 +1,7 @@ .block-course-overview .courseovbox { border-bottom: 1px solid #d3d8dc; - padding-top: 10px; - height: 50px; + padding-top: 12px; + height: 52px; } .block-course-overview .course-list { @@ -21,9 +21,6 @@ width: 36px; } -.dialogue { -} - .activity_overviews a { color: #0075b0; } @@ -65,3 +62,13 @@ a.favourite_icon:hover { text-decoration: none; } + +.block-course-overview .overview-help { + margin-top: 10px; +} + +.block-course-overview .overview-help i { + font-size: 1.5em; +} + + diff --git a/styles.old.css b/styles.old.css deleted file mode 100644 index 2aab2a3..0000000 --- a/styles.old.css +++ /dev/null @@ -1,87 +0,0 @@ -.block_course_overview .coursechildren { - font-weight: normal; - font-style: italic; -} - -.block_course_overview .categorypath { - text-align: right; -} - -.block_course_overview .content { - margin: 0 20px; -} - -.block_course_overview .content .notice { - margin: 5px 0; -} - -.block_course_overview .coursebox { - padding: 15px; - width: auto; -} - -.block_course_overview .profilepicture { - float: left; -} - -.block_course_overview .welcome_area { - width: 100%; - padding-bottom: 5px; -} - -.block_course_overview .welcome_message { - float: left; - padding: 10px; - border-collapse: separate; - clear: none; -} - -.block_course_overview .content h2.title { - float: left; - margin: 0 0 .5em 0; - position: relative; -} - -.block_course_overview .course_title { - position: relative; -} - -.editing .block_course_overview .coursebox .cursor { - cursor: move; - margin-bottom: 2px; -} - -.editing .block_course_overview .move { - float: left; - padding: 2px 10px 0 0; -} - -.block_course_overview .course_list { - width: 100%; -} - -.block_course_overview div.flush { - clear: both; -} - -.block_course_overview .activity_info { - clear: both; -} - -.block_course_overview .activity_overview { - padding: 2px; -} - -.block_course_overview .activity_overview img.iconlarge { - vertical-align: text-bottom; - margin-right: 6px; -} - -.block_course_overview .singleselect { - text-align: left; - margin: 0; -} - -.block_course_overview .content .course_list .movehere { - margin-bottom: 15px; -} diff --git a/templates/courselist.mustache b/templates/courselist.mustache new file mode 100644 index 0000000..c3fa1e9 --- /dev/null +++ b/templates/courselist.mustache @@ -0,0 +1,48 @@ +{{! + This file is part of Moodle - http://moodle.org/ + + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}} +{{! + @template block_course_overview/main + + This template renders the course list for the course_overview block + + Example context (json): + {} +}} +
+ {{# data }} +
+

+ {{# isediting }} + + {{/ isediting }} + {{^ isediting }} + + + + {{/ isediting }} + {{ fullname }} + {{# hasoverviews }} + {{# overviews }} +
+ {{{ icon }}} +
+ {{/ overviews }} + {{/ hasoverviews }} +

+
+ {{/ data }} +
diff --git a/templates/main.mustache b/templates/main.mustache index 69422de..d80abbb 100644 --- a/templates/main.mustache +++ b/templates/main.mustache @@ -31,60 +31,47 @@ -
- {{# courses }} -
-

- {{# isediting }} - - {{/ isediting }} - {{^ isediting }} - - - - {{/ isediting }} - {{ fullname }} - {{# hasoverviews }} - {{# overviews }} -
- {{{ icon }}} -
- {{/ overviews }} - {{/ hasoverviews }} -

+
+ {{# tabs }} +
+ {{> block_course_overview/courselist }}
- {{/ courses }} + {{/ tabs }}
{{^ isediting }} -
- {{# courses }} - {{# hasoverviews }} - {{# overviews }} -
-

{{ coursename }}

-
- {{{ text }}} + - {{/ overviews }} - {{/ hasoverviews }} - {{/ courses }} + {{/ overviews }} + {{/ hasoverviews }} + {{/ data }} + {{/ tabs }}
{{/ isediting }} - 'Customise this page' then drag-and-drop to reorder +
+ {{{ help }}} +
{{# isediting }} @@ -97,7 +84,7 @@ {{^ isediting }} {{# js }} require(['jquery', 'block_course_overview/popup'], function($, Popup) { - Popup.init(); + Popup.init({{ viewingfavourites }}); }); {{/ js }} {{/ isediting }} From e2f2a6b454f0c7c4c159854bca891aab68897290 Mon Sep 17 00:00:00 2001 From: Howard Miller Date: Tue, 28 Nov 2017 11:19:41 +0000 Subject: [PATCH 08/29] Working version of "facelift" --- amd/build/edit.min.js | 1 - amd/build/popup.min.js | 1 - amd/src/edit.js | 6 +- block_course_overview.php | 37 ++---- classes/output/main.php | 57 +++++++--- lang/en/block_course_overview.php | 11 +- locallib.php | 83 ++------------ save.php | 6 +- settings.php | 6 - styles.css | 8 ++ templates/courselist.mustache | 12 +- templates/main.mustache | 4 - tests/behat/block_course_overview.feature | 70 ------------ .../block_course_overview_student.feature | 2 +- tests/behat/quiz_overview.feature | 107 ------------------ version.php | 6 +- 16 files changed, 88 insertions(+), 329 deletions(-) delete mode 100644 amd/build/edit.min.js delete mode 100644 amd/build/popup.min.js delete mode 100644 tests/behat/quiz_overview.feature diff --git a/amd/build/edit.min.js b/amd/build/edit.min.js deleted file mode 100644 index 4868599..0000000 --- a/amd/build/edit.min.js +++ /dev/null @@ -1 +0,0 @@ -define(["jquery","jqueryui"],function(a,b){return{init:function(){a(".coursebox a").removeAttr("href"),a(".course-list").sortable({update:function(b,c){var d=a(".course-list").children(),e=[];a.each(d,function(a,b){var c=b.getAttribute("id");e[a]=c.substring(7)});var f=a(".block_course_overview .nav-tabs .active").data("tabname"),g={sesskey:M.cfg.sesskey,tab:f,sortorder:e};a.post(M.cfg.wwwroot+"/blocks/course_overview/save.php",g)}})}}}); \ No newline at end of file diff --git a/amd/build/popup.min.js b/amd/build/popup.min.js deleted file mode 100644 index 71da834..0000000 --- a/amd/build/popup.min.js +++ /dev/null @@ -1 +0,0 @@ -define(["jquery","jqueryui","core/config"],function(a,b,c){return{init:function(){a(".dialogue").dialog({autoOpen:!1,minWidth:400,classes:{"ui-dialog":"course-overview-dialog"},closeText:"",modal:!0}),a(".overview-icon").click(function(){var b=a(this).data("id");a(b).dialog("open")})}}}); \ No newline at end of file diff --git a/amd/src/edit.js b/amd/src/edit.js index d2a2175..1b8e72c 100644 --- a/amd/src/edit.js +++ b/amd/src/edit.js @@ -29,12 +29,12 @@ define(['jquery', 'jqueryui'], function($, UI) { init: function() { // change non-js links to be inactive - $(".coursebox a").removeAttr("href"); + $(".courseovbox a").removeAttr("href"); // Make the course list sort - $(".course-list").sortable({ + $(".tab-pane .course-list").sortable({ update: function(event, ui) { - var kids = $(".course-list").children(); + var kids = $(".tab-pane.active .course-list").children(); var sortorder = []; $.each(kids, function(index, value) { var id = value.getAttribute('id'); diff --git a/block_course_overview.php b/block_course_overview.php index aa6a695..453149c 100644 --- a/block_course_overview.php +++ b/block_course_overview.php @@ -83,49 +83,34 @@ public function get_content() { } // Check if tab clicked - $tab = isset($SESSION->overviewtab) ? $SESSION->overviewtab : 'courses'; - $overviewtab = optional_param('overviewtab', '', PARAM_TEXT); - if (($overviewtab == 'favourite') || ($overviewtab == 'courses')) { - $tab = $overviewtab; - } - - $showallcourses = ($updatemynumber === self::SHOW_ALL_COURSES); // get data for favourites and course tab $tabs = array(); $ftab = new stdClass; $ftab->tab = 'favourites'; - list($ftab->sortedcourses, $ftab->sitecourses, $ftab->totalcourses) = block_course_overview_get_sorted_courses(true, true); + list($ftab->sortedcourses, $ftab->sitecourses, $ftab->totalcourses) = block_course_overview_get_sorted_courses(true); $ftab->overviews = block_course_overview_get_overviews($ftab->sortedcourses); $ctab = new stdClass; $ctab->tab = 'courses'; - list($ctab->sortedcourses, $ctab->sitecourses, $ctab->totalcourses) = block_course_overview_get_sorted_courses($showallcourses, false, array_keys($ftab->sortedcourses)); + list($ctab->sortedcourses, $ctab->sitecourses, $ctab->totalcourses) = block_course_overview_get_sorted_courses(false, array_keys($ftab->sortedcourses)); $ctab->overviews = block_course_overview_get_overviews($ctab->sortedcourses); $tabs = array( 'favourites' => $ftab, 'courses' => $ctab, ); - $renderer = $this->page->get_renderer('block_course_overview'); - - // try it - $main = new block_course_overview\output\main($tabs, $isediting, $tab); - $this->content->text .= $renderer->render($main); - return $this->content; - - // Number of sites to display. - if ($isediting && empty($config->forcedefaultmaxcourses)) { - $this->content->text .= $renderer->editing_bar_head($totalcourses); - } - - if (empty($sortedcourses)) { - $this->content->text .= get_string('nocourses','my'); + // Default tab. One with something in it or favourites + if ($ftab->totalcourses) { + $tab = 'favourites'; } else { - // For each course, build category cache. - $this->content->text .= $renderer->course_overview($sortedcourses, $overviews); - $this->content->text .= $renderer->hidden_courses($totalcourses - count($sortedcourses)); + $tab = 'courses'; } + $renderer = $this->page->get_renderer('block_course_overview'); + + // Render block + $main = new block_course_overview\output\main($config, $tabs, $isediting, $tab); + $this->content->text .= $renderer->render($main); return $this->content; } diff --git a/classes/output/main.php b/classes/output/main.php index a67d089..5adc793 100644 --- a/classes/output/main.php +++ b/classes/output/main.php @@ -38,6 +38,8 @@ */ class main implements renderable, templatable { + private $config; + private $tabs; private $isediting; @@ -46,13 +48,16 @@ class main implements renderable, templatable { /** * Constructor + * @param object $config block configuration * @param array $tabs data for favourites/courses * @param boolean $isediting + * @param string $selectedtab */ - public function __construct($tabs, $isediting, $selectedtab) { + public function __construct($config, $tabs, $isediting, $selectedtab) { + $this->config = $config; $this->tabs = $tabs; $this->isediting = $isediting; - $this->tab = $selectedtab; + $this->selectedtab = $selectedtab; } /** @@ -68,6 +73,7 @@ private function process_tab($output, $favourites, $tab) { $courselist = []; foreach ($tab->sortedcourses as $course) { $course->link = new \moodle_url('/course/view.php', array('id' => $course->id)); + $course->categories = implode(' / ', $this->categories($course->category)); if ($favourites) { $course->favouritelink = new \moodle_url('/my', array('unfavourite' => $course->id)); $course->favouriteicon = 'fa-star'; @@ -101,6 +107,34 @@ private function process_tab($output, $favourites, $tab) { return $courselist; } + /** + * Get (if required) category string for course + * @param int $id course's category id + * @return string category path + */ + private function categories($id) { + $categories = array(); + + if ($this->config->showcategories != BLOCKS_COURSE_OVERVIEW_SHOWCATEGORIES_NONE) { + + // List category parent or categories path here. + $currentcategory = \coursecat::get($id, IGNORE_MISSING); + if ($currentcategory !== null) { + if ($this->config->showcategories == BLOCKS_COURSE_OVERVIEW_SHOWCATEGORIES_FULL_PATH) { + foreach ($currentcategory->get_parents() as $categoryid) { + $category = \coursecat::get($categoryid, IGNORE_MISSING); + if ($category !== null) { + $categories[] = $category->get_formatted_name(); + } + } + } + $categories[] = $currentcategory->get_formatted_name(); + } + } + + return $categories; + } + /** * Export this data so it can be used as the context for a mustache template. * @@ -113,31 +147,20 @@ public function export_for_template(renderer_base $output) { $tabs = array( 0 => (object) [ 'tab' => 'favourites', - 'show' => '', - 'data' => $this->process_tab($output, true, $this->tabs['favourites']) + 'show' => $this->selectedtab == 'favourites' ? 'show active' : '', + 'data' => $this->process_tab($output, true, $this->tabs['favourites']), ], 1 => (object) [ 'tab' => 'courses', - 'show' => 'show active', - 'data' => $this->process_tab($output, false, $this->tabs['courses']) + 'show' => $this->selectedtab == 'courses' ? 'show active' : '', + 'data' => $this->process_tab($output, false, $this->tabs['courses']), ], ); - // 'courses to show' select box - $options = array('0' => get_string('alwaysshowall', 'block_course_overview')); - for ($i = 1; $i <= $this->tabs['courses']->totalcourses; $i++) { - $options[$i] = $i; - } - $url = new \moodle_url('/my/index.php', ['sesskey' => sesskey()]); - $select = new \single_select($url, 'mynumber', $options, block_course_overview_get_max_user_courses(), array()); - $select->set_label(get_string('numtodisplay', 'block_course_overview')); - return [ 'tabs' => $tabs, 'isediting' => $this->isediting, - 'select' => $output->render($select), 'help' => $output->help_icon('help', 'block_course_overview', true), - 'url' => $url, 'viewingfavourites' => $this->selectedtab == 'favourites', ]; } diff --git a/lang/en/block_course_overview.php b/lang/en/block_course_overview.php index c490f51..cfae34f 100644 --- a/lang/en/block_course_overview.php +++ b/lang/en/block_course_overview.php @@ -30,19 +30,11 @@ $string['configpreservestates'] = 'If enabled, the collapsed/expanded states set by the user are stored and used on each load.'; $string['course_overview:addinstance'] = 'Add a new course overview block'; $string['course_overview:myaddinstance'] = 'Add a new course overview block to Dashboard'; -$string['defaultmaxcourses'] = 'Default maximum courses'; -$string['defaultmaxcoursesdesc'] = 'Maximum courses which should be displayed on course overview block, 0 will show all courses'; $string['expandall'] = 'Expand all course lists'; $string['favourites'] = 'Favourites'; -$string['forcedefaultmaxcourses'] = 'Force maximum courses'; -$string['forcedefaultmaxcoursesdesc'] = 'If set then user will not be able to change his/her personal setting'; $string['fullpath'] = 'All categories and subcategories'; $string['help'] = 'Help'; $string['help_help'] = '\'Customise this page\', then drag-and-drop to reorder courses. Click activity icons for overview'; -$string['hiddencoursecount'] = 'You have {$a} hidden course'; -$string['hiddencoursecountplural'] = 'You have {$a} hidden courses'; -$string['hiddencoursecountwithshowall'] = 'You have {$a->coursecount} hidden course ({$a->showalllink})'; -$string['hiddencoursecountwithshowallplural'] = 'You have {$a->coursecount} hidden courses ({$a->showalllink})'; $string['makefavourite'] = 'Make favourite'; $string['message'] = 'message'; $string['messages'] = 'messages'; @@ -51,6 +43,7 @@ $string['movetofirst'] = 'Move {$a} course to top'; $string['moveafterhere'] = 'Move {$a->movingcoursename} course after {$a->currentcoursename}'; $string['movingcourse'] = 'You are moving: {$a->fullname} ({$a->cancellink})'; +$string['nocourses'] = 'There are no courses to show'; $string['none'] = 'None'; $string['numtodisplay'] = 'Number of courses to display: '; $string['onlyparentname'] = 'Parent category only'; @@ -63,8 +56,6 @@ $string['shortnamesufixprural'] = ' (and {$a} others)'; $string['showcategories'] = 'Categories to show'; $string['showcategoriesdesc'] = 'Should course categories be displayed below each course?'; -$string['showchildren'] = 'Show children'; -$string['showchildrendesc'] = 'Should child courses be listed underneath the main course title?'; $string['title'] = 'Course overview (legacy)'; $string['unfavourite'] = 'Remove favourite'; $string['view_edit_profile'] = '(View and edit your profile.)'; diff --git a/locallib.php b/locallib.php index 26ef9bf..b5faa54 100644 --- a/locallib.php +++ b/locallib.php @@ -35,11 +35,17 @@ function block_course_overview_get_overviews($courses) { global $CFG; + // tab may not have any courses + if (!$courses) { + return array(); + } + // Disable debugging mode because all course modules show debugging message in their print_overview. $debugmode = $CFG->debug; $CFG->debug ^= E_DEPRECATED; $htmlarray = array(); + if ($modules = get_plugin_list_with_function('mod', 'print_overview')) { // Split courses list into batches with no more than MAX_MODINFO_CACHE_SIZE courses in one batch. // Otherwise we exceed the cache limit in get_fast_modinfo() and rebuild it too often. @@ -127,83 +133,16 @@ function block_course_overview_update_favourites($favourites) { set_user_preference('course_overview_favourites', $value); } -/** - * Returns shortname of activities in course - * - * @param int $courseid id of course for which activity shortname is needed - * @return string|bool list of child shortname - */ -function block_course_overview_get_child_shortnames($courseid) { - global $DB; - $ctxselect = context_helper::get_preload_record_columns_sql('ctx'); - $sql = "SELECT c.id, c.shortname, $ctxselect - FROM {enrol} e - JOIN {course} c ON (c.id = e.customint1) - JOIN {context} ctx ON (ctx.instanceid = e.customint1) - WHERE e.courseid = :courseid AND e.enrol = :method AND ctx.contextlevel = :contextlevel ORDER BY e.sortorder"; - $params = array('method' => 'meta', 'courseid' => $courseid, 'contextlevel' => CONTEXT_COURSE); - - if ($results = $DB->get_records_sql($sql, $params)) { - $shortnames = array(); - // Preload the context we will need it to format the category name shortly. - foreach ($results as $res) { - context_helper::preload_from_record($res); - $context = context_course::instance($res->id); - $shortnames[] = format_string($res->shortname, true, $context); - } - $total = count($shortnames); - $suffix = ''; - if ($total > 10) { - $shortnames = array_slice($shortnames, 0, 10); - $diff = $total - count($shortnames); - if ($diff > 1) { - $suffix = get_string('shortnamesufixprural', 'block_course_overview', $diff); - } else { - $suffix = get_string('shortnamesufixsingular', 'block_course_overview', $diff); - } - } - $shortnames = get_string('shortnameprefix', 'block_course_overview', implode('; ', $shortnames)); - $shortnames .= $suffix; - } - - return isset($shortnames) ? $shortnames : false; -} - -/** - * Returns maximum number of courses which will be displayed in course_overview block - * - * @param bool $showallcourses if set true all courses will be visible. - * @return int maximum number of courses - */ -function block_course_overview_get_max_user_courses($showallcourses = false) { - // Get block configuration - $config = get_config('block_course_overview'); - $limit = $config->defaultmaxcourses; - - // If max course is not set then try get user preference - if (empty($config->forcedefaultmaxcourses)) { - if ($showallcourses) { - $limit = 0; - } else { - $limit = get_user_preferences('course_overview_number_of_courses', $limit); - } - } - return $limit; -} - /** * Return sorted list of user courses * - * @param bool $showallcourses if set true all courses will be visible. * @param bool $favourites tab selected * @param array $exlude list of courses not to include (i.e. favs in courses list) * @return array list of sorted courses and count of courses. */ -function block_course_overview_get_sorted_courses($showallcourses = false, $favourites, $exclude = []) { +function block_course_overview_get_sorted_courses($favourites, $exclude = []) { global $USER; - $limit = block_course_overview_get_max_user_courses($showallcourses); - $courses = enrol_get_my_courses(); $site = get_site(); @@ -241,9 +180,6 @@ function block_course_overview_get_sorted_courses($showallcourses = false, $favo $counter = 0; // Get courses in sort order into list. foreach ($order as $key => $cid) { - if (($counter >= $limit) && ($limit != 0)) { - break; - } // Make sure user is still enroled. if (isset($courses[$cid])) { @@ -255,9 +191,6 @@ function block_course_overview_get_sorted_courses($showallcourses = false, $favo // Append unsorted courses if limit allows & not favourites if (!$favourites) { foreach ($courses as $c) { - if (($limit != 0) && ($counter >= $limit)) { - break; - } if (in_array($c->id, $exclude)) { continue; } @@ -275,7 +208,7 @@ function block_course_overview_get_sorted_courses($showallcourses = false, $favo $sitecourses[$key] = $course; } } - return array($sortedcourses, $sitecourses, count($courses)); + return array($sortedcourses, $sitecourses, count($sortedcourses)); } /** diff --git a/save.php b/save.php index 4f4d930..420e23e 100644 --- a/save.php +++ b/save.php @@ -30,10 +30,10 @@ require_login(); $sortorder = required_param_array('sortorder', PARAM_INT); -$activetab = required_param_array('tab', PARAM_INT); +$activetab = required_param('tab', PARAM_ALPHA); -if ($tab == 'courses') { +if ($activetab == 'courses') { block_course_overview_update_myorder($sortorder); -} else if ($tab = "favourites") { +} else if ($activetab == "favourites") { block_course_overview_update_favourites($sortorder); } diff --git a/settings.php b/settings.php index a175ea1..97ef0c2 100644 --- a/settings.php +++ b/settings.php @@ -24,12 +24,6 @@ defined('MOODLE_INTERNAL') || die; if ($ADMIN->fulltree) { - $settings->add(new admin_setting_configtext('block_course_overview/defaultmaxcourses', new lang_string('defaultmaxcourses', 'block_course_overview'), - new lang_string('defaultmaxcoursesdesc', 'block_course_overview'), 10, PARAM_INT)); - $settings->add(new admin_setting_configcheckbox('block_course_overview/forcedefaultmaxcourses', new lang_string('forcedefaultmaxcourses', 'block_course_overview'), - new lang_string('forcedefaultmaxcoursesdesc', 'block_course_overview'), 1, PARAM_INT)); - $settings->add(new admin_setting_configcheckbox('block_course_overview/showchildren', new lang_string('showchildren', 'block_course_overview'), - new lang_string('showchildrendesc', 'block_course_overview'), 1, PARAM_INT)); $showcategories = array( BLOCKS_COURSE_OVERVIEW_SHOWCATEGORIES_NONE => new lang_string('none', 'block_course_overview'), BLOCKS_COURSE_OVERVIEW_SHOWCATEGORIES_ONLY_PARENT_NAME => new lang_string('onlyparentname', 'block_course_overview'), diff --git a/styles.css b/styles.css index 3d7a96b..21e06c3 100644 --- a/styles.css +++ b/styles.css @@ -4,6 +4,14 @@ height: 52px; } +.block-course-overview .courseovbox h2 { + margin-bottom: 0; +} + +.block-course-overview .ovcategories { + padding-left: 42px; +} + .block-course-overview .course-list { border-top: 1px solid #d3d8dc; } diff --git a/templates/courselist.mustache b/templates/courselist.mustache index c3fa1e9..c025436 100644 --- a/templates/courselist.mustache +++ b/templates/courselist.mustache @@ -15,7 +15,7 @@ along with Moodle. If not, see . }} {{! - @template block_course_overview/main + @template block_course_overview/courselist This template renders the course list for the course_overview block @@ -24,7 +24,7 @@ }}
{{# data }} -
+

{{# isediting }} @@ -43,6 +43,14 @@ {{/ overviews }} {{/ hasoverviews }}

+
+ {{ categories }} +
{{/ data }} + {{^ data }} +
+ {{# str }}nocourses, block_course_overview{{/ str }} +
+ {{/ data }}
diff --git a/templates/main.mustache b/templates/main.mustache index d80abbb..5bcf488 100644 --- a/templates/main.mustache +++ b/templates/main.mustache @@ -25,10 +25,6 @@
- {{# isediting }} - {{{ select }}} - {{/ isediting }} -