1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// This program 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 |
// This program 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 |
* Library of interface functions and constants for module edusharing
|
|
|
19 |
*
|
|
|
20 |
* All the core Moodle functions, needed to allow the module to work
|
|
|
21 |
* integrated in Moodle should be placed here.
|
|
|
22 |
* All the edusharing specific functions, needed to implement all the module
|
|
|
23 |
* logic, should go to locallib.php. This will help to save some memory when
|
|
|
24 |
* Moodle is performing actions across all modules.
|
|
|
25 |
*
|
|
|
26 |
* @package mod_edusharing
|
|
|
27 |
* @copyright metaVentis GmbH — http://metaventis.com
|
|
|
28 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
29 |
*
|
|
|
30 |
*/
|
|
|
31 |
|
|
|
32 |
use mod_edusharing\EduSharingService;
|
|
|
33 |
use mod_edusharing\UtilityFunctions;
|
|
|
34 |
|
|
|
35 |
defined('MOODLE_INTERNAL') || die();
|
|
|
36 |
|
|
|
37 |
set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/lib');
|
|
|
38 |
|
|
|
39 |
/**
|
|
|
40 |
* Module feature detection.
|
|
|
41 |
*
|
|
|
42 |
* @param string $feature FEATURE_xx constant for requested feature
|
|
|
43 |
* @return int|bool True if module supports feature, false if not, null if doesn't know
|
|
|
44 |
*/
|
|
|
45 |
function edusharing_supports(string $feature): int|bool {
|
|
|
46 |
return match ($feature) {
|
|
|
47 |
FEATURE_MOD_ARCHETYPE => MOD_ARCHETYPE_RESOURCE,
|
|
|
48 |
FEATURE_MOD_INTRO, FEATURE_SHOW_DESCRIPTION, FEATURE_BACKUP_MOODLE2 => true,
|
|
|
49 |
default => false,
|
|
|
50 |
};
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
/**
|
|
|
54 |
* Given an object containing all the necessary data,
|
|
|
55 |
* (defined by the form in mod_form.php) this function
|
|
|
56 |
* will create a new instance and return the id number
|
|
|
57 |
* of the new instance.
|
|
|
58 |
*
|
|
|
59 |
* @param stdClass $edusharing An object from the form in mod_form.php
|
|
|
60 |
* @return int|bool The id of the newly inserted edusharing record
|
|
|
61 |
*/
|
|
|
62 |
function edusharing_add_instance(stdClass $edusharing): int|bool {
|
|
|
63 |
$service = new EduSharingService();
|
|
|
64 |
try {
|
|
|
65 |
$id = $service->add_instance($edusharing);
|
|
|
66 |
} catch (Exception $exception) {
|
|
|
67 |
debugging('Instance creation failed: ' . $exception->getMessage());
|
|
|
68 |
return false;
|
|
|
69 |
}
|
|
|
70 |
return $id;
|
|
|
71 |
}
|
|
|
72 |
|
|
|
73 |
/**
|
|
|
74 |
* Function edusharing_update_instance
|
|
|
75 |
*
|
|
|
76 |
* Given an object containing all the necessary data,
|
|
|
77 |
* (defined by the form in mod_form.php) this function
|
|
|
78 |
* will update an existing instance with new data.
|
|
|
79 |
*
|
|
|
80 |
* @param stdClass $edusharing An object from the form in mod_form.php
|
|
|
81 |
* @return boolean Success/Fail
|
|
|
82 |
*/
|
|
|
83 |
function edusharing_update_instance(stdClass $edusharing): bool {
|
|
|
84 |
$service = new EduSharingService();
|
|
|
85 |
try {
|
|
|
86 |
$service->update_instance($edusharing);
|
|
|
87 |
} catch (Exception $exception) {
|
|
|
88 |
debugging('Instance update failed: ' . $exception->getMessage());
|
|
|
89 |
return false;
|
|
|
90 |
}
|
|
|
91 |
return true;
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
/**
|
|
|
95 |
* Given an ID of an instance of this module,
|
|
|
96 |
* this function will permanently delete the instance
|
|
|
97 |
* and any data that depends on it.
|
|
|
98 |
*
|
|
|
99 |
* @param int $id Id of the module instance
|
|
|
100 |
* @return boolean Success/Failure
|
|
|
101 |
*/
|
|
|
102 |
function edusharing_delete_instance($id): bool {
|
|
|
103 |
$service = new EduSharingService();
|
|
|
104 |
try {
|
|
|
105 |
$service->delete_instance((string)$id);
|
|
|
106 |
} catch (Exception $exception) {
|
|
|
107 |
debugging('Instance deletion failed: ' . $exception->getMessage());
|
|
|
108 |
return false;
|
|
|
109 |
}
|
|
|
110 |
return true;
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
|
|
|
114 |
/**
|
|
|
115 |
* Return a small object with summary information about what a
|
|
|
116 |
* user has done with a given particular instance of this module
|
|
|
117 |
* Used for user activity reports.
|
|
|
118 |
*
|
|
|
119 |
* @param object $course
|
|
|
120 |
* @param object $user
|
|
|
121 |
* @param object $mod
|
|
|
122 |
* @param object $edusharing
|
|
|
123 |
*
|
|
|
124 |
* @return stdClass
|
|
|
125 |
*/
|
|
|
126 |
function edusharing_user_outline($course, $user, $mod, $edusharing) {
|
|
|
127 |
$return = new stdClass;
|
|
|
128 |
$return->time = time();
|
|
|
129 |
$return->info = 'edusharing_user_outline() - edu-sharing activity outline.';
|
|
|
130 |
|
|
|
131 |
return $return;
|
|
|
132 |
}
|
|
|
133 |
|
|
|
134 |
/**
|
|
|
135 |
* Print a detailed representation of what a user has done with
|
|
|
136 |
* a given particular instance of this module, for user activity reports.
|
|
|
137 |
*
|
|
|
138 |
* @param object $course
|
|
|
139 |
* @param object $user
|
|
|
140 |
* @param object $mod
|
|
|
141 |
* @param object $edusharing
|
|
|
142 |
*
|
|
|
143 |
* @return boolean
|
|
|
144 |
*/
|
|
|
145 |
function edusharing_user_complete($course, $user, $mod, $edusharing) {
|
|
|
146 |
return true;
|
|
|
147 |
}
|
|
|
148 |
|
|
|
149 |
/**
|
|
|
150 |
* Given a course and a time, this module should find recent activity
|
|
|
151 |
* that has occurred in edusharing activities and print it out.
|
|
|
152 |
* Return true if there was output, or false is there was none.
|
|
|
153 |
*
|
|
|
154 |
* @param object $course
|
|
|
155 |
* @param object $isteacher
|
|
|
156 |
* @param object $timestart
|
|
|
157 |
*
|
|
|
158 |
* @return boolean
|
|
|
159 |
*/
|
|
|
160 |
function edusharing_print_recent_activity($course, $isteacher, $timestart) {
|
|
|
161 |
return false;
|
|
|
162 |
}
|
|
|
163 |
|
|
|
164 |
/**
|
|
|
165 |
* Function to be run periodically according to the moodle cron
|
|
|
166 |
* This function searches for things that need to be done, such
|
|
|
167 |
* as sending out mail, toggling flags etc ...
|
|
|
168 |
*
|
|
|
169 |
* @return boolean
|
|
|
170 |
**/
|
|
|
171 |
function edusharing_cron() {
|
|
|
172 |
return true;
|
|
|
173 |
}
|
|
|
174 |
|
|
|
175 |
/**
|
|
|
176 |
* Must return an array of users who are participants for a given instance
|
|
|
177 |
* of edusharing. Must include every user involved in the instance,
|
|
|
178 |
* independient of his role (student, teacher, admin...). The returned
|
|
|
179 |
* objects must contain at least id property.
|
|
|
180 |
* See other modules as example.
|
|
|
181 |
*
|
|
|
182 |
* @param int $edusharingid ID of an instance of this module
|
|
|
183 |
* @return boolean|array false if no participants, array of objects otherwise
|
|
|
184 |
*/
|
|
|
185 |
function edusharing_get_participants($edusharingid) {
|
|
|
186 |
return false;
|
|
|
187 |
}
|
|
|
188 |
|
|
|
189 |
/**
|
|
|
190 |
* This function returns if a scale is being used by one edusharing
|
|
|
191 |
* if it has support for grading and scales. Commented code should be
|
|
|
192 |
* modified if necessary. See forum, glossary or journal modules
|
|
|
193 |
* as reference.
|
|
|
194 |
*
|
|
|
195 |
* @param int $edusharingid ID of an instance of this module
|
|
|
196 |
* @param int $scaleid
|
|
|
197 |
* @return mixed
|
|
|
198 |
*/
|
|
|
199 |
function edusharing_scale_used($edusharingid, $scaleid) {
|
|
|
200 |
return false;
|
|
|
201 |
}
|
|
|
202 |
|
|
|
203 |
/**
|
|
|
204 |
* Checks if scale is being used by any instance of edusharing.
|
|
|
205 |
* This function was added in 1.9
|
|
|
206 |
*
|
|
|
207 |
* This is used to find out if scale used anywhere
|
|
|
208 |
* @param int $scaleid
|
|
|
209 |
* @return boolean True if the scale is used by any edusharing
|
|
|
210 |
*/
|
|
|
211 |
function edusharing_scale_used_anywhere($scaleid) {
|
|
|
212 |
return false;
|
|
|
213 |
}
|
|
|
214 |
|
|
|
215 |
/**
|
|
|
216 |
* Execute post-install actions for the module
|
|
|
217 |
* This function was added in 1.9
|
|
|
218 |
*
|
|
|
219 |
* @return boolean true if success, false on error
|
|
|
220 |
*/
|
|
|
221 |
function edusharing_install() {
|
|
|
222 |
return true;
|
|
|
223 |
}
|
|
|
224 |
|
|
|
225 |
/**
|
|
|
226 |
* Execute post-uninstall custom actions for the module
|
|
|
227 |
* This function was added in 1.9
|
|
|
228 |
*
|
|
|
229 |
* @return boolean true if success, false on error
|
|
|
230 |
*/
|
|
|
231 |
function edusharing_uninstall() {
|
|
|
232 |
return true;
|
|
|
233 |
}
|
|
|
234 |
|
|
|
235 |
/**
|
|
|
236 |
* Moodle will cache the outpu of this method, so it gets only called after
|
|
|
237 |
* adding or updating an edu-sharing-resource, NOT every time the course
|
|
|
238 |
* is shown.
|
|
|
239 |
*
|
|
|
240 |
* @param stdClass $coursemodule
|
|
|
241 |
* @return stdClass|bool
|
|
|
242 |
*/
|
|
|
243 |
function edusharing_get_coursemodule_info(stdClass $coursemodule): cached_cm_info|bool {
|
|
|
244 |
$utils = new UtilityFunctions();
|
|
|
245 |
return $utils->get_course_module_info($coursemodule);
|
|
|
246 |
}
|
|
|
247 |
|
|
|
248 |
/**
|
|
|
249 |
* Hook called before we delete a course module.
|
|
|
250 |
*
|
|
|
251 |
* @param \stdClass $cm The course module record.
|
|
|
252 |
*/
|
|
|
253 |
function edusharing_pre_course_module_delete($cm) {
|
|
|
254 |
return false;
|
|
|
255 |
}
|
|
|
256 |
|
|
|
257 |
/**
|
|
|
258 |
* Function edusharing_course_module_background_deletion_recommended
|
|
|
259 |
*
|
|
|
260 |
* @return false
|
|
|
261 |
*/
|
|
|
262 |
function edusharing_course_module_background_deletion_recommended() {
|
|
|
263 |
return false;
|
|
|
264 |
}
|
|
|
265 |
|
|
|
266 |
|
|
|
267 |
/**
|
|
|
268 |
* Function edusharing_pre_block_delete
|
|
|
269 |
*
|
|
|
270 |
* @param mixed $cm
|
|
|
271 |
* @return false
|
|
|
272 |
*/
|
|
|
273 |
function edusharing_pre_block_delete($cm) {
|
|
|
274 |
return false;
|
|
|
275 |
}
|
|
|
276 |
|
|
|
277 |
/**
|
|
|
278 |
* Function edusharing_update_settings_images
|
|
|
279 |
*
|
|
|
280 |
* @param string $settingname
|
|
|
281 |
* @return void
|
|
|
282 |
*/
|
|
|
283 |
function edusharing_update_settings_images(string $settingname) {
|
|
|
284 |
$utils = new UtilityFunctions();
|
|
|
285 |
$utils->update_settings_images($settingname);
|
|
|
286 |
}
|
|
|
287 |
|
|
|
288 |
/**
|
|
|
289 |
* Function edusharing_update_settings_name
|
|
|
290 |
*
|
|
|
291 |
* @return void
|
|
|
292 |
*/
|
|
|
293 |
function edusharing_update_settings_name() {
|
|
|
294 |
// Reset language cache.
|
|
|
295 |
get_string_manager()->reset_caches();
|
|
|
296 |
}
|