[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/course/publish/ -> lib.php (source)

   1  <?php
   2  
   3  // This file is part of Moodle - http://moodle.org/
   4  //
   5  // Moodle is free software: you can redistribute it and/or modify
   6  // it under the terms of the GNU General Public License as published by
   7  // the Free Software Foundation, either version 3 of the License, or
   8  // (at your option) any later version.
   9  //
  10  // Moodle is distributed in the hope that it will be useful,
  11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13  // GNU General Public License for more details.
  14  //
  15  // You should have received a copy of the GNU General Public License
  16  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  17  /// TIME PERIOD ///
  18  
  19  define('HUB_LASTMODIFIED_WEEK', 7);
  20  
  21  define('HUB_LASTMODIFIED_FORTEENNIGHT', 14);
  22  
  23  define('HUB_LASTMODIFIED_MONTH', 30);
  24  
  25  
  26  
  27  //// AUDIENCE ////
  28  
  29  /**
  30   * Audience: educators
  31   */
  32  define('HUB_AUDIENCE_EDUCATORS', 'educators');
  33  
  34  /**
  35   * Audience: students
  36   */
  37  define('HUB_AUDIENCE_STUDENTS', 'students');
  38  
  39  /**
  40   * Audience: admins
  41   */
  42  define('HUB_AUDIENCE_ADMINS', 'admins');
  43  
  44  
  45  
  46  ///// EDUCATIONAL LEVEL /////
  47  
  48  /**
  49   * Educational level: primary
  50   */
  51  define('HUB_EDULEVEL_PRIMARY', 'primary');
  52  
  53  /**
  54   * Educational level: secondary
  55   */
  56  define('HUB_EDULEVEL_SECONDARY', 'secondary');
  57  
  58  /**
  59   * Educational level: tertiary
  60   */
  61  define('HUB_EDULEVEL_TERTIARY', 'tertiary');
  62  
  63  /**
  64   * Educational level: government
  65   */
  66  define('HUB_EDULEVEL_GOVERNMENT', 'government');
  67  
  68  /**
  69   * Educational level: association
  70   */
  71  define('HUB_EDULEVEL_ASSOCIATION', 'association');
  72  
  73  /**
  74   * Educational level: corporate
  75   */
  76  define('HUB_EDULEVEL_CORPORATE', 'corporate');
  77  
  78  /**
  79   * Educational level: other
  80   */
  81  define('HUB_EDULEVEL_OTHER', 'other');
  82  
  83  
  84  
  85  ///// FILE TYPES /////
  86  
  87  /**
  88   * FILE TYPE: COURSE SCREENSHOT
  89   */
  90  define('HUB_SCREENSHOT_FILE_TYPE', 'screenshot');
  91  
  92  /**
  93   * FILE TYPE: HUB SCREENSHOT
  94   */
  95  define('HUB_HUBSCREENSHOT_FILE_TYPE', 'hubscreenshot');
  96  
  97  /**
  98   * FILE TYPE: BACKUP
  99   */
 100  define('HUB_BACKUP_FILE_TYPE', 'backup');
 101  
 102  /**
 103   *
 104   * Course publication library
 105   *
 106   * @package   course
 107   * @copyright 2010 Moodle Pty Ltd (http://moodle.com)
 108   * @author    Jerome Mouneyrac
 109   * @copyright 1999 onwards Martin Dougiamas  {@link http://moodle.com}
 110   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 111   */
 112  class course_publish_manager {
 113  
 114      /**
 115       * Record a course publication
 116       * @param int $hubid the hub id from the 'registered on hub' table
 117       * @param int $courseid the course id from site point of view
 118       * @param int $enrollable if the course is enrollable = 1, if downloadable = 0
 119       * @param int $hubcourseid the course id from the hub point of view
 120       */
 121      public function add_course_publication($huburl, $courseid, $enrollable, $hubcourseid) {
 122          global $DB;
 123          $publication = new stdClass();
 124          $publication->huburl = $huburl;
 125          $publication->courseid = $courseid;
 126          $publication->hubcourseid = $hubcourseid;
 127          $publication->enrollable = (int) $enrollable;
 128          $publication->timepublished = time();
 129          $DB->insert_record('course_published', $publication);
 130      }
 131  
 132      /**
 133       * Update a enrollable course publication
 134       * @param int $publicationid
 135       */
 136      public function update_enrollable_course_publication($publicationid) {
 137          global $DB;
 138          $publication = new stdClass();
 139          $publication->id = $publicationid;
 140          $publication->timepublished = time();
 141          $DB->update_record('course_published', $publication);
 142      }
 143  
 144      /**
 145       * Update a course publication
 146       * @param object $publication
 147       */
 148      public function update_publication($publication) {
 149          global $DB;
 150          $DB->update_record('course_published', $publication);
 151      }
 152  
 153      /**
 154       * Get courses publications
 155       * @param int $hubid specify a hub
 156       * @param int $courseid specify a course
 157       * @param int $enrollable specify type of publication (enrollable or downloadable)
 158       * @return array of publications
 159       */
 160      public function get_publications($huburl = null, $courseid = null, $enrollable = -1) {
 161          global $DB;
 162          $params = array();
 163  
 164          if (!empty($huburl)) {
 165              $params['huburl'] = $huburl;
 166          }
 167  
 168          if (!empty($courseid)) {
 169              $params['courseid'] = $courseid;
 170          }
 171  
 172          if ($enrollable != -1) {
 173              $params['enrollable'] = (int) $enrollable;
 174          }
 175  
 176          return $DB->get_records('course_published', $params);
 177      }
 178  
 179      /**
 180       * Get a publication for a course id on a hub
 181       * (which is either the id of the unique possible enrollable publication of a course,
 182       * either an id of one of the downloadable publication)
 183       * @param int $hubcourseid
 184       * @param string $huburl
 185       * @return object publication
 186       */
 187      public function get_publication($hubcourseid, $huburl) {
 188          global $DB;
 189          return $DB->get_record('course_published',
 190                  array('hubcourseid' => $hubcourseid, 'huburl' => $huburl));
 191      }
 192  
 193      /**
 194       * Get all publication for a course
 195       * @param int $courseid
 196       * @return array of publication
 197       */
 198      public function get_course_publications($courseid) {
 199          global $DB;
 200          $sql = 'SELECT cp.id, cp.status, cp.timechecked, cp.timepublished, rh.hubname,
 201                         rh.huburl, cp.courseid, cp.enrollable, cp.hubcourseid
 202                  FROM {course_published} cp, {registration_hubs} rh
 203                  WHERE cp.huburl = rh.huburl and cp.courseid = :courseid
 204                  ORDER BY cp.enrollable DESC, rh.hubname, cp.timepublished';
 205          $params = array('courseid' => $courseid);
 206          return $DB->get_records_sql($sql, $params);
 207      }
 208  
 209      /**
 210       * Get the hub concerned by a publication
 211       * @param int $publicationid
 212       * @return object the hub (id, name, url, token)
 213       */
 214      public function get_registeredhub_by_publication($publicationid) {
 215          global $DB;
 216          $sql = 'SELECT rh.huburl, rh.hubname, rh.token
 217                  FROM {course_published} cp, {registration_hubs} rh
 218                  WHERE cp.huburl = rh.huburl and cp.id = :publicationid';
 219          $params = array('publicationid' => $publicationid);
 220          return $DB->get_record_sql($sql, $params);
 221      }
 222  
 223      /**
 224       * Delete a publication
 225       * @param int $publicationid
 226       */
 227      public function delete_publication($publicationid) {
 228          global $DB;
 229          $DB->delete_records('course_published', array('id' => $publicationid));
 230      }
 231  
 232      /**
 233       * Delete publications for a hub
 234       * @param string $huburl
 235       * @param int $enrollable
 236       */
 237      public function delete_hub_publications($huburl, $enrollable = -1) {
 238          global $DB;
 239  
 240          $params = array();
 241  
 242          if (!empty($huburl)) {
 243              $params['huburl'] = $huburl;
 244          }
 245  
 246          if ($enrollable != -1) {
 247              $params['enrollable'] = (int) $enrollable;
 248          }
 249  
 250          $DB->delete_records('course_published', $params);
 251      }
 252  
 253      /**
 254       * Get an array of all block instances for a given context
 255       * @param int $contextid a context id
 256       * @return array of block instances.
 257       */
 258      public function get_block_instances_by_context($contextid, $sort = '') {
 259          global $DB;
 260          return $DB->get_records('block_instances', array('parentcontextid' => $contextid), $sort);
 261      }
 262  
 263      /**
 264       * Retrieve all the sorted course subjects
 265       * @return array $subjects
 266       */
 267      public function get_sorted_subjects() {
 268          $subjects = get_string_manager()->load_component_strings('edufields', current_language());
 269  
 270          //sort the subjects
 271          asort($subjects);
 272          foreach ($subjects as $key => $option) {
 273              $keylength = strlen($key);
 274              if ($keylength == 8) {
 275                  $toplevel[$key] = $option;
 276              } else if ($keylength == 10) {
 277                  $sublevel[substr($key, 0, 8)][$key] = $option;
 278              } else if ($keylength == 12) {
 279                  $subsublevel[substr($key, 0, 8)][substr($key, 0, 10)][$key] = $option;
 280              }
 281          }
 282  
 283          //recreate the initial structure returned by get_string_manager()
 284          $subjects = array();
 285          foreach ($toplevel as $key => $name) {
 286              $subjects[$key] = $name;
 287              foreach ($sublevel[$key] as $subkey => $subname) {
 288                  $subjects[$subkey] = $subname;
 289                  foreach ($subsublevel[$key][$subkey] as $subsubkey => $subsubname) {
 290                      $subjects[$subsubkey] = $subsubname;
 291                  }
 292              }
 293          }
 294  
 295          return $subjects;
 296      }
 297  
 298  }
 299  ?>


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