├── README.md ├── version.php ├── save.php ├── db └── access.php ├── styles.css ├── move.php ├── settings.php ├── lang └── en │ └── block_course_overview.php ├── block_course_overview.php ├── tests └── behat │ ├── quiz_overview.feature │ └── block_course_overview.feature ├── module.js ├── locallib.php ├── renderer.php └── LICENSE /README.md: -------------------------------------------------------------------------------- 1 | Course overview (legacy) block for Moodle 2 | ========================================= 3 | 4 | This is a legacy version of the standard Course overview block which used to be 5 | part of the standard Moodle installation. Starting with Moodle 3.3, the block 6 | has been moved to the plugins directory and can be installed as an additional 7 | plugin. 8 | 9 | See for more details. 10 | -------------------------------------------------------------------------------- /version.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Version details 19 | * 20 | * @package block_course_overview 21 | * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com) 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | 25 | defined('MOODLE_INTERNAL') || die(); 26 | 27 | $plugin->component = 'block_course_overview'; 28 | $plugin->version = 2017050400; 29 | $plugin->requires = 2017042100; 30 | $plugin->maturity = MATURITY_STABLE; 31 | $plugin->release = '3.3.0'; 32 | -------------------------------------------------------------------------------- /save.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Save course order in course_overview block 19 | * 20 | * @package block_course_overview 21 | * @copyright 2012 Adam Olley 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | define('AJAX_SCRIPT', true); 25 | 26 | require_once(__DIR__ . '/../../config.php'); 27 | require_once(__DIR__ . '/locallib.php'); 28 | 29 | require_sesskey(); 30 | require_login(); 31 | 32 | $sortorder = required_param_array('sortorder', PARAM_INT); 33 | 34 | block_course_overview_update_myorder($sortorder); 35 | -------------------------------------------------------------------------------- /db/access.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Course overview block caps. 19 | * 20 | * @package block_course_overview 21 | * @copyright Mark Nelson 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | 25 | defined('MOODLE_INTERNAL') || die(); 26 | 27 | $capabilities = array( 28 | 29 | 'block/course_overview:myaddinstance' => array( 30 | 'captype' => 'write', 31 | 'contextlevel' => CONTEXT_SYSTEM, 32 | 'archetypes' => array( 33 | 'user' => CAP_ALLOW 34 | ), 35 | 36 | 'clonepermissionsfrom' => 'moodle/my:manageblocks' 37 | ), 38 | 39 | 'block/course_overview:addinstance' => array( 40 | 'riskbitmask' => RISK_SPAM | RISK_XSS, 41 | 42 | 'captype' => 'write', 43 | 'contextlevel' => CONTEXT_BLOCK, 44 | 'archetypes' => array( 45 | 'manager' => CAP_ALLOW 46 | ), 47 | 48 | 'clonepermissionsfrom' => 'moodle/site:manageblocks' 49 | ) 50 | ); 51 | -------------------------------------------------------------------------------- /styles.css: -------------------------------------------------------------------------------- 1 | .block_course_overview .coursechildren { 2 | font-weight: normal; 3 | font-style: italic; 4 | } 5 | 6 | .block_course_overview .categorypath { 7 | text-align: right; 8 | } 9 | 10 | .block_course_overview .content { 11 | margin: 0 20px; 12 | } 13 | 14 | .block_course_overview .content .notice { 15 | margin: 5px 0; 16 | } 17 | 18 | .block_course_overview .coursebox { 19 | padding: 15px; 20 | width: auto; 21 | } 22 | 23 | .block_course_overview .profilepicture { 24 | float: left; 25 | } 26 | 27 | .block_course_overview .welcome_area { 28 | width: 100%; 29 | padding-bottom: 5px; 30 | } 31 | 32 | .block_course_overview .welcome_message { 33 | float: left; 34 | padding: 10px; 35 | border-collapse: separate; 36 | clear: none; 37 | } 38 | 39 | .block_course_overview .content h2.title { 40 | float: left; 41 | margin: 0 0 .5em 0; 42 | position: relative; 43 | } 44 | 45 | .block_course_overview .course_title { 46 | position: relative; 47 | } 48 | 49 | .editing .block_course_overview .coursebox .cursor { 50 | cursor: move; 51 | margin-bottom: 2px; 52 | } 53 | 54 | .editing .block_course_overview .move { 55 | float: left; 56 | padding: 2px 10px 0 0; 57 | } 58 | 59 | .block_course_overview .course_list { 60 | width: 100%; 61 | } 62 | 63 | .block_course_overview div.flush { 64 | clear: both; 65 | } 66 | 67 | .block_course_overview .activity_info { 68 | clear: both; 69 | } 70 | 71 | .block_course_overview .activity_overview { 72 | padding: 2px; 73 | } 74 | 75 | .block_course_overview .activity_overview img.iconlarge { 76 | vertical-align: text-bottom; 77 | margin-right: 6px; 78 | } 79 | 80 | .block_course_overview .singleselect { 81 | text-align: left; 82 | margin: 0; 83 | } 84 | 85 | .block_course_overview .content .course_list .movehere { 86 | margin-bottom: 15px; 87 | } 88 | -------------------------------------------------------------------------------- /move.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Move/order course functionality for course_overview block. 19 | * 20 | * @package block_course_overview 21 | * @copyright 2012 Adam Olley 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | require_once(__DIR__ . '/../../config.php'); 25 | require_once(__DIR__ . '/locallib.php'); 26 | 27 | require_sesskey(); 28 | require_login(); 29 | 30 | $coursetomove = required_param('courseid', PARAM_INT); 31 | $moveto = required_param('moveto', PARAM_INT); 32 | 33 | list($courses, $sitecourses, $coursecount) = block_course_overview_get_sorted_courses(); 34 | $sortedcourses = array_keys($courses); 35 | 36 | $currentcourseindex = array_search($coursetomove, $sortedcourses); 37 | // If coursetomove is not found or moveto < 0 or > count($sortedcourses) then throw error. 38 | if ($currentcourseindex === false) { 39 | print_error("invalidcourseid", null, null, $coursetomove); 40 | } else if (($moveto < 0) || ($moveto >= count($sortedcourses))) { 41 | print_error("invalidaction"); 42 | } 43 | 44 | // If current course index is same as destination index then don't do anything. 45 | if ($currentcourseindex === $moveto) { 46 | redirect(new moodle_url('/my/index.php')); 47 | } 48 | 49 | // Create neworder list for courses. 50 | $neworder = array(); 51 | 52 | unset($sortedcourses[$currentcourseindex]); 53 | $neworder = array_slice($sortedcourses, 0, $moveto, true); 54 | $neworder[] = $coursetomove; 55 | $remaningcourses = array_slice($sortedcourses, $moveto); 56 | foreach ($remaningcourses as $courseid) { 57 | $neworder[] = $courseid; 58 | } 59 | block_course_overview_update_myorder(array_values($neworder)); 60 | redirect(new moodle_url('/my/index.php')); 61 | -------------------------------------------------------------------------------- /settings.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * course_overview block settings 19 | * 20 | * @package block_course_overview 21 | * @copyright 2012 Adam Olley 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | defined('MOODLE_INTERNAL') || die; 25 | 26 | if ($ADMIN->fulltree) { 27 | $settings->add(new admin_setting_configtext('block_course_overview/defaultmaxcourses', new lang_string('defaultmaxcourses', 'block_course_overview'), 28 | new lang_string('defaultmaxcoursesdesc', 'block_course_overview'), 10, PARAM_INT)); 29 | $settings->add(new admin_setting_configcheckbox('block_course_overview/forcedefaultmaxcourses', new lang_string('forcedefaultmaxcourses', 'block_course_overview'), 30 | new lang_string('forcedefaultmaxcoursesdesc', 'block_course_overview'), 1, PARAM_INT)); 31 | $settings->add(new admin_setting_configcheckbox('block_course_overview/showchildren', new lang_string('showchildren', 'block_course_overview'), 32 | new lang_string('showchildrendesc', 'block_course_overview'), 1, PARAM_INT)); 33 | $settings->add(new admin_setting_configcheckbox('block_course_overview/showwelcomearea', new lang_string('showwelcomearea', 'block_course_overview'), 34 | new lang_string('showwelcomeareadesc', 'block_course_overview'), 1, PARAM_INT)); 35 | $showcategories = array( 36 | BLOCKS_COURSE_OVERVIEW_SHOWCATEGORIES_NONE => new lang_string('none', 'block_course_overview'), 37 | BLOCKS_COURSE_OVERVIEW_SHOWCATEGORIES_ONLY_PARENT_NAME => new lang_string('onlyparentname', 'block_course_overview'), 38 | BLOCKS_COURSE_OVERVIEW_SHOWCATEGORIES_FULL_PATH => new lang_string('fullpath', 'block_course_overview') 39 | ); 40 | $settings->add(new admin_setting_configselect('block_course_overview/showcategories', new lang_string('showcategories', 'block_course_overview'), 41 | new lang_string('showcategoriesdesc', 'block_course_overview'), BLOCKS_COURSE_OVERVIEW_SHOWCATEGORIES_NONE, $showcategories)); 42 | } 43 | -------------------------------------------------------------------------------- /lang/en/block_course_overview.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Lang strings for course_overview block 19 | * 20 | * @package block_course_overview 21 | * @copyright 2012 Adam Olley 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | 25 | $string['activityoverview'] = 'You have {$a}s that need attention'; 26 | $string['alwaysshowall'] = 'Always show all'; 27 | $string['collapseall'] = 'Collapse all course lists'; 28 | $string['configotherexpanded'] = 'If enabled, other courses will be expanded by default unless overridden by user preferences.'; 29 | $string['configpreservestates'] = 'If enabled, the collapsed/expanded states set by the user are stored and used on each load.'; 30 | $string['course_overview:addinstance'] = 'Add a new course overview block'; 31 | $string['course_overview:myaddinstance'] = 'Add a new course overview block to Dashboard'; 32 | $string['defaultmaxcourses'] = 'Default maximum courses'; 33 | $string['defaultmaxcoursesdesc'] = 'Maximum courses which should be displayed on course overview block, 0 will show all courses'; 34 | $string['expandall'] = 'Expand all course lists'; 35 | $string['forcedefaultmaxcourses'] = 'Force maximum courses'; 36 | $string['forcedefaultmaxcoursesdesc'] = 'If set then user will not be able to change his/her personal setting'; 37 | $string['fullpath'] = 'All categories and subcategories'; 38 | $string['hiddencoursecount'] = 'You have {$a} hidden course'; 39 | $string['hiddencoursecountplural'] = 'You have {$a} hidden courses'; 40 | $string['hiddencoursecountwithshowall'] = 'You have {$a->coursecount} hidden course ({$a->showalllink})'; 41 | $string['hiddencoursecountwithshowallplural'] = 'You have {$a->coursecount} hidden courses ({$a->showalllink})'; 42 | $string['message'] = 'message'; 43 | $string['messages'] = 'messages'; 44 | $string['movecourse'] = 'Move course: {$a}'; 45 | $string['movecoursehere'] = 'Move course here'; 46 | $string['movetofirst'] = 'Move {$a} course to top'; 47 | $string['moveafterhere'] = 'Move {$a->movingcoursename} course after {$a->currentcoursename}'; 48 | $string['movingcourse'] = 'You are moving: {$a->fullname} ({$a->cancellink})'; 49 | $string['none'] = 'None'; 50 | $string['numtodisplay'] = 'Number of courses to display: '; 51 | $string['onlyparentname'] = 'Parent category only'; 52 | $string['otherexpanded'] = 'Other courses expanded'; 53 | $string['pluginname'] = 'Course overview (legacy)'; 54 | $string['preservestates'] = 'Preserve expanded states'; 55 | $string['shortnameprefix'] = 'Includes {$a}'; 56 | $string['shortnamesufixsingular'] = ' (and {$a} other)'; 57 | $string['shortnamesufixprural'] = ' (and {$a} others)'; 58 | $string['showcategories'] = 'Categories to show'; 59 | $string['showcategoriesdesc'] = 'Should course categories be displayed below each course?'; 60 | $string['showchildren'] = 'Show children'; 61 | $string['showchildrendesc'] = 'Should child courses be listed underneath the main course title?'; 62 | $string['showwelcomearea'] = 'Show welcome area'; 63 | $string['showwelcomeareadesc'] = 'Show the welcome area above the course list?'; 64 | $string['title'] = 'Course overview'; 65 | $string['view_edit_profile'] = '(View and edit your profile.)'; 66 | $string['welcome'] = 'Welcome {$a}'; 67 | $string['youhavemessages'] = 'You have {$a} unread '; 68 | $string['youhavenomessages'] = 'You have no unread '; 69 | -------------------------------------------------------------------------------- /block_course_overview.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Course overview block 19 | * 20 | * @package block_course_overview 21 | * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com) 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | require_once($CFG->dirroot.'/blocks/course_overview/locallib.php'); 25 | 26 | /** 27 | * Course overview block 28 | * 29 | * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com) 30 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 31 | */ 32 | class block_course_overview extends block_base { 33 | /** 34 | * If this is passed as mynumber then showallcourses, irrespective of limit by user. 35 | */ 36 | const SHOW_ALL_COURSES = -2; 37 | 38 | /** 39 | * Block initialization 40 | */ 41 | public function init() { 42 | $this->title = get_string('title', 'block_course_overview'); 43 | } 44 | 45 | /** 46 | * Return contents of course_overview block 47 | * 48 | * @return stdClass contents of block 49 | */ 50 | public function get_content() { 51 | global $USER, $CFG, $DB; 52 | require_once($CFG->dirroot.'/user/profile/lib.php'); 53 | 54 | if($this->content !== NULL) { 55 | return $this->content; 56 | } 57 | 58 | $config = get_config('block_course_overview'); 59 | 60 | $this->content = new stdClass(); 61 | $this->content->text = ''; 62 | $this->content->footer = ''; 63 | 64 | $content = array(); 65 | 66 | $updatemynumber = optional_param('mynumber', -1, PARAM_INT); 67 | if ($updatemynumber >= 0 && optional_param('sesskey', '', PARAM_RAW) && confirm_sesskey()) { 68 | block_course_overview_update_mynumber($updatemynumber); 69 | } 70 | 71 | profile_load_custom_fields($USER); 72 | 73 | $showallcourses = ($updatemynumber === self::SHOW_ALL_COURSES); 74 | list($sortedcourses, $sitecourses, $totalcourses) = block_course_overview_get_sorted_courses($showallcourses); 75 | $overviews = block_course_overview_get_overviews($sitecourses); 76 | 77 | $renderer = $this->page->get_renderer('block_course_overview'); 78 | if (!empty($config->showwelcomearea)) { 79 | require_once($CFG->dirroot.'/message/lib.php'); 80 | $msgcount = message_count_unread_messages(); 81 | $this->content->text = $renderer->welcome_area($msgcount); 82 | } 83 | 84 | // Number of sites to display. 85 | if ($this->page->user_is_editing() && empty($config->forcedefaultmaxcourses)) { 86 | $this->content->text .= $renderer->editing_bar_head($totalcourses); 87 | } 88 | 89 | if (empty($sortedcourses)) { 90 | $this->content->text .= get_string('nocourses','my'); 91 | } else { 92 | // For each course, build category cache. 93 | $this->content->text .= $renderer->course_overview($sortedcourses, $overviews); 94 | $this->content->text .= $renderer->hidden_courses($totalcourses - count($sortedcourses)); 95 | } 96 | 97 | return $this->content; 98 | } 99 | 100 | /** 101 | * Allow the block to have a configuration page 102 | * 103 | * @return boolean 104 | */ 105 | public function has_config() { 106 | return true; 107 | } 108 | 109 | /** 110 | * Locations where block can be displayed 111 | * 112 | * @return array 113 | */ 114 | public function applicable_formats() { 115 | return array('my' => true); 116 | } 117 | 118 | /** 119 | * Sets block header to be hidden or visible 120 | * 121 | * @return bool if true then header will be visible. 122 | */ 123 | public function hide_header() { 124 | // Hide header if welcome area is show. 125 | $config = get_config('block_course_overview'); 126 | return !empty($config->showwelcomearea); 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /tests/behat/quiz_overview.feature: -------------------------------------------------------------------------------- 1 | @block @block_course_overview @mod_quiz 2 | Feature: View the quiz being due 3 | In order to know what quizzes are due 4 | As a student 5 | I can visit my dashboard 6 | 7 | Background: 8 | Given the following "users" exist: 9 | | username | firstname | lastname | email | 10 | | student1 | Student | 1 | student1@example.com | 11 | | student2 | Student | 2 | student2@example.com | 12 | | teacher1 | Teacher | 1 | teacher1@example.com | 13 | And the following "courses" exist: 14 | | fullname | shortname | 15 | | Course 1 | C1 | 16 | | Course 2 | C2 | 17 | And the following "course enrolments" exist: 18 | | user | course | role | 19 | | student1 | C1 | student | 20 | | student2 | C2 | student | 21 | | teacher1 | C1 | editingteacher | 22 | | teacher1 | C2 | editingteacher | 23 | And the following "activities" exist: 24 | | activity | course | idnumber | name | timeclose | 25 | | quiz | C1 | Q1A | Quiz 1A No deadline | 0 | 26 | | quiz | C1 | Q1B | Quiz 1B Past deadline | 1337 | 27 | | quiz | C1 | Q1C | Quiz 1C Future deadline | 9000000000 | 28 | | quiz | C1 | Q1D | Quiz 1D Future deadline | 9000000000 | 29 | | quiz | C1 | Q1E | Quiz 1E Future deadline | 9000000000 | 30 | | quiz | C2 | Q2A | Quiz 2A Future deadline | 9000000000 | 31 | And the following "question categories" exist: 32 | | contextlevel | reference | name | 33 | | Course | C1 | Test questions | 34 | And the following "questions" exist: 35 | | qtype | name | questiontext | questioncategory | 36 | | truefalse | First question | Answer the first question | Test questions | 37 | And quiz "Quiz 1A No deadline" contains the following questions: 38 | | question | page | 39 | | First question | 1 | 40 | And quiz "Quiz 1B Past deadline" contains the following questions: 41 | | question | page | 42 | | First question | 1 | 43 | And quiz "Quiz 1C Future deadline" contains the following questions: 44 | | question | page | 45 | | First question | 1 | 46 | And quiz "Quiz 1D Future deadline" contains the following questions: 47 | | question | page | 48 | | First question | 1 | 49 | And quiz "Quiz 1E Future deadline" contains the following questions: 50 | | question | page | 51 | | First question | 1 | 52 | And quiz "Quiz 2A Future deadline" contains the following questions: 53 | | question | page | 54 | | First question | 1 | 55 | 56 | Scenario: View my quizzes that are due 57 | Given I log in as "student1" 58 | When I am on homepage 59 | Then I should see "You have quizzes that are due" in the "Course overview" "block" 60 | And I should see "Quiz 1C Future deadline" in the "Course overview" "block" 61 | And I should see "Quiz 1D Future deadline" in the "Course overview" "block" 62 | And I should see "Quiz 1E Future deadline" in the "Course overview" "block" 63 | And I should not see "Quiz 1A No deadline" in the "Course overview" "block" 64 | And I should not see "Quiz 1B Past deadline" in the "Course overview" "block" 65 | And I should not see "Quiz 2A Future deadline" in the "Course overview" "block" 66 | And I log out 67 | And I log in as "student2" 68 | And I should see "You have quizzes that are due" in the "Course overview" "block" 69 | And I should not see "Quiz 1C Future deadline" in the "Course overview" "block" 70 | And I should not see "Quiz 1D Future deadline" in the "Course overview" "block" 71 | And I should not see "Quiz 1E Future deadline" in the "Course overview" "block" 72 | And I should not see "Quiz 1A No deadline" in the "Course overview" "block" 73 | And I should not see "Quiz 1B Past deadline" in the "Course overview" "block" 74 | And I should see "Quiz 2A Future deadline" in the "Course overview" "block" 75 | 76 | Scenario: View my quizzes that are due and never finished 77 | Given I log in as "student1" 78 | And I follow "Course 1" 79 | And I follow "Quiz 1D Future deadline" 80 | And I press "Attempt quiz now" 81 | And I follow "Finish attempt ..." 82 | And I press "Submit all and finish" 83 | And I follow "Course 1" 84 | And I follow "Quiz 1E Future deadline" 85 | And I press "Attempt quiz now" 86 | When I am on homepage 87 | Then I should see "You have quizzes that are due" in the "Course overview" "block" 88 | And I should see "Quiz 1C Future deadline" in the "Course overview" "block" 89 | And I should see "Quiz 1E Future deadline" in the "Course overview" "block" 90 | And I should not see "Quiz 1A No deadline" in the "Course overview" "block" 91 | And I should not see "Quiz 1B Past deadline" in the "Course overview" "block" 92 | And I should not see "Quiz 1D Future deadline" in the "Course overview" "block" 93 | And I should not see "Quiz 2A Future deadline" in the "Course overview" "block" 94 | -------------------------------------------------------------------------------- /tests/behat/block_course_overview.feature: -------------------------------------------------------------------------------- 1 | @block @block_course_overview 2 | Feature: View the course overview block on the dashboard and test it's functionality 3 | In order to view the course overview block on the dashboard 4 | As an admin 5 | I can configure the course overview block 6 | 7 | Background: 8 | Given the following "users" exist: 9 | | username | firstname | lastname | email | idnumber | 10 | | student1 | Student | 1 | student1@example.com | S1 | 11 | | teacher1 | Teacher | 1 | teacher1@example.com | T1 | 12 | And the following "categories" exist: 13 | | name | category | idnumber | 14 | | Category 1 | 0 | CAT1 | 15 | | Category 2 | CAT1 | CAT2 | 16 | And the following "courses" exist: 17 | | fullname | shortname | category | 18 | | Course 1 | C1 | 0 | 19 | | Course 2 | C2 | CAT1 | 20 | | Course 3 | C3 | CAT2 | 21 | 22 | Scenario: View the block by a user without any enrolments 23 | Given I log in as "student1" 24 | Then I should see "No course information to show" in the "Course overview" "block" 25 | 26 | Scenario: View the block by a user with several enrolments 27 | Given the following "course enrolments" exist: 28 | | user | course | role | 29 | | student1 | C1 | student | 30 | | student1 | C2 | student | 31 | When I log in as "student1" 32 | Then I should see "Course 1" in the "Course overview" "block" 33 | And I should see "Course 2" in the "Course overview" "block" 34 | 35 | Scenario: View the block by a user with several enrolments and limit the number of courses. 36 | Given the following "course enrolments" exist: 37 | | user | course | role | 38 | | student1 | C1 | student | 39 | | student1 | C2 | student | 40 | | student1 | C3 | student | 41 | When I log in as "student1" 42 | And I press "Customise this page" 43 | And I select "1" from the "Number of courses to display:" singleselect 44 | Then I should see "Course 1" in the "Course overview" "block" 45 | And I should see "You have 2 hidden courses" 46 | And I should not see "Course 2" in the "Course overview" "block" 47 | And I should not see "Course 3" in the "Course overview" "block" 48 | And I follow "Show all courses" 49 | And I should see "Course 1" in the "Course overview" "block" 50 | And I should see "Course 2" in the "Course overview" "block" 51 | And I should see "Course 3" in the "Course overview" "block" 52 | 53 | Scenario: View the block by a user with several enrolments and an admin set default max courses. 54 | Given the following config values are set as admin: 55 | | defaultmaxcourses | 2 | block_course_overview | 56 | And the following "course enrolments" exist: 57 | | user | course | role | 58 | | student1 | C1 | student | 59 | | student1 | C2 | student | 60 | | student1 | C3 | student | 61 | When I log in as "student1" 62 | Then I should see "Course 1" in the "Course overview" "block" 63 | And I should see "Course 2" in the "Course overview" "block" 64 | And I should see "You have 1 hidden course" 65 | And I press "Customise this page" 66 | And I select "Always show all" from the "Number of courses to display:" singleselect 67 | And I should see "Course 3" in the "Course overview" "block" 68 | And I should not see "You have 1 hidden course" 69 | 70 | Scenario: View the block by a user with several enrolments and an admin enforced maximum displayed courses. 71 | Given the following config values are set as admin: 72 | | defaultmaxcourses | 2 | block_course_overview | 73 | | forcedefaultmaxcourses | 1 | block_course_overview | 74 | And the following "course enrolments" exist: 75 | | user | course | role | 76 | | student1 | C1 | student | 77 | | student1 | C2 | student | 78 | | student1 | C3 | student | 79 | When I log in as "student1" 80 | Then I should see "Course 1" in the "Course overview" "block" 81 | And I should see "Course 2" in the "Course overview" "block" 82 | And I should see "You have 1 hidden course" 83 | And I press "Customise this page" 84 | And I should not see "Always show all" 85 | 86 | Scenario: View the block by a user with the welcome area enabled and messaging disabled. 87 | Given the following config values are set as admin: 88 | | showwelcomearea | 1 | block_course_overview | 89 | | messaging | 0 | | 90 | When I log in as "student1" 91 | Then I should see "Welcome Student" in the "Course overview" "block" 92 | And I should not see "messages" in the "Course overview" "block" 93 | 94 | Scenario: View the block by a user with both the welcome area and messaging enabled. 95 | Given the following config values are set as admin: 96 | | showwelcomearea | 1 | block_course_overview | 97 | When I log in as "student1" 98 | Then I should see "Welcome Student" in the "Course overview" "block" 99 | And I should see "You have no unread messages" in the "Course overview" "block" 100 | And I follow "messages" 101 | And I should see "No messages" 102 | 103 | @javascript 104 | Scenario: View the block by a user with the welcome area and the user having messages. 105 | Given the following config values are set as admin: 106 | | showwelcomearea | 1 | block_course_overview | 107 | And I log in as "student1" 108 | And I should see "Welcome Student" in the "Course overview" "block" 109 | And I should see "You have no unread messages" in the "Course overview" "block" 110 | And I follow "messages" 111 | And I send "This is message 1" message to "Teacher 1" user 112 | And I send "This is message 2" message to "Teacher 1" user 113 | When I log out 114 | And I log in as "teacher1" 115 | Then I should see "Welcome Teacher" in the "Course overview" "block" 116 | And I should see "You have 2 unread messages" in the "Course overview" "block" 117 | 118 | Scenario: View the block by a user with the parent categories displayed. 119 | Given the following config values are set as admin: 120 | | showcategories | Parent category only | block_course_overview | 121 | And the following "course enrolments" exist: 122 | | user | course | role | 123 | | student1 | C1 | student | 124 | | student1 | C2 | student | 125 | | student1 | C3 | student | 126 | When I log in as "student1" 127 | Then I should see "Miscellaneous" in the "Course overview" "block" 128 | And I should see "Category 1" in the "Course overview" "block" 129 | And I should see "Category 2" in the "Course overview" "block" 130 | And I should not see "Category 1 / Category 1" in the "Course overview" "block" 131 | 132 | Scenario: View the block by a user with the full categories displayed. 133 | Given the following config values are set as admin: 134 | | showcategories | 2 | block_course_overview | 135 | And the following "course enrolments" exist: 136 | | user | course | role | 137 | | student1 | C1 | student | 138 | | student1 | C2 | student | 139 | | student1 | C3 | student | 140 | When I log in as "student1" 141 | Then I should see "Miscellaneous" in the "Course overview" "block" 142 | And I should see "Category 1 / Category 2" in the "Course overview" "block" 143 | 144 | @javascript 145 | Scenario: View the block by a user with the show children option enabled. 146 | Given the following config values are set as admin: 147 | | showchildren | 1 | block_course_overview | 148 | And the following "course enrolments" exist: 149 | | user | course | role | 150 | | student1 | C1 | student | 151 | And I log in as "admin" 152 | And I navigate to "Manage enrol plugins" node in "Site administration > Plugins > Enrolments" 153 | And I click on "Enable" "link" in the "Course meta link" "table_row" 154 | And I am on site homepage 155 | And I follow "Course 2" 156 | And I add "Course meta link" enrolment method with: 157 | | Link course | C1 | 158 | And I log out 159 | When I log in as "student1" 160 | Then I should see "Course 1" in the "Course overview" "block" 161 | And I should see "Course 2" in the "Course overview" "block" 162 | And I should see "Includes C1" in the "Course overview" "block" 163 | -------------------------------------------------------------------------------- /module.js: -------------------------------------------------------------------------------- 1 | M.block_course_overview = {} 2 | 3 | M.block_course_overview.add_handles = function(Y) { 4 | M.block_course_overview.Y = Y; 5 | var MOVEICON = { 6 | pix: "i/move_2d", 7 | component: 'moodle' 8 | }; 9 | 10 | YUI().use('dd-constrain', 'dd-proxy', 'dd-drop', 'dd-plugin', function(Y) { 11 | //Static Vars 12 | var goingUp = false, lastY = 0; 13 | 14 | var list = Y.Node.all('.course_list .coursebox'); 15 | list.each(function(v, k) { 16 | // Replace move link and image with move_2d image. 17 | var imagenode = v.one('.course_title .move a img'); 18 | imagenode.setAttribute('src', M.util.image_url(MOVEICON.pix, MOVEICON.component)); 19 | imagenode.addClass('cursor'); 20 | v.one('.course_title .move a').replace(imagenode); 21 | 22 | var dd = new Y.DD.Drag({ 23 | node: v, 24 | target: { 25 | padding: '0 0 0 20' 26 | } 27 | }).plug(Y.Plugin.DDProxy, { 28 | moveOnEnd: false 29 | }).plug(Y.Plugin.DDConstrained, { 30 | constrain2node: '.course_list' 31 | }); 32 | dd.addHandle('.course_title .move'); 33 | }); 34 | 35 | Y.DD.DDM.on('drag:start', function(e) { 36 | //Get our drag object 37 | var drag = e.target; 38 | //Set some styles here 39 | drag.get('node').setStyle('opacity', '.25'); 40 | drag.get('dragNode').addClass('block_course_overview'); 41 | drag.get('dragNode').set('innerHTML', drag.get('node').get('innerHTML')); 42 | drag.get('dragNode').setStyles({ 43 | opacity: '.5', 44 | borderColor: drag.get('node').getStyle('borderColor'), 45 | backgroundColor: drag.get('node').getStyle('backgroundColor') 46 | }); 47 | }); 48 | 49 | Y.DD.DDM.on('drag:end', function(e) { 50 | var drag = e.target; 51 | //Put our styles back 52 | drag.get('node').setStyles({ 53 | visibility: '', 54 | opacity: '1' 55 | }); 56 | M.block_course_overview.save(Y); 57 | }); 58 | 59 | Y.DD.DDM.on('drag:drag', function(e) { 60 | //Get the last y point 61 | var y = e.target.lastXY[1]; 62 | //is it greater than the lastY var? 63 | if (y < lastY) { 64 | //We are going up 65 | goingUp = true; 66 | } else { 67 | //We are going down. 68 | goingUp = false; 69 | } 70 | //Cache for next check 71 | lastY = y; 72 | }); 73 | 74 | Y.DD.DDM.on('drop:over', function(e) { 75 | //Get a reference to our drag and drop nodes 76 | var drag = e.drag.get('node'), 77 | drop = e.drop.get('node'); 78 | 79 | //Are we dropping on a li node? 80 | if (drop.hasClass('coursebox')) { 81 | //Are we not going up? 82 | if (!goingUp) { 83 | drop = drop.get('nextSibling'); 84 | } 85 | //Add the node to this list 86 | e.drop.get('node').get('parentNode').insertBefore(drag, drop); 87 | //Resize this nodes shim, so we can drop on it later. 88 | e.drop.sizeShim(); 89 | } 90 | }); 91 | 92 | Y.DD.DDM.on('drag:drophit', function(e) { 93 | var drop = e.drop.get('node'), 94 | drag = e.drag.get('node'); 95 | 96 | //if we are not on an li, we must have been dropped on a ul 97 | if (!drop.hasClass('coursebox')) { 98 | if (!drop.contains(drag)) { 99 | drop.appendChild(drag); 100 | } 101 | } 102 | }); 103 | }); 104 | } 105 | 106 | M.block_course_overview.save = function() { 107 | var Y = M.block_course_overview.Y; 108 | var sortorder = Y.one('.course_list').get('children').getAttribute('id'); 109 | for (var i = 0; i < sortorder.length; i++) { 110 | sortorder[i] = sortorder[i].substring(7); 111 | } 112 | var params = { 113 | sesskey : M.cfg.sesskey, 114 | sortorder : sortorder 115 | }; 116 | Y.io(M.cfg.wwwroot+'/blocks/course_overview/save.php', { 117 | method: 'POST', 118 | data: build_querystring(params), 119 | context: this 120 | }); 121 | } 122 | 123 | /** 124 | * Init a collapsible region, see print_collapsible_region in weblib.php 125 | * @param {YUI} Y YUI3 instance with all libraries loaded 126 | * @param {String} id the HTML id for the div. 127 | * @param {String} userpref the user preference that records the state of this box. false if none. 128 | * @param {String} strtooltip 129 | */ 130 | M.block_course_overview.collapsible = function(Y, id, userpref, strtooltip) { 131 | if (userpref) { 132 | M.block_course_overview.userpref = true; 133 | } 134 | Y.use('anim', function(Y) { 135 | new M.block_course_overview.CollapsibleRegion(Y, id, userpref, strtooltip); 136 | }); 137 | }; 138 | 139 | /** 140 | * Object to handle a collapsible region : instantiate and forget styled object 141 | * 142 | * @class 143 | * @constructor 144 | * @param {YUI} Y YUI3 instance with all libraries loaded 145 | * @param {String} id The HTML id for the div. 146 | * @param {String} userpref The user preference that records the state of this box. false if none. 147 | * @param {String} strtooltip 148 | */ 149 | M.block_course_overview.CollapsibleRegion = function(Y, id, userpref, strtooltip) { 150 | // Record the pref name 151 | this.userpref = userpref; 152 | 153 | // Find the divs in the document. 154 | this.div = Y.one('#'+id); 155 | 156 | // Get the caption for the collapsible region 157 | var caption = this.div.one('#'+id + '_caption'); 158 | caption.setAttribute('title', strtooltip); 159 | 160 | // Create a link 161 | var a = Y.Node.create(''); 162 | // Create a local scoped lamba function to move nodes to a new link 163 | var movenode = function(node){ 164 | node.remove(); 165 | a.append(node); 166 | }; 167 | // Apply the lamba function on each of the captions child nodes 168 | caption.get('children').each(movenode, this); 169 | caption.prepend(a); 170 | 171 | // Get the height of the div at this point before we shrink it if required 172 | var height = this.div.get('offsetHeight'); 173 | if (this.div.hasClass('collapsed')) { 174 | // Shrink the div as it is collapsed by default 175 | this.div.setStyle('height', caption.get('offsetHeight')+'px'); 176 | } 177 | 178 | // Create the animation. 179 | var animation = new Y.Anim({ 180 | node: this.div, 181 | duration: 0.3, 182 | easing: Y.Easing.easeBoth, 183 | to: {height:caption.get('offsetHeight')}, 184 | from: {height:height} 185 | }); 186 | 187 | // Handler for the animation finishing. 188 | animation.on('end', function() { 189 | this.div.toggleClass('collapsed'); 190 | }, this); 191 | 192 | // Hook up the event handler. 193 | caption.on('click', function(e, animation) { 194 | e.preventDefault(); 195 | // Animate to the appropriate size. 196 | if (animation.get('running')) { 197 | animation.stop(); 198 | } 199 | animation.set('reverse', this.div.hasClass('collapsed')); 200 | // Update the user preference. 201 | if (this.userpref) { 202 | M.util.set_user_preference(this.userpref, !this.div.hasClass('collapsed')); 203 | } 204 | animation.run(); 205 | }, this, animation); 206 | }; 207 | 208 | M.block_course_overview.userpref = false; 209 | 210 | /** 211 | * The user preference that stores the state of this box. 212 | * @property userpref 213 | * @type String 214 | */ 215 | M.block_course_overview.CollapsibleRegion.prototype.userpref = null; 216 | 217 | /** 218 | * The key divs that make up this 219 | * @property div 220 | * @type Y.Node 221 | */ 222 | M.block_course_overview.CollapsibleRegion.prototype.div = null; 223 | 224 | /** 225 | * The key divs that make up this 226 | * @property icon 227 | * @type Y.Node 228 | */ 229 | M.block_course_overview.CollapsibleRegion.prototype.icon = null; 230 | 231 | -------------------------------------------------------------------------------- /locallib.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Helper functions for course_overview block 19 | * 20 | * @package block_course_overview 21 | * @copyright 2012 Adam Olley 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | 25 | define('BLOCKS_COURSE_OVERVIEW_SHOWCATEGORIES_NONE', '0'); 26 | define('BLOCKS_COURSE_OVERVIEW_SHOWCATEGORIES_ONLY_PARENT_NAME', '1'); 27 | define('BLOCKS_COURSE_OVERVIEW_SHOWCATEGORIES_FULL_PATH', '2'); 28 | 29 | /** 30 | * Display overview for courses 31 | * 32 | * @param array $courses courses for which overview needs to be shown 33 | * @return array html overview 34 | */ 35 | function block_course_overview_get_overviews($courses) { 36 | $htmlarray = array(); 37 | if ($modules = get_plugin_list_with_function('mod', 'print_overview')) { 38 | // Split courses list into batches with no more than MAX_MODINFO_CACHE_SIZE courses in one batch. 39 | // Otherwise we exceed the cache limit in get_fast_modinfo() and rebuild it too often. 40 | if (defined('MAX_MODINFO_CACHE_SIZE') && MAX_MODINFO_CACHE_SIZE > 0 && count($courses) > MAX_MODINFO_CACHE_SIZE) { 41 | $batches = array_chunk($courses, MAX_MODINFO_CACHE_SIZE, true); 42 | } else { 43 | $batches = array($courses); 44 | } 45 | foreach ($batches as $courses) { 46 | foreach ($modules as $fname) { 47 | $fname($courses, $htmlarray); 48 | } 49 | } 50 | } 51 | return $htmlarray; 52 | } 53 | 54 | /** 55 | * Sets user preference for maximum courses to be displayed in course_overview block 56 | * 57 | * @param int $number maximum courses which should be visible 58 | */ 59 | function block_course_overview_update_mynumber($number) { 60 | set_user_preference('course_overview_number_of_courses', $number); 61 | } 62 | 63 | /** 64 | * Sets user course sorting preference in course_overview block 65 | * 66 | * @param array $sortorder list of course ids 67 | */ 68 | function block_course_overview_update_myorder($sortorder) { 69 | $value = implode(',', $sortorder); 70 | if (core_text::strlen($value) > 1333) { 71 | // The value won't fit into the user preference. Remove courses in the end of the list (mostly likely user won't even notice). 72 | $value = preg_replace('/,[\d]*$/', '', core_text::substr($value, 0, 1334)); 73 | } 74 | set_user_preference('course_overview_course_sortorder', $value); 75 | } 76 | 77 | /** 78 | * Gets user course sorting preference in course_overview block 79 | * 80 | * @return array list of course ids 81 | */ 82 | function block_course_overview_get_myorder() { 83 | if ($value = get_user_preferences('course_overview_course_sortorder')) { 84 | return explode(',', $value); 85 | } 86 | // If preference was not found, look in the old location and convert if found. 87 | $order = array(); 88 | if ($value = get_user_preferences('course_overview_course_order')) { 89 | $order = unserialize_array($value); 90 | block_course_overview_update_myorder($order); 91 | unset_user_preference('course_overview_course_order'); 92 | } 93 | return $order; 94 | } 95 | 96 | /** 97 | * Returns shortname of activities in course 98 | * 99 | * @param int $courseid id of course for which activity shortname is needed 100 | * @return string|bool list of child shortname 101 | */ 102 | function block_course_overview_get_child_shortnames($courseid) { 103 | global $DB; 104 | $ctxselect = context_helper::get_preload_record_columns_sql('ctx'); 105 | $sql = "SELECT c.id, c.shortname, $ctxselect 106 | FROM {enrol} e 107 | JOIN {course} c ON (c.id = e.customint1) 108 | JOIN {context} ctx ON (ctx.instanceid = e.customint1) 109 | WHERE e.courseid = :courseid AND e.enrol = :method AND ctx.contextlevel = :contextlevel ORDER BY e.sortorder"; 110 | $params = array('method' => 'meta', 'courseid' => $courseid, 'contextlevel' => CONTEXT_COURSE); 111 | 112 | if ($results = $DB->get_records_sql($sql, $params)) { 113 | $shortnames = array(); 114 | // Preload the context we will need it to format the category name shortly. 115 | foreach ($results as $res) { 116 | context_helper::preload_from_record($res); 117 | $context = context_course::instance($res->id); 118 | $shortnames[] = format_string($res->shortname, true, $context); 119 | } 120 | $total = count($shortnames); 121 | $suffix = ''; 122 | if ($total > 10) { 123 | $shortnames = array_slice($shortnames, 0, 10); 124 | $diff = $total - count($shortnames); 125 | if ($diff > 1) { 126 | $suffix = get_string('shortnamesufixprural', 'block_course_overview', $diff); 127 | } else { 128 | $suffix = get_string('shortnamesufixsingular', 'block_course_overview', $diff); 129 | } 130 | } 131 | $shortnames = get_string('shortnameprefix', 'block_course_overview', implode('; ', $shortnames)); 132 | $shortnames .= $suffix; 133 | } 134 | 135 | return isset($shortnames) ? $shortnames : false; 136 | } 137 | 138 | /** 139 | * Returns maximum number of courses which will be displayed in course_overview block 140 | * 141 | * @param bool $showallcourses if set true all courses will be visible. 142 | * @return int maximum number of courses 143 | */ 144 | function block_course_overview_get_max_user_courses($showallcourses = false) { 145 | // Get block configuration 146 | $config = get_config('block_course_overview'); 147 | $limit = $config->defaultmaxcourses; 148 | 149 | // If max course is not set then try get user preference 150 | if (empty($config->forcedefaultmaxcourses)) { 151 | if ($showallcourses) { 152 | $limit = 0; 153 | } else { 154 | $limit = get_user_preferences('course_overview_number_of_courses', $limit); 155 | } 156 | } 157 | return $limit; 158 | } 159 | 160 | /** 161 | * Return sorted list of user courses 162 | * 163 | * @param bool $showallcourses if set true all courses will be visible. 164 | * @return array list of sorted courses and count of courses. 165 | */ 166 | function block_course_overview_get_sorted_courses($showallcourses = false) { 167 | global $USER; 168 | 169 | $limit = block_course_overview_get_max_user_courses($showallcourses); 170 | 171 | $courses = enrol_get_my_courses(); 172 | $site = get_site(); 173 | 174 | if (array_key_exists($site->id,$courses)) { 175 | unset($courses[$site->id]); 176 | } 177 | 178 | foreach ($courses as $c) { 179 | if (isset($USER->lastcourseaccess[$c->id])) { 180 | $courses[$c->id]->lastaccess = $USER->lastcourseaccess[$c->id]; 181 | } else { 182 | $courses[$c->id]->lastaccess = 0; 183 | } 184 | } 185 | 186 | // Get remote courses. 187 | $remotecourses = array(); 188 | if (is_enabled_auth('mnet')) { 189 | $remotecourses = get_my_remotecourses(); 190 | } 191 | // Remote courses will have -ve remoteid as key, so it can be differentiated from normal courses 192 | foreach ($remotecourses as $id => $val) { 193 | $remoteid = $val->remoteid * -1; 194 | $val->id = $remoteid; 195 | $courses[$remoteid] = $val; 196 | } 197 | 198 | $order = block_course_overview_get_myorder(); 199 | 200 | $sortedcourses = array(); 201 | $counter = 0; 202 | // Get courses in sort order into list. 203 | foreach ($order as $key => $cid) { 204 | if (($counter >= $limit) && ($limit != 0)) { 205 | break; 206 | } 207 | 208 | // Make sure user is still enroled. 209 | if (isset($courses[$cid])) { 210 | $sortedcourses[$cid] = $courses[$cid]; 211 | $counter++; 212 | } 213 | } 214 | // Append unsorted courses if limit allows 215 | foreach ($courses as $c) { 216 | if (($limit != 0) && ($counter >= $limit)) { 217 | break; 218 | } 219 | if (!in_array($c->id, $order)) { 220 | $sortedcourses[$c->id] = $c; 221 | $counter++; 222 | } 223 | } 224 | 225 | // From list extract site courses for overview 226 | $sitecourses = array(); 227 | foreach ($sortedcourses as $key => $course) { 228 | if ($course->id > 0) { 229 | $sitecourses[$key] = $course; 230 | } 231 | } 232 | return array($sortedcourses, $sitecourses, count($courses)); 233 | } 234 | -------------------------------------------------------------------------------- /renderer.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * course_overview block rendrer 19 | * 20 | * @package block_course_overview 21 | * @copyright 2012 Adam Olley 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | defined('MOODLE_INTERNAL') || die; 25 | 26 | /** 27 | * Course_overview block rendrer 28 | * 29 | * @copyright 2012 Adam Olley 30 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 31 | */ 32 | class block_course_overview_renderer extends plugin_renderer_base { 33 | 34 | /** 35 | * Construct contents of course_overview block 36 | * 37 | * @param array $courses list of courses in sorted order 38 | * @param array $overviews list of course overviews 39 | * @return string html to be displayed in course_overview block 40 | */ 41 | public function course_overview($courses, $overviews) { 42 | $html = ''; 43 | $config = get_config('block_course_overview'); 44 | if ($config->showcategories != BLOCKS_COURSE_OVERVIEW_SHOWCATEGORIES_NONE) { 45 | global $CFG; 46 | require_once($CFG->libdir.'/coursecatlib.php'); 47 | } 48 | $ismovingcourse = false; 49 | $courseordernumber = 0; 50 | $maxcourses = count($courses); 51 | $userediting = false; 52 | // Intialise string/icon etc if user is editing and courses > 1 53 | if ($this->page->user_is_editing() && (count($courses) > 1)) { 54 | $userediting = true; 55 | $this->page->requires->js_init_call('M.block_course_overview.add_handles'); 56 | 57 | // Check if course is moving 58 | $ismovingcourse = optional_param('movecourse', FALSE, PARAM_BOOL); 59 | $movingcourseid = optional_param('courseid', 0, PARAM_INT); 60 | } 61 | 62 | // Render first movehere icon. 63 | if ($ismovingcourse) { 64 | // Remove movecourse param from url. 65 | $this->page->ensure_param_not_in_url('movecourse'); 66 | 67 | // Show moving course notice, so user knows what is being moved. 68 | $html .= $this->output->box_start('notice'); 69 | $a = new stdClass(); 70 | $a->fullname = $courses[$movingcourseid]->fullname; 71 | $a->cancellink = html_writer::link($this->page->url, get_string('cancel')); 72 | $html .= get_string('movingcourse', 'block_course_overview', $a); 73 | $html .= $this->output->box_end(); 74 | 75 | $moveurl = new moodle_url('/blocks/course_overview/move.php', 76 | array('sesskey' => sesskey(), 'moveto' => 0, 'courseid' => $movingcourseid)); 77 | // Create move icon, so it can be used. 78 | $name = $courses[$movingcourseid]->fullname; 79 | $movetofirsticon = $this->output->pix_icon('movehere', get_string('movetofirst', 'block_course_overview', $name)); 80 | $moveurl = html_writer::link($moveurl, $movetofirsticon); 81 | $html .= html_writer::tag('div', $moveurl, array('class' => 'movehere')); 82 | } 83 | 84 | foreach ($courses as $key => $course) { 85 | // If moving course, then don't show course which needs to be moved. 86 | if ($ismovingcourse && ($course->id == $movingcourseid)) { 87 | continue; 88 | } 89 | $html .= $this->output->box_start('coursebox', "course-{$course->id}"); 90 | $html .= html_writer::start_tag('div', array('class' => 'course_title')); 91 | // If user is editing, then add move icons. 92 | if ($userediting && !$ismovingcourse) { 93 | $moveicon = $this->output->pix_icon('t/move', get_string('movecourse', 'block_course_overview', $course->fullname)); 94 | $moveurl = new moodle_url($this->page->url, array('sesskey' => sesskey(), 'movecourse' => 1, 'courseid' => $course->id)); 95 | $moveurl = html_writer::link($moveurl, $moveicon); 96 | $html .= html_writer::tag('div', $moveurl, array('class' => 'move')); 97 | 98 | } 99 | 100 | // No need to pass title through s() here as it will be done automatically by html_writer. 101 | $attributes = array('title' => $course->fullname); 102 | if ($course->id > 0) { 103 | if (empty($course->visible)) { 104 | $attributes['class'] = 'dimmed'; 105 | } 106 | $courseurl = new moodle_url('/course/view.php', array('id' => $course->id)); 107 | $coursefullname = format_string(get_course_display_name_for_list($course), true, $course->id); 108 | $link = html_writer::link($courseurl, $coursefullname, $attributes); 109 | $html .= $this->output->heading($link, 2, 'title'); 110 | } else { 111 | $html .= $this->output->heading(html_writer::link( 112 | new moodle_url('/auth/mnet/jump.php', array('hostid' => $course->hostid, 'wantsurl' => '/course/view.php?id='.$course->remoteid)), 113 | format_string($course->shortname, true), $attributes) . ' (' . format_string($course->hostname) . ')', 2, 'title'); 114 | } 115 | $html .= $this->output->container('', 'flush'); 116 | $html .= html_writer::end_tag('div'); 117 | 118 | if (!empty($config->showchildren) && ($course->id > 0)) { 119 | // List children here. 120 | if ($children = block_course_overview_get_child_shortnames($course->id)) { 121 | $html .= html_writer::tag('span', $children, array('class' => 'coursechildren')); 122 | } 123 | } 124 | 125 | // If user is moving courses, then down't show overview. 126 | if (isset($overviews[$course->id]) && !$ismovingcourse) { 127 | $html .= $this->activity_display($course->id, $overviews[$course->id]); 128 | } 129 | 130 | if ($config->showcategories != BLOCKS_COURSE_OVERVIEW_SHOWCATEGORIES_NONE) { 131 | // List category parent or categories path here. 132 | $currentcategory = coursecat::get($course->category, IGNORE_MISSING); 133 | if ($currentcategory !== null) { 134 | $html .= html_writer::start_tag('div', array('class' => 'categorypath')); 135 | if ($config->showcategories == BLOCKS_COURSE_OVERVIEW_SHOWCATEGORIES_FULL_PATH) { 136 | foreach ($currentcategory->get_parents() as $categoryid) { 137 | $category = coursecat::get($categoryid, IGNORE_MISSING); 138 | if ($category !== null) { 139 | $html .= $category->get_formatted_name().' / '; 140 | } 141 | } 142 | } 143 | $html .= $currentcategory->get_formatted_name(); 144 | $html .= html_writer::end_tag('div'); 145 | } 146 | } 147 | 148 | $html .= $this->output->container('', 'flush'); 149 | $html .= $this->output->box_end(); 150 | $courseordernumber++; 151 | if ($ismovingcourse) { 152 | $moveurl = new moodle_url('/blocks/course_overview/move.php', 153 | array('sesskey' => sesskey(), 'moveto' => $courseordernumber, 'courseid' => $movingcourseid)); 154 | $a = new stdClass(); 155 | $a->movingcoursename = $courses[$movingcourseid]->fullname; 156 | $a->currentcoursename = $course->fullname; 157 | $movehereicon = $this->output->pix_icon('movehere', get_string('moveafterhere', 'block_course_overview', $a)); 158 | $moveurl = html_writer::link($moveurl, $movehereicon); 159 | $html .= html_writer::tag('div', $moveurl, array('class' => 'movehere')); 160 | } 161 | } 162 | // Wrap course list in a div and return. 163 | return html_writer::tag('div', $html, array('class' => 'course_list')); 164 | } 165 | 166 | /** 167 | * Coustuct activities overview for a course 168 | * 169 | * @param int $cid course id 170 | * @param array $overview overview of activities in course 171 | * @return string html of activities overview 172 | */ 173 | protected function activity_display($cid, $overview) { 174 | $output = html_writer::start_tag('div', array('class' => 'activity_info')); 175 | foreach (array_keys($overview) as $module) { 176 | $output .= html_writer::start_tag('div', array('class' => 'activity_overview')); 177 | $url = new moodle_url("/mod/$module/index.php", array('id' => $cid)); 178 | $modulename = get_string('modulename', $module); 179 | $icontext = html_writer::link($url, $this->output->image_icon('icon', $modulename, 'mod_'.$module, array('class'=>'iconlarge'))); 180 | if (get_string_manager()->string_exists("activityoverview", $module)) { 181 | $icontext .= get_string("activityoverview", $module); 182 | } else { 183 | $icontext .= get_string("activityoverview", 'block_course_overview', $modulename); 184 | } 185 | 186 | // Add collapsible region with overview text in it. 187 | $output .= $this->collapsible_region($overview[$module], '', 'region_'.$cid.'_'.$module, $icontext, '', true); 188 | 189 | $output .= html_writer::end_tag('div'); 190 | } 191 | $output .= html_writer::end_tag('div'); 192 | return $output; 193 | } 194 | 195 | /** 196 | * Constructs header in editing mode 197 | * 198 | * @param int $max maximum number of courses 199 | * @return string html of header bar. 200 | */ 201 | public function editing_bar_head($max = 0) { 202 | $output = $this->output->box_start('notice'); 203 | 204 | $options = array('0' => get_string('alwaysshowall', 'block_course_overview')); 205 | for ($i = 1; $i <= $max; $i++) { 206 | $options[$i] = $i; 207 | } 208 | $url = new moodle_url('/my/index.php', ['sesskey' => sesskey()]); 209 | $select = new single_select($url, 'mynumber', $options, block_course_overview_get_max_user_courses(), array()); 210 | $select->set_label(get_string('numtodisplay', 'block_course_overview')); 211 | $output .= $this->output->render($select); 212 | 213 | $output .= $this->output->box_end(); 214 | return $output; 215 | } 216 | 217 | /** 218 | * Show hidden courses count 219 | * 220 | * @param int $total count of hidden courses 221 | * @return string html 222 | */ 223 | public function hidden_courses($total) { 224 | if ($total <= 0) { 225 | return; 226 | } 227 | $output = $this->output->box_start('notice'); 228 | $plural = $total > 1 ? 'plural' : ''; 229 | $config = get_config('block_course_overview'); 230 | // Show view all course link to user if forcedefaultmaxcourses is not empty. 231 | if (!empty($config->forcedefaultmaxcourses)) { 232 | $output .= get_string('hiddencoursecount'.$plural, 'block_course_overview', $total); 233 | } else { 234 | $a = new stdClass(); 235 | $a->coursecount = $total; 236 | $a->showalllink = html_writer::link(new moodle_url('/my/index.php', array('mynumber' => block_course_overview::SHOW_ALL_COURSES)), 237 | get_string('showallcourses')); 238 | $output .= get_string('hiddencoursecountwithshowall'.$plural, 'block_course_overview', $a); 239 | } 240 | 241 | $output .= $this->output->box_end(); 242 | return $output; 243 | } 244 | 245 | /** 246 | * Creates collapsable region 247 | * 248 | * @param string $contents existing contents 249 | * @param string $classes class names added to the div that is output. 250 | * @param string $id id added to the div that is output. Must not be blank. 251 | * @param string $caption text displayed at the top. Clicking on this will cause the region to expand or contract. 252 | * @param string $userpref the name of the user preference that stores the user's preferred default state. 253 | * (May be blank if you do not wish the state to be persisted. 254 | * @param bool $default Initial collapsed state to use if the user_preference it not set. 255 | * @return bool if true, return the HTML as a string, rather than printing it. 256 | */ 257 | protected function collapsible_region($contents, $classes, $id, $caption, $userpref = '', $default = false) { 258 | $output = $this->collapsible_region_start($classes, $id, $caption, $userpref, $default); 259 | $output .= $contents; 260 | $output .= $this->collapsible_region_end(); 261 | 262 | return $output; 263 | } 264 | 265 | /** 266 | * Print (or return) the start of a collapsible region, that has a caption that can 267 | * be clicked to expand or collapse the region. If JavaScript is off, then the region 268 | * will always be expanded. 269 | * 270 | * @param string $classes class names added to the div that is output. 271 | * @param string $id id added to the div that is output. Must not be blank. 272 | * @param string $caption text displayed at the top. Clicking on this will cause the region to expand or contract. 273 | * @param string $userpref the name of the user preference that stores the user's preferred default state. 274 | * (May be blank if you do not wish the state to be persisted. 275 | * @param bool $default Initial collapsed state to use if the user_preference it not set. 276 | * @return bool if true, return the HTML as a string, rather than printing it. 277 | */ 278 | protected function collapsible_region_start($classes, $id, $caption, $userpref = '', $default = false) { 279 | // Work out the initial state. 280 | if (!empty($userpref) and is_string($userpref)) { 281 | user_preference_allow_ajax_update($userpref, PARAM_BOOL); 282 | $collapsed = get_user_preferences($userpref, $default); 283 | } else { 284 | $collapsed = $default; 285 | $userpref = false; 286 | } 287 | 288 | if ($collapsed) { 289 | $classes .= ' collapsed'; 290 | } 291 | 292 | $output = ''; 293 | $output .= '
'; 294 | $output .= '
'; 295 | $output .= '
'; 296 | $output .= $caption . ' '; 297 | $output .= '
'; 298 | $this->page->requires->js_init_call('M.block_course_overview.collapsible', array($id, $userpref, get_string('clicktohideshow'))); 299 | 300 | return $output; 301 | } 302 | 303 | /** 304 | * Close a region started with print_collapsible_region_start. 305 | * 306 | * @return string return the HTML as a string, rather than printing it. 307 | */ 308 | protected function collapsible_region_end() { 309 | $output = '
'; 310 | return $output; 311 | } 312 | 313 | /** 314 | * Cretes html for welcome area 315 | * 316 | * @param int $msgcount number of messages 317 | * @return string html string for welcome area. 318 | */ 319 | public function welcome_area($msgcount) { 320 | global $CFG, $USER; 321 | $output = $this->output->box_start('welcome_area'); 322 | 323 | $picture = $this->output->user_picture($USER, array('size' => 75, 'class' => 'welcome_userpicture')); 324 | $output .= html_writer::tag('div', $picture, array('class' => 'profilepicture')); 325 | 326 | $output .= $this->output->box_start('welcome_message'); 327 | $output .= $this->output->heading(get_string('welcome', 'block_course_overview', $USER->firstname)); 328 | 329 | if (!empty($CFG->messaging)) { 330 | $plural = 's'; 331 | if ($msgcount > 0) { 332 | $output .= get_string('youhavemessages', 'block_course_overview', $msgcount); 333 | if ($msgcount == 1) { 334 | $plural = ''; 335 | } 336 | } else { 337 | $output .= get_string('youhavenomessages', 'block_course_overview'); 338 | } 339 | $output .= html_writer::link(new moodle_url('/message/index.php'), 340 | get_string('message'.$plural, 'block_course_overview')); 341 | } 342 | $output .= $this->output->box_end(); 343 | $output .= $this->output->container('', 'flush'); 344 | $output .= $this->output->box_end(); 345 | 346 | return $output; 347 | } 348 | } 349 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {project} Copyright (C) {year} {fullname} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------