course publication MDL-19315 split /lib/hublib.php into admin/registration/lib.php...
[moodle.git] / course / publish / lib.php
CommitLineData
94788de2 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
19//// AUDIENCE ////
20
21/**
22 * Audience: educators
23 */
24define('HUB_AUDIENCE_EDUCATORS', 'educators');
25
26/**
27 * Audience: students
28 */
29define('HUB_AUDIENCE_STUDENTS', 'students');
30
31/**
32 * Audience: admins
33 */
34define('HUB_AUDIENCE_ADMINS', 'admins');
35
36
37
38///// EDUCATIONAL LEVEL /////
39
40/**
41 * Educational level: primary
42 */
43define('HUB_EDULEVEL_PRIMARY', 'primary');
44
45/**
46 * Educational level: secondary
47 */
48define('HUB_EDULEVEL_SECONDARY', 'secondary');
49
50/**
51 * Educational level: tertiary
52 */
53define('HUB_EDULEVEL_TERTIARY', 'tertiary');
54
55/**
56 * Educational level: government
57 */
58define('HUB_EDULEVEL_GOVERNMENT', 'government');
59
60/**
61 * Educational level: association
62 */
63define('HUB_EDULEVEL_ASSOCIATION', 'association');
64
65/**
66 * Educational level: corporate
67 */
68define('HUB_EDULEVEL_CORPORATE', 'corporate');
69
70/**
71 * Educational level: other
72 */
73define('HUB_EDULEVEL_OTHER', 'other');
74
75
76
77///// FILE TYPES /////
78
79/**
80 * FILE TYPE: COURSE SCREENSHOT
81 */
82define('HUB_SCREENSHOT_FILE_TYPE', 'screenshot');
83
84/**
85 * FILE TYPE: HUB SCREENSHOT
86 */
87define('HUB_HUBSCREENSHOT_FILE_TYPE', 'hubscreenshot');
88
89/**
90 * FILE TYPE: BACKUP
91 */
92define('HUB_BACKUP_FILE_TYPE', 'backup');
93
94
95
96/**
97 *
98 * Course publication library
99 *
100 * @package course
101 * @copyright 2010 Moodle Pty Ltd (http://moodle.com)
102 * @author Jerome Mouneyrac
103 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
104 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
105 */
106
107class course_publish_manager {
108
109 /**
110 * Record a course publication
111 * @param int $hubid the hub id from the 'registered on hub' table
112 * @param int $courseid the course id from site point of view
113 * @param int $enrollable if the course is enrollable = 1, if downloadable = 0
114 * @param int $hubcourseid the course id from the hub point of view
115 */
116 public function add_course_publication($hubid, $courseid, $enrollable, $hubcourseid) {
117 global $DB;
118 $publication = new stdClass();
119 $publication->hubid = $hubid;
120 $publication->courseid = $courseid;
121 $publication->hubcourseid = $hubcourseid;
122 $publication->enrollable = $enrollable;
123 $publication->timepublished = time();
124 $DB->insert_record('course_published', $publication);
125 }
126
127 /**
128 * Update a enrollable course publication
129 * @param int $publicationid
130 */
131 public function update_enrollable_course_publication($publicationid) {
132 global $DB;
133 $publication = new stdClass();
134 $publication->id = $publicationid;
135 $publication->timepublished = time();
136 $DB->update_record('course_published', $publication);
137 }
138
139 /**
140 * Update a course publication
141 * @param object $publication
142 */
143 public function update_publication($publication) {
144 global $DB;
145 $DB->update_record('course_published', $publication);
146 }
147
148 /**
149 * Get courses publication for a given hub, a given course and a given type (enrollable or downloadable)
150 * @param int $hubid
151 * @param int $courseid
152 * @param int $enrollable
153 * @return array of publications
154 */
155 public function get_publications($hubid, $courseid, $enrollable) {
156 global $DB;
157 return $DB->get_records('course_published',
158 array('hubid' => $hubid, 'courseid' => $courseid, 'enrollable' => $enrollable));
159 }
160
161 /**
162 * Get a publication for a course id on the hub
163 * (which is either the id of the unique possible enrollable publication of a course,
164 * either an id of one of the downloadable publication)
165 * @param int $hubcourseid
166 * @return object publication
167 */
168 public function get_publication($hubcourseid) {
169 global $DB;
170 return $DB->get_record('course_published',
171 array('hubcourseid' => $hubcourseid));
172 }
173
174 /**
175 * Get all publication for a course
176 * @param int $courseid
177 * @return array of publication
178 */
179 public function get_course_publications($courseid) {
180 global $DB;
181 $sql = 'SELECT cp.id, cp.status, cp.timechecked, cp.timepublished, rh.hubname, rh.huburl, cp.courseid, cp.enrollable, cp.hubcourseid
182 FROM {course_published} cp, {registration_hubs} rh
183 WHERE cp.hubid = rh.id and cp.courseid = :courseid
184 ORDER BY cp.enrollable DESC, rh.hubname, cp.timepublished';
185 $params = array('courseid' => $courseid);
186 return $DB->get_records_sql($sql, $params);
187 }
188
189 /**
190 * Get the hub concerned by a publication
191 * @param int $publicationid
192 * @return object the hub (id, name, url, token)
193 */
194 public function get_registeredhub_by_publication($publicationid) {
195 global $DB;
196 $sql = 'SELECT cp.hubid, rh.hubname, rh.huburl, rh.token
197 FROM {course_published} cp, {registration_hubs} rh
198 WHERE cp.hubid = rh.id and cp.id = :publicationid';
199 $params = array('publicationid' => $publicationid);
200 return $DB->get_record_sql($sql, $params);
201 }
202
203 /**
204 * Delete a publication
205 * @param int $publicationid
206 */
207 public function delete_publication($publicationid) {
208 global $DB;
209 $DB->delete_records('course_published', array('id' => $publicationid));
210 }
211
212
213 /**
214 * Get an array of all block instances for a given context
215 * @param int $contextid a context id
216 * @return array of block instances.
217 */
218 public function get_block_instances_by_context($contextid, $sort = '') {
219 global $DB;
220 return $DB->get_records('block_instances', array('parentcontextid' => $contextid), $sort);
221 }
222}
223
224?>