[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/blocks/course_overview/ -> move.php (source)

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * Move/order course functionality for course_overview block.
  19   *
  20   * @package    block_course_overview
  21   * @copyright  2012 Adam Olley <adam.olley@netspot.com.au>
  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'));


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1