Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: ee3d7d8a71
Fetching contributors…

Cannot retrieve contributors at this time

file 299 lines (249 sloc) 8.56 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
<?php

// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/// TIME PERIOD ///

define('HUB_LASTMODIFIED_WEEK', 7);

define('HUB_LASTMODIFIED_FORTEENNIGHT', 14);

define('HUB_LASTMODIFIED_MONTH', 30);



//// AUDIENCE ////

/**
* Audience: educators
*/
define('HUB_AUDIENCE_EDUCATORS', 'educators');

/**
* Audience: students
*/
define('HUB_AUDIENCE_STUDENTS', 'students');

/**
* Audience: admins
*/
define('HUB_AUDIENCE_ADMINS', 'admins');



///// EDUCATIONAL LEVEL /////

/**
* Educational level: primary
*/
define('HUB_EDULEVEL_PRIMARY', 'primary');

/**
* Educational level: secondary
*/
define('HUB_EDULEVEL_SECONDARY', 'secondary');

/**
* Educational level: tertiary
*/
define('HUB_EDULEVEL_TERTIARY', 'tertiary');

/**
* Educational level: government
*/
define('HUB_EDULEVEL_GOVERNMENT', 'government');

/**
* Educational level: association
*/
define('HUB_EDULEVEL_ASSOCIATION', 'association');

/**
* Educational level: corporate
*/
define('HUB_EDULEVEL_CORPORATE', 'corporate');

/**
* Educational level: other
*/
define('HUB_EDULEVEL_OTHER', 'other');



///// FILE TYPES /////

/**
* FILE TYPE: COURSE SCREENSHOT
*/
define('HUB_SCREENSHOT_FILE_TYPE', 'screenshot');

/**
* FILE TYPE: HUB SCREENSHOT
*/
define('HUB_HUBSCREENSHOT_FILE_TYPE', 'hubscreenshot');

/**
* FILE TYPE: BACKUP
*/
define('HUB_BACKUP_FILE_TYPE', 'backup');

/**
*
* Course publication library
*
* @package course
* @copyright 2010 Moodle Pty Ltd (http://moodle.com)
* @author Jerome Mouneyrac
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class course_publish_manager {

    /**
* Record a course publication
* @param int $hubid the hub id from the 'registered on hub' table
* @param int $courseid the course id from site point of view
* @param int $enrollable if the course is enrollable = 1, if downloadable = 0
* @param int $hubcourseid the course id from the hub point of view
*/
    public function add_course_publication($huburl, $courseid, $enrollable, $hubcourseid) {
        global $DB;
        $publication = new stdClass();
        $publication->huburl = $huburl;
        $publication->courseid = $courseid;
        $publication->hubcourseid = $hubcourseid;
        $publication->enrollable = (int) $enrollable;
        $publication->timepublished = time();
        $DB->insert_record('course_published', $publication);
    }

    /**
* Update a enrollable course publication
* @param int $publicationid
*/
    public function update_enrollable_course_publication($publicationid) {
        global $DB;
        $publication = new stdClass();
        $publication->id = $publicationid;
        $publication->timepublished = time();
        $DB->update_record('course_published', $publication);
    }

    /**
* Update a course publication
* @param object $publication
*/
    public function update_publication($publication) {
        global $DB;
        $DB->update_record('course_published', $publication);
    }

    /**
* Get courses publications
* @param int $hubid specify a hub
* @param int $courseid specify a course
* @param int $enrollable specify type of publication (enrollable or downloadable)
* @return array of publications
*/
    public function get_publications($huburl = null, $courseid = null, $enrollable = -1) {
        global $DB;
        $params = array();

        if (!empty($huburl)) {
            $params['huburl'] = $huburl;
        }

        if (!empty($courseid)) {
            $params['courseid'] = $courseid;
        }

        if ($enrollable != -1) {
            $params['enrollable'] = (int) $enrollable;
        }

        return $DB->get_records('course_published', $params);
    }

    /**
* Get a publication for a course id on a hub
* (which is either the id of the unique possible enrollable publication of a course,
* either an id of one of the downloadable publication)
* @param int $hubcourseid
* @param string $huburl
* @return object publication
*/
    public function get_publication($hubcourseid, $huburl) {
        global $DB;
        return $DB->get_record('course_published',
                array('hubcourseid' => $hubcourseid, 'huburl' => $huburl));
    }

    /**
* Get all publication for a course
* @param int $courseid
* @return array of publication
*/
    public function get_course_publications($courseid) {
        global $DB;
        $sql = 'SELECT cp.id, cp.status, cp.timechecked, cp.timepublished, rh.hubname,
rh.huburl, cp.courseid, cp.enrollable, cp.hubcourseid
FROM {course_published} cp, {registration_hubs} rh
WHERE cp.huburl = rh.huburl and cp.courseid = :courseid
ORDER BY cp.enrollable DESC, rh.hubname, cp.timepublished';
        $params = array('courseid' => $courseid);
        return $DB->get_records_sql($sql, $params);
    }

    /**
* Get the hub concerned by a publication
* @param int $publicationid
* @return object the hub (id, name, url, token)
*/
    public function get_registeredhub_by_publication($publicationid) {
        global $DB;
        $sql = 'SELECT rh.huburl, rh.hubname, rh.token
FROM {course_published} cp, {registration_hubs} rh
WHERE cp.huburl = rh.huburl and cp.id = :publicationid';
        $params = array('publicationid' => $publicationid);
        return $DB->get_record_sql($sql, $params);
    }

    /**
* Delete a publication
* @param int $publicationid
*/
    public function delete_publication($publicationid) {
        global $DB;
        $DB->delete_records('course_published', array('id' => $publicationid));
    }

    /**
* Delete publications for a hub
* @param string $huburl
* @param int $enrollable
*/
    public function delete_hub_publications($huburl, $enrollable = -1) {
        global $DB;

        $params = array();

        if (!empty($huburl)) {
            $params['huburl'] = $huburl;
        }

        if ($enrollable != -1) {
            $params['enrollable'] = (int) $enrollable;
        }

        $DB->delete_records('course_published', $params);
    }

    /**
* Get an array of all block instances for a given context
* @param int $contextid a context id
* @return array of block instances.
*/
    public function get_block_instances_by_context($contextid, $sort = '') {
        global $DB;
        return $DB->get_records('block_instances', array('parentcontextid' => $contextid), $sort);
    }

    /**
* Retrieve all the sorted course subjects
* @return array $subjects
*/
    public function get_sorted_subjects() {
        $subjects = get_string_manager()->load_component_strings('edufields', current_language());

        //sort the subjects
        asort($subjects);
        foreach ($subjects as $key => $option) {
            $keylength = strlen($key);
            if ($keylength == 8) {
                $toplevel[$key] = $option;
            } else if ($keylength == 10) {
                $sublevel[substr($key, 0, 8)][$key] = $option;
            } else if ($keylength == 12) {
                $subsublevel[substr($key, 0, 8)][substr($key, 0, 10)][$key] = $option;
            }
        }

        //recreate the initial structure returned by get_string_manager()
        $subjects = array();
        foreach ($toplevel as $key => $name) {
            $subjects[$key] = $name;
            foreach ($sublevel[$key] as $subkey => $subname) {
                $subjects[$subkey] = $subname;
                foreach ($subsublevel[$key][$subkey] as $subsubkey => $subsubname) {
                    $subjects[$subsubkey] = $subsubname;
                }
            }
        }

        return $subjects;
    }

}
?>
Something went wrong with that request. Please try again.