-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlib.php
789 lines (646 loc) · 26.7 KB
/
lib.php
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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
<?php // $Id$
require_once($CFG->libdir.'/portfoliolib.php');
define('RESOURCE_LOCALPATH', 'LOCALPATH');
global $RESOURCE_WINDOW_OPTIONS; // must be global because it might be included from a function!
$RESOURCE_WINDOW_OPTIONS = array('resizable', 'scrollbars', 'directories', 'location',
'menubar', 'toolbar', 'status', 'width', 'height');
if (!isset($CFG->resource_hide_repository)) {
set_config("resource_hide_repository", "1");
}
/**
* resource_base is the base class for resource types
*
* This class provides all the functionality for a resource
*/
class resource_base {
var $cm;
var $course;
var $resource;
var $navlinks;
/**
* Constructor for the base resource class
*
* Constructor for the base resource class.
* If cmid is set create the cm, course, resource objects.
* and do some checks to make sure people can be here, and so on.
*
* @param cmid integer, the current course module id - not set for new resources
*/
function resource_base($cmid=0) {
global $CFG, $COURSE, $DB;
$this->navlinks = array();
if ($cmid) {
if (! $this->cm = get_coursemodule_from_id('resource', $cmid)) {
print_error('invalidcoursemodule');
}
if (! $this->course = $DB->get_record("course", array("id"=>$this->cm->course))) {
print_error('coursemisconf');
}
if (! $this->resource = $DB->get_record("resource", array("id"=>$this->cm->instance))) {
print_error('invalidid', 'resource');
}
$this->strresource = get_string("modulename", "resource");
$this->strresources = get_string("modulenameplural", "resource");
if (!$this->cm->visible and !has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_MODULE, $this->cm->id))) {
$pagetitle = strip_tags($this->course->shortname.': '.$this->strresource);
$navigation = build_navigation($this->navlinks, $this->cm);
print_header($pagetitle, $this->course->fullname, $navigation, "", "", true, '', navmenu($this->course, $this->cm));
notice(get_string("activityiscurrentlyhidden"), "$CFG->wwwroot/course/view.php?id={$this->course->id}");
}
} else {
$this->course = $COURSE;
}
}
/**
* Display function does nothing in the base class
*/
function display() {
}
/**
* Display the resource with the course blocks.
*/
function display_course_blocks_start() {
global $CFG, $USER, $THEME;
require_once($CFG->dirroot.'/course/lib.php'); //required by some blocks
$PAGE = page_create_object(PAGE_COURSE_VIEW, $this->course->id);
$PAGE->set_url('mod/resource/view.php', array('id' => $this->cm->id));
$this->PAGE = $PAGE;
$pageblocks = blocks_setup($PAGE);
$blocks_preferred_width = bounded_number(180, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]), 210);
/// Print the page header
$edit = optional_param('edit', -1, PARAM_BOOL);
if (($edit != -1) and $PAGE->user_allowed_editing()) {
$USER->editing = $edit;
}
$morenavlinks = array($this->strresources => 'index.php?id='.$this->course->id,
$this->resource->name => '');
$PAGE->print_header($this->course->shortname.': %fullname%', $morenavlinks, "", "",
update_module_button($this->cm->id, $this->course->id, $this->strresource));
echo '<table id="layout-table"><tr>';
$lt = (empty($THEME->layouttable)) ? array('left', 'middle', 'right') : $THEME->layouttable;
foreach ($lt as $column) {
$lt1[] = $column;
if ($column == 'middle') break;
}
foreach ($lt1 as $column) {
switch ($column) {
case 'left':
if((blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $PAGE->user_is_editing())) {
echo '<td style="width: '.$blocks_preferred_width.'px;" id="left-column">';
print_container_start();
blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
print_container_end();
echo '</td>';
}
break;
case 'middle':
echo '<td id="middle-column">';
print_container_start(false, 'middle-column-wrap');
echo '<div id="resource">';
break;
case 'right':
if((blocks_have_content($pageblocks, BLOCK_POS_RIGHT) || $PAGE->user_is_editing())) {
echo '<td style="width: '.$blocks_preferred_width.'px;" id="right-column">';
print_container_start();
blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT);
print_container_end();
echo '</td>';
}
break;
}
}
}
/**
* Finish displaying the resource with the course blocks
*/
function display_course_blocks_end() {
global $CFG, $THEME;
$PAGE = $this->PAGE;
$pageblocks = blocks_setup($PAGE);
$blocks_preferred_width = bounded_number(180, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]), 210);
$lt = (empty($THEME->layouttable)) ? array('left', 'middle', 'right') : $THEME->layouttable;
foreach ($lt as $column) {
if ($column != 'middle') {
array_shift($lt);
} else if ($column == 'middle') {
break;
}
}
foreach ($lt as $column) {
switch ($column) {
case 'left':
if((blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $PAGE->user_is_editing())) {
echo '<td style="width: '.$blocks_preferred_width.'px;" id="left-column">';
print_container_start();
blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
print_container_end();
echo '</td>';
}
break;
case 'middle':
echo '</div>';
print_container_end();
echo '</td>';
break;
case 'right':
if((blocks_have_content($pageblocks, BLOCK_POS_RIGHT) || $PAGE->user_is_editing())) {
echo '<td style="width: '.$blocks_preferred_width.'px;" id="right-column">';
print_container_start();
blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT);
print_container_end();
echo '</td>';
}
break;
}
}
echo '</tr></table>';
print_footer($this->course);
}
function add_instance($resource) {
global $DB;
// Given an object containing all the necessary data,
// (defined by the form in mod_form.php) this function
// will create a new instance and return the id number
// of the new instance.
$resource->timemodified = time();
return $DB->insert_record("resource", $resource);
}
function update_instance($resource) {
global $DB;
// Given an object containing all the necessary data,
// (defined by the form in mod_form.php) this function
// will update an existing instance with new data.
$resource->id = $resource->instance;
$resource->timemodified = time();
return $DB->update_record("resource", $resource);
}
function delete_instance($resource) {
global $DB;
// Given an object containing the resource data
// this function will permanently delete the instance
// and any data that depends on it.
$result = true;
if (! $DB->delete_records("resource", array("id"=>$resource->id))) {
$result = false;
}
return $result;
}
function setup_elements(&$mform) {
//override to add your own options
}
function setup_preprocessing(&$default_values){
//override to add your own options
}
function portfolio_prepare_package_uploaded($exporter) {
// @todo penny implement later - see MDL-15758
}
function portfolio_prepare_package_online($exporter, $text=false) {
$filename = clean_filename($this->cm->name . '.' . 'html');
$formatoptions = (object)array('noclean' => true);
$format = (($text) ? FORMAT_MOODLE : FORMAT_HTML);
$content = format_text($this->resource->alltext, $format, $formatoptions, $this->course->id);
return $exporter->write_new_file($content, $filename, false);
}
function portfolio_get_sha1_online($text=false) {
$formatoptions = (object)array('noclean' => true);
$format = (($text) ? FORMAT_MOODLE : FORMAT_HTML);
$content = format_text($this->resource->alltext, $format, $formatoptions, $this->course->id);
return sha1($content);
}
function portfolio_get_sha1_uploaded() {
// @todo penny implement later.
}
} /// end of class definition
function resource_add_instance($resource) {
global $CFG;
$resource->type = clean_param($resource->type, PARAM_SAFEDIR); // Just to be safe
require_once("$CFG->dirroot/mod/resource/type/$resource->type/resource.class.php");
$resourceclass = "resource_$resource->type";
$res = new $resourceclass();
return $res->add_instance($resource);
}
function resource_update_instance($resource) {
global $CFG;
$resource->type = clean_param($resource->type, PARAM_SAFEDIR); // Just to be safe
require_once("$CFG->dirroot/mod/resource/type/$resource->type/resource.class.php");
$resourceclass = "resource_$resource->type";
$res = new $resourceclass();
return $res->update_instance($resource);
}
function resource_delete_instance($id) {
global $CFG, $DB;
if (! $resource = $DB->get_record("resource", array("id"=>$id))) {
return false;
}
$resource->type = clean_param($resource->type, PARAM_SAFEDIR); // Just to be safe
require_once("$CFG->dirroot/mod/resource/type/$resource->type/resource.class.php");
$resourceclass = "resource_$resource->type";
$res = new $resourceclass();
return $res->delete_instance($resource);
}
function resource_user_outline($course, $user, $mod, $resource) {
global $DB;
if ($logs = $DB->get_records("log", array('userid'=>$user->id, 'module'=>'resource',
'action'=>'view', 'info'=>$resource->id), "time ASC")) {
$numviews = count($logs);
$lastlog = array_pop($logs);
$result = new object();
$result->info = get_string("numviews", "", $numviews);
$result->time = $lastlog->time;
return $result;
}
return NULL;
}
function resource_user_complete($course, $user, $mod, $resource) {
global $CFG, $DB;
if ($logs = $DB->get_records("log", array('userid'=>$user->id, 'module'=>'resource',
'action'=>'view', 'info'=>$resource->id), "time ASC")) {
$numviews = count($logs);
$lastlog = array_pop($logs);
$strmostrecently = get_string("mostrecently");
$strnumviews = get_string("numviews", "", $numviews);
echo "$strnumviews - $strmostrecently ".userdate($lastlog->time);
} else {
print_string("neverseen", "resource");
}
}
function resource_get_participants($resourceid) {
//Returns the users with data in one resource
//(NONE, byt must exists on EVERY mod !!)
return false;
}
function resource_get_coursemodule_info($coursemodule) {
/// Given a course_module object, this function returns any
/// "extra" information that may be needed when printing
/// this activity in a course listing.
///
/// See get_array_of_activities() in course/lib.php
///
global $CFG, $DB;
$info = NULL;
if ($resource = $DB->get_record("resource", array("id"=>$coursemodule->instance), 'id, popup, reference, type, name')) {
$info = new object();
$info->name = $resource->name;
if (!empty($resource->popup)) {
$info->extra = urlencode("onclick=\"this.target='resource$resource->id'; return ".
"openpopup('/mod/resource/view.php?inpopup=true&id=".
$coursemodule->id.
"','resource$resource->id','$resource->popup');\"");
}
require_once($CFG->libdir.'/filelib.php');
$customicon = $CFG->dirroot.'/mod/resource/type/'.$resource->type.'/icon.gif';
if ($resource->type == 'file') {
$icon = mimeinfo("icon", $resource->reference);
if ($icon != 'unknown.gif') {
$info->icon ="f/$icon";
} else {
$info->icon ="f/web.gif";
}
} else if ($resource->type == 'directory') {
$info->icon ="f/folder.gif";
} else if (file_exists($customicon)) {
$info->icon ='mod/resource/type/'.$resource->type.'/icon.gif';
}
}
return $info;
}
function resource_redirect_tags($text, $url, $tagtoparse, $keytoparse,$prefix = "" ) {
$valid = 1;
if ( strpos($url,"?") == FALSE ) {
$valid = 1;
}
if ( $valid ) {
$lastpoint = strrpos($url,".");
$lastslash = strrpos($url,"/");
if ( $lastpoint > $lastslash ) {
$root = substr($url,0,$lastslash+1);
} else {
$root = $url;
}
if ( $root == "http://" or
$root == "https://") {
$root = $url;
}
if ( substr($root,strlen($root)-1) == '/' ) {
$root = substr($root,0,-1);
}
$mainroot = $root;
$lastslash = strrpos($mainroot,"/");
while ( $lastslash > 9) {
$mainroot = substr($mainroot,0,$lastslash);
$lastslash = strrpos($mainroot,"/");
}
$regex = "/<$tagtoparse (.+?)>/is";
$count = preg_match_all($regex, $text, $hrefs);
for ( $i = 0; $i < $count; $i++) {
$tag = $hrefs[1][$i];
$poshref = strpos(strtolower($tag),strtolower($keytoparse));
$start = $poshref + strlen($keytoparse);
$left = substr($tag,0,$start);
if ( $tag[$start] == '"' ) {
$left .= '"';
$start++;
}
$posspace = strpos($tag," ", $start+1);
$right = "";
if ( $posspace != FALSE) {
$right = substr($tag, $posspace);
}
$end = strlen($tag)-1;
if ( $tag[$end] == '"' ) {
$right = '"' . $right;
}
$finalurl = substr($tag,$start,$end-$start+$diff);
// Here, we could have these possible values for $finalurl:
// file.ext Add current root dir
// http://(domain) don't care
// http://(domain)/ don't care
// http://(domain)/folder don't care
// http://(domain)/folder/ don't care
// http://(domain)/folder/file.ext don't care
// folder/ Add current root dir
// folder/file.ext Add current root dir
// /folder/ Add main root dir
// /folder/file.ext Add main root dir
// Special case: If finalurl contains a ?, it won't be parsed
$valid = 1;
if ( strpos($finalurl,"?") == FALSE ) {
$valid = 1;
}
if ( $valid ) {
if ( $finalurl[0] == "/" ) {
$finalurl = $mainroot . $finalurl;
} elseif ( strtolower(substr($finalurl,0,7)) != "http://" and
strtolower(substr($finalurl,0,8)) != "https://") {
if ( $finalurl[0] == "/") {
$finalurl = $mainroot . $finalurl;
} else {
$finalurl = "$root/$finalurl";
}
}
$text = str_replace($tag,"$left$prefix$finalurl$right",$text);
}
}
}
return $text;
}
function resource_is_url($path) {
if (strpos($path, '://')) { // eg http:// https:// ftp:// etc
return true;
}
if (strpos($path, '/') === 0) { // Starts with slash
return true;
}
return false;
}
function resource_get_types() {
global $CFG;
$types = array();
$standardresources = array('text','html','file','directory');
foreach ($standardresources as $resourcetype) {
$type = new object();
$type->modclass = MOD_CLASS_RESOURCE;
$type->name = $resourcetype;
$type->type = "resource&type=$resourcetype";
$type->typestr = get_string("resourcetype$resourcetype", 'resource');
$types[] = $type;
}
/// Drop-in extra resource types
$resourcetypes = get_list_of_plugins('mod/resource/type');
foreach ($resourcetypes as $resourcetype) {
if (!empty($CFG->{'resource_hide_'.$resourcetype})) { // Not wanted
continue;
}
if (!in_array($resourcetype, $standardresources)) {
$type = new object();
$type->modclass = MOD_CLASS_RESOURCE;
$type->name = $resourcetype;
$type->type = "resource&type=$resourcetype";
$type->typestr = resource_get_name($resourcetype);
$types[] = $type;
}
}
return $types;
}
function resource_get_view_actions() {
return array('view','view all');
}
function resource_get_post_actions() {
return array();
}
function resource_renamefiles($course, $wdir, $oldname, $name) {
global $CFG, $DB;
$status = '<p align=\"center\"><strong>'.get_string('affectedresources', 'resource').':</strong><ul>';
$updates = false;
$old = trim($wdir.'/'.$oldname, '/');
$new = trim($wdir.'/'.$name, '/');
$sql = "SELECT r.id, r.reference, r.name, cm.id AS cmid
FROM {resource} r, {course_modules} cm, {modules} m
WHERE r.course = :courseid
AND m.name = 'resource'
AND cm.module = m.id
AND cm.instance = r.id
AND (r.type = 'file' OR r.type = 'directory')
AND (r.reference LIKE :old1 OR r.reference = :old2)";
$params = array('courseid'=>$course->id, 'old1'=>"{$old}/%", 'old2'=>$old);
if ($resources = $DB->get_records_sql($sql, $params)) {
foreach ($resources as $resource) {
$r = new object();
$r->id = $resource->id;
$r->reference = '';
if ($resource->reference == $old) {
$r->reference = $new;
} else {
$r->reference = preg_replace('|^'.preg_quote($old, '|').'/|', $new.'/', $resource->reference);
}
if ($r->reference !== '') {
$updates = true;
$status .= "<li><a href=\"$CFG->wwwroot/mod/resource/view.php?id=$resource->cmid\" target=\"_blank\">$resource->name</a>: $resource->reference ==> $r->reference</li>";
if (!empty($CFG->resource_autofilerename)) {
if (!$DB->update_record('resource', $r)) {
print_error('cannotupdate', 'resource');
}
}
}
}
}
$status .= '</ul></p>';
if ($updates) {
echo $status;
if (empty($CFG->resource_autofilerename)) {
notify(get_string('warningdisabledrename', 'resource'));
}
}
}
function resource_delete_warning($course, $files) {
global $CFG, $DB;
$found = array();
foreach($files as $key=>$file) {
$files[$key] = trim($file, '/');
}
$sql = "SELECT r.id, r.reference, r.name, cm.id AS cmid
FROM {resource} r,
{course_modules} cm,
{modules} m
WHERE r.course = ?
AND m.name = 'resource'
AND cm.module = m.id
AND cm.instance = r.id
AND (r.type = 'file' OR r.type = 'directory')";
if ($resources = $DB->get_records_sql($sql, array($course->id))) {
foreach ($resources as $resource) {
if ($resource->reference == '') {
continue; // top shared directory does not prevent anything
}
if (in_array($resource->reference, $files)) {
$found[$resource->id] = $resource;
} else {
foreach($files as $file) {
if (preg_match('|^'.preg_quote($file, '|').'/|', $resource->reference)) {
$found[$resource->id] = $resource;
}
}
}
}
}
if (!empty($found)) {
print_simple_box_start("center");
echo '<p><strong>'.get_string('affectedresources', 'resource').':</strong><ul>';
foreach($found as $resource) {
echo "<li><a href=\"$CFG->wwwroot/mod/resource/view.php?id=$resource->cmid\" target=\"_blank\">$resource->name</a>: $resource->reference</li>";
}
echo '</ul></p>';
print_simple_box_end();
return true;
} else {
return false;
}
}
/**
* This function is used by the reset_course_userdata function in moodlelib.
* @param $data the data submitted from the reset course.
* @return array status array
*/
function resource_reset_userdata($data) {
return array();
}
/**
* Returns all other caps used in module
*/
function resource_get_extra_capabilities() {
return array('moodle/site:accessallgroups');
}
class resource_portfolio_caller extends portfolio_module_caller_base {
private $resource;
private $resourcefile;
public static function expected_callbackargs() {
return array(
'id' => true,
);
}
public function load_data() {
global $CFG, $DB;
if (!$this->cm = get_coursemodule_from_instance('resource', $this->id)) {
throw new portfolio_caller_exception('invalidid');
}
$this->cm->type = $DB->get_field('resource', 'type', array('id' => $this->cm->instance));
$resourceclass = 'resource_'. $this->cm->type;
$this->resourcefile = $CFG->dirroot.'/mod/resource/type/'.$this->cm->type.'/resource.class.php';
require_once($this->resourcefile);
$this->resource= new $resourceclass($this->cm->id);
if (!is_callable(array($this->resource, 'portfolio_prepare_package')) || !is_callable(array($this->resource, 'portfolio_get_sha1'))) {
debug_print_backtrace();
throw new portfolio_exception('portfolionotimplemented', 'resource', null, $this->cm->type);
}
$this->supportedformats = array(self::type_to_format($this->cm->type));
}
public static function type_to_format($type) {
// this is kind of yuk... but there's just not good enough OO here
$format = PORTFOLIO_FORMAT_FILE;
switch ($type) {
case 'html':
$format = PORTFOLIO_FORMAT_PLAINHTML;
case 'text':
$format = PORTFOLIO_FORMAT_TEXT;
case 'file':
// $format = portfolio_format_from_file($file); // change after we switch upload type resources over to new files api.
}
return $format;
}
public function __wakeup() {
global $CFG;
if (empty($CFG)) {
return; // too early yet
}
require_once($this->resourcefile);
$this->resource = unserialize(serialize($this->resource));
}
public function expected_time() {
// @todo penny check filesize if the type is uploadey (not implemented yet)
// like this: return portfolio_expected_time_file($this->file); // or whatever
return PORTFOLIO_TIME_LOW;
}
public function prepare_package() {
return $this->resource->portfolio_prepare_package($this->exporter);
}
public function check_permissions() {
return has_capability('mod/resource:exportresource', get_context_instance(CONTEXT_MODULE, $this->cm->id));
}
public static function add_button($resource, $format=null, $return=false) {
if (!has_capability('mod/resource:exportresource', get_context_instance(CONTEXT_MODULE, $resource->cm->id))) {
return;
}
if (!is_callable(array($resource, 'portfolio_prepare_package')) || !is_callable(array($resource, 'portfolio_get_sha1'))) {
debugging(get_string('portfolionotimplemented', 'resource'));
return false;
}
$callersupports = array(self::type_to_format($resource->resource->type));
if ($resource->resource->type == 'file') {
// $callersupports = array(portfolio_format_from_file($file);
}
$button = new portfolio_add_button();
$button->set_callback_options('resource_portfolio_caller', array('id' => $resource->cm->instance), '/mod/resource/lib.php');
$button->set_formats($callersupports);
if ($return) {
return $button->to_html($format);
}
$button->render($format);
}
public function get_sha1() {
return $this->resource->portfolio_get_sha1();
}
public static function display_name() {
return get_string('modulename', 'resource');
}
}
/**
* @param string $feature FEATURE_xx constant for requested feature
* @return mixed True if module supports feature, null if doesn't know
*/
function resource_supports($feature) {
switch($feature) {
case FEATURE_GROUPS: return false;
case FEATURE_GROUPINGS: return false;
case FEATURE_GROUPMEMBERSONLY: return true;
case FEATURE_MOD_INTRO: return true;
case FEATURE_COMPLETION_TRACKS_VIEWS: return true;
case FEATURE_GRADE_HAS_GRADE: return false;
case FEATURE_GRADE_OUTCOMES: return false;
default: return null;
}
}
/**
* Returns the full name of the given resource type. The name can
* either be set at the resource type level or at the resource module
* level.
*
* @param string $type shortname (or directory name) of the resource type
*/
function resource_get_name($type) {
$name = get_string("resourcetype$type", "resource_$type");
if (substr($name, 0, 2) === '[[') {
$name = get_string("resourcetype$type", 'resource');
}
return $name;
}
?>