Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/course/publish/lib.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00018 
00019 define('HUB_LASTMODIFIED_WEEK', 7);
00020 
00021 define('HUB_LASTMODIFIED_FORTEENNIGHT', 14);
00022 
00023 define('HUB_LASTMODIFIED_MONTH', 30);
00024 
00025 
00026 
00028 
00032 define('HUB_AUDIENCE_EDUCATORS', 'educators');
00033 
00037 define('HUB_AUDIENCE_STUDENTS', 'students');
00038 
00042 define('HUB_AUDIENCE_ADMINS', 'admins');
00043 
00044 
00045 
00047 
00051 define('HUB_EDULEVEL_PRIMARY', 'primary');
00052 
00056 define('HUB_EDULEVEL_SECONDARY', 'secondary');
00057 
00061 define('HUB_EDULEVEL_TERTIARY', 'tertiary');
00062 
00066 define('HUB_EDULEVEL_GOVERNMENT', 'government');
00067 
00071 define('HUB_EDULEVEL_ASSOCIATION', 'association');
00072 
00076 define('HUB_EDULEVEL_CORPORATE', 'corporate');
00077 
00081 define('HUB_EDULEVEL_OTHER', 'other');
00082 
00083 
00084 
00086 
00090 define('HUB_SCREENSHOT_FILE_TYPE', 'screenshot');
00091 
00095 define('HUB_HUBSCREENSHOT_FILE_TYPE', 'hubscreenshot');
00096 
00100 define('HUB_BACKUP_FILE_TYPE', 'backup');
00101 
00112 class course_publish_manager {
00113 
00121     public function add_course_publication($huburl, $courseid, $enrollable, $hubcourseid) {
00122         global $DB;
00123         $publication = new stdClass();
00124         $publication->huburl = $huburl;
00125         $publication->courseid = $courseid;
00126         $publication->hubcourseid = $hubcourseid;
00127         $publication->enrollable = (int) $enrollable;
00128         $publication->timepublished = time();
00129         $DB->insert_record('course_published', $publication);
00130     }
00131 
00136     public function update_enrollable_course_publication($publicationid) {
00137         global $DB;
00138         $publication = new stdClass();
00139         $publication->id = $publicationid;
00140         $publication->timepublished = time();
00141         $DB->update_record('course_published', $publication);
00142     }
00143 
00148     public function update_publication($publication) {
00149         global $DB;
00150         $DB->update_record('course_published', $publication);
00151     }
00152 
00160     public function get_publications($huburl = null, $courseid = null, $enrollable = -1) {
00161         global $DB;
00162         $params = array();
00163 
00164         if (!empty($huburl)) {
00165             $params['huburl'] = $huburl;
00166         }
00167 
00168         if (!empty($courseid)) {
00169             $params['courseid'] = $courseid;
00170         }
00171 
00172         if ($enrollable != -1) {
00173             $params['enrollable'] = (int) $enrollable;
00174         }
00175 
00176         return $DB->get_records('course_published', $params);
00177     }
00178 
00187     public function get_publication($hubcourseid, $huburl) {
00188         global $DB;
00189         return $DB->get_record('course_published',
00190                 array('hubcourseid' => $hubcourseid, 'huburl' => $huburl));
00191     }
00192 
00198     public function get_course_publications($courseid) {
00199         global $DB;
00200         $sql = 'SELECT cp.id, cp.status, cp.timechecked, cp.timepublished, rh.hubname,
00201                        rh.huburl, cp.courseid, cp.enrollable, cp.hubcourseid
00202                 FROM {course_published} cp, {registration_hubs} rh
00203                 WHERE cp.huburl = rh.huburl and cp.courseid = :courseid
00204                 ORDER BY cp.enrollable DESC, rh.hubname, cp.timepublished';
00205         $params = array('courseid' => $courseid);
00206         return $DB->get_records_sql($sql, $params);
00207     }
00208 
00214     public function get_registeredhub_by_publication($publicationid) {
00215         global $DB;
00216         $sql = 'SELECT rh.huburl, rh.hubname, rh.token
00217                 FROM {course_published} cp, {registration_hubs} rh
00218                 WHERE cp.huburl = rh.huburl and cp.id = :publicationid';
00219         $params = array('publicationid' => $publicationid);
00220         return $DB->get_record_sql($sql, $params);
00221     }
00222 
00227     public function delete_publication($publicationid) {
00228         global $DB;
00229         $DB->delete_records('course_published', array('id' => $publicationid));
00230     }
00231 
00237     public function delete_hub_publications($huburl, $enrollable = -1) {
00238         global $DB;
00239 
00240         $params = array();
00241 
00242         if (!empty($huburl)) {
00243             $params['huburl'] = $huburl;
00244         }
00245 
00246         if ($enrollable != -1) {
00247             $params['enrollable'] = (int) $enrollable;
00248         }
00249 
00250         $DB->delete_records('course_published', $params);
00251     }
00252 
00258     public function get_block_instances_by_context($contextid, $sort = '') {
00259         global $DB;
00260         return $DB->get_records('block_instances', array('parentcontextid' => $contextid), $sort);
00261     }
00262 
00267     public function get_sorted_subjects() {
00268         $subjects = get_string_manager()->load_component_strings('edufields', current_language());
00269 
00270         //sort the subjects
00271         asort($subjects);
00272         foreach ($subjects as $key => $option) {
00273             $keylength = strlen($key);
00274             if ($keylength == 8) {
00275                 $toplevel[$key] = $option;
00276             } else if ($keylength == 10) {
00277                 $sublevel[substr($key, 0, 8)][$key] = $option;
00278             } else if ($keylength == 12) {
00279                 $subsublevel[substr($key, 0, 8)][substr($key, 0, 10)][$key] = $option;
00280             }
00281         }
00282         
00283         //recreate the initial structure returned by get_string_manager()
00284         $subjects = array();
00285         foreach ($toplevel as $key => $name) {
00286             $subjects[$key] = $name;
00287             foreach ($sublevel[$key] as $subkey => $subname) {
00288                 $subjects[$subkey] = $subname;
00289                 foreach ($subsublevel[$key][$subkey] as $subsubkey => $subsubname) {
00290                     $subjects[$subsubkey] = $subsubname;
00291                 }
00292             }
00293         }
00294 
00295         return $subjects;
00296     }
00297 
00298 }
00299 ?>
 All Data Structures Namespaces Files Functions Variables Enumerations