2a439ba7 |
1 | <?PHP // $Id$ |
2 | |
3 | define("REFERENCE", "1"); |
4 | define("WEBPAGE", "2"); |
5 | define("UPLOADEDFILE","3"); |
6 | define("PLAINTEXT", "4"); |
7 | define("WEBLINK", "5"); |
8 | define("HTML", "6"); |
f7a5c8fa |
9 | define("PROGRAM", "7"); |
3e9ca9fb |
10 | define("WIKITEXT", "8"); |
2a439ba7 |
11 | |
12 | $RESOURCE_TYPE = array (REFERENCE => get_string("resourcetype1", "resource"), |
13 | WEBPAGE => get_string("resourcetype2", "resource"), |
14 | UPLOADEDFILE => get_string("resourcetype3", "resource"), |
15 | PLAINTEXT => get_string("resourcetype4", "resource"), |
16 | WEBLINK => get_string("resourcetype5", "resource"), |
f7a5c8fa |
17 | HTML => get_string("resourcetype6", "resource"), |
3e9ca9fb |
18 | PROGRAM => get_string("resourcetype7", "resource"), |
19 | WIKITEXT => get_string("resourcetype8", "resource") ); |
2a439ba7 |
20 | |
92a419a2 |
21 | $RESOURCE_FRAME_SIZE = 130; |
22 | |
23 | |
cccb016a |
24 | function resource_add_instance($resource) { |
25 | // Given an object containing all the necessary data, |
26 | // (defined by the form in mod.html) this function |
27 | // will create a new instance and return the id number |
28 | // of the new instance. |
2a439ba7 |
29 | |
cccb016a |
30 | $resource->timemodified = time(); |
2a439ba7 |
31 | |
cccb016a |
32 | return insert_record("resource", $resource); |
33 | } |
2a439ba7 |
34 | |
cccb016a |
35 | |
36 | function resource_update_instance($resource) { |
37 | // Given an object containing all the necessary data, |
38 | // (defined by the form in mod.html) this function |
39 | // will update an existing instance with new data. |
40 | |
41 | $resource->id = $resource->instance; |
42 | $resource->timemodified = time(); |
43 | |
44 | return update_record("resource", $resource); |
45 | } |
46 | |
47 | |
48 | function resource_delete_instance($id) { |
49 | // Given an ID of an instance of this module, |
50 | // this function will permanently delete the instance |
51 | // and any data that depends on it. |
52 | |
53 | if (! $resource = get_record("resource", "id", "$id")) { |
54 | return false; |
2a439ba7 |
55 | } |
56 | |
cccb016a |
57 | $result = true; |
58 | |
59 | if (! delete_records("resource", "id", "$resource->id")) { |
60 | $result = false; |
2a439ba7 |
61 | } |
62 | |
cccb016a |
63 | return $result; |
2a439ba7 |
64 | } |
cccb016a |
65 | |
2a439ba7 |
66 | |
67 | function resource_user_outline($course, $user, $mod, $resource) { |
ebc3bd2b |
68 | if ($logs = get_records_select("log", "userid='$user->id' AND module='resource' |
69 | AND action='view' AND info='$resource->id'", "time ASC")) { |
2a439ba7 |
70 | |
71 | $numviews = count($logs); |
72 | $lastlog = array_pop($logs); |
73 | |
74 | $result->info = get_string("numviews", "", $numviews); |
75 | $result->time = $lastlog->time; |
76 | |
77 | return $result; |
78 | } |
79 | return NULL; |
80 | } |
81 | |
82 | |
83 | function resource_user_complete($course, $user, $mod, $resource) { |
84 | global $CFG, $THEME; |
85 | |
ebc3bd2b |
86 | if ($logs = get_records_select("log", "userid='$user->id' AND module='resource' |
87 | AND action='view' AND info='$resource->id'", "time ASC")) { |
2a439ba7 |
88 | $numviews = count($logs); |
89 | $lastlog = array_pop($logs); |
90 | |
91 | $strmostrecently = get_string("mostrecently"); |
92 | $strnumviews = get_string("numviews", "", $numviews); |
93 | |
94 | echo "$strnumviews - $strmostrecently ".userdate($lastlog->time); |
95 | |
96 | } else { |
4282d7dd |
97 | print_string("neverseen", "resource"); |
2a439ba7 |
98 | } |
99 | } |
100 | |
2a439ba7 |
101 | |
102 | ?> |