Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

MDL-31640 course: removed extra error message, perpage is set properl…

…y, modulelink hidden field, and new context call is used.
  • Loading branch information...
commit fdfe7064894c5c2f48c6c7f56b84d8a84efb9bea 1 parent 506cbfd
Rajesh Taneja rajeshtaneja authored

Showing 2 changed files with 20 additions and 15 deletions. Show diff stats Hide diff stats

  1. +20 14 course/search.php
  2. +0 1  lang/en/error.php
34 course/search.php
@@ -50,7 +50,7 @@
50 50 $urlparams['perpage'] = $perpage;
51 51 }
52 52 $PAGE->set_url('/course/search.php', $urlparams);
53   - $PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
  53 + $PAGE->set_context(context_system::instance());
54 54 $PAGE->set_pagelayout('standard');
55 55
56 56 if ($CFG->forcelogin) {
@@ -63,12 +63,17 @@
63 63 $USER->editing = $edit;
64 64 }
65 65 $adminediting = $PAGE->user_is_editing();
  66 +
  67 + // Set perpage if user can edit in category
  68 + if ($perpage != 99999) {
  69 + $perpage = 30;
  70 + }
66 71 } else {
67 72 $adminediting = false;
68 73 }
69 74
70 75 /// Editing functions
71   - if (has_capability('moodle/course:visibility', get_context_instance(CONTEXT_SYSTEM))) {
  76 + if (has_capability('moodle/course:visibility', context_system::instance())) {
72 77 /// Hide or show a course
73 78 if ($hide or $show and confirm_sesskey()) {
74 79 if ($hide) {
@@ -84,10 +89,6 @@
84 89 }
85 90 }
86 91
87   - if (has_any_capability($capabilities, get_context_instance(CONTEXT_SYSTEM)) && ($perpage != 99999)) {
88   - $perpage = 30;
89   - }
90   -
91 92 $displaylist = array();
92 93 $parentlist = array();
93 94 make_categories_list($displaylist, $parentlist);
@@ -130,17 +131,17 @@
130 131 }
131 132
132 133 //User should have manage and create capablity on destination category.
133   - require_capability('moodle/category:manage', get_context_instance(CONTEXT_COURSECAT, $moveto));
134   - require_capability('moodle/course:create', get_context_instance(CONTEXT_COURSECAT, $moveto));
  134 + require_capability('moodle/category:manage', context_coursecat::instance($moveto));
  135 + require_capability('moodle/course:create', context_coursecat::instance($moveto));
135 136
136 137 foreach ( $data as $key => $value ) {
137 138 if (preg_match('/^c\d+$/', $key)) {
138 139 $courseid = substr($key, 1);
139 140 // user must have category:manage and course:create capability for the course to be moved.
140   - if (has_all_capabilities($capabilities, get_context_instance(CONTEXT_COURSE, $courseid))) {
  141 + $coursecontext = context_course::instance($courseid);
  142 + foreach ($capabilities as $capability) {
  143 + require_capability($capability, $coursecontext);
141 144 array_push($courses, $courseid);
142   - } else {
143   - print_error('cannotmovecoursetocategory');
144 145 }
145 146 }
146 147 }
@@ -251,11 +252,16 @@
251 252 echo $OUTPUT->spacer(array('height'=>5, 'width'=>5, 'br'=>true)); // should be done with CSS instead
252 253 }
253 254 } else { //editing mode
254   - echo "<form id=\"movecourses\" action=\"search.php?".$modulelink."\" method=\"post\">\n";
  255 + echo "<form id=\"movecourses\" action=\"search.php\" method=\"post\">\n";
255 256 echo "<div><input type=\"hidden\" name=\"sesskey\" value=\"".sesskey()."\" />\n";
256 257 echo "<input type=\"hidden\" name=\"search\" value=\"".s($search)."\" />\n";
257 258 echo "<input type=\"hidden\" name=\"page\" value=\"$page\" />\n";
258 259 echo "<input type=\"hidden\" name=\"perpage\" value=\"$perpage\" /></div>\n";
  260 + if (!empty($modulelist) and confirm_sesskey()) {
  261 + echo "<input type=\"hidden\" name=\"modulelist\" value=\"$modulelist\" /></div>\n";
  262 + } else if (!empty($blocklist) and confirm_sesskey()) {
  263 + echo "<input type=\"hidden\" name=\"blocklist\" value=\"$blocklist\" /></div>\n";
  264 + }
259 265 echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"4\" class=\"generalbox boxaligncenter\">\n<tr>\n";
260 266 echo "<th scope=\"col\">$strcourses</th>\n";
261 267 echo "<th scope=\"col\">$strcategory</th>\n";
@@ -264,7 +270,7 @@
264 270
265 271 foreach ($courses as $course) {
266 272
267   - $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
  273 + $coursecontext = context_course::instance($course->id);
268 274
269 275 $linkcss = $course->visible ? "" : " class=\"dimmed\" ";
270 276
@@ -393,7 +399,7 @@ function print_navigation_bar($totalcount,$page,$perpage,$encodedsearch,$modulel
393 399 $defaultperpage = 10;
394 400 //If user has course:create or category:manage capability the show 30 records.
395 401 $capabilities = array('moodle/course:create', 'moodle/category:manage');
396   - if (has_any_capability($capabilities, get_context_instance(CONTEXT_SYSTEM))) {
  402 + if (has_any_capability($capabilities, context_system::instance())) {
397 403 $defaultperpage = 30;
398 404 }
399 405
1  lang/en/error.php
@@ -103,7 +103,6 @@
103 103 $string['cannotmigratedatacomments'] = 'Cannot migrate data module comments';
104 104 $string['cannotmodulename'] = 'Cannot get the module name in build navigation';
105 105 $string['cannotmoduletype'] = 'Cannot get the module type in build navigation';
106   -$string['cannotmovecoursetocategory'] = 'You do not have capabilities to move the course into different category.';
107 106 $string['cannotmoverolewithid'] = 'Cannot move role with ID {$a}';
108 107 $string['cannotnetgeo'] = 'Cannot connect to NetGeo server at http://netgeo.caida.org, please check proxy settings or better install MaxMind GeoLite City data file';
109 108 $string['cannotopencsv'] = 'Cannot open CSV file';

0 comments on commit fdfe706

Please sign in to comment.
Something went wrong with that request. Please try again.