-
Notifications
You must be signed in to change notification settings - Fork 1
/
lib.php
187 lines (180 loc) · 6.96 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
<?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/>.
/**
* Serve question type files
*
* @since 2.0
* @package qtype_xdom
* @copyright THEYEAR YOURNAME (YOURCONTACTINFO)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Checks file access for xdom questions.
* @package qtype_xdom
* @category files
* @param stdClass $course course object
* @param stdClass $cm course module object
* @param stdClass $context context object
* @param string $filearea file area
* @param array $args extra arguments
* @param bool $forcedownload whether or not force download
* @param array $options additional options affecting the file serving
* @return bool
*/
function qtype_xdom_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=array()) {
global $DB, $CFG;
require_once($CFG->libdir . '/questionlib.php');
//question_pluginfile($course, $context, 'qtype_xdom', $filearea, $args, $forcedownload, $options);
//send_file('qtype_xdom/qtype_xdom_scenebackground/3/','helikopter.x3d');
$fs = get_file_storage();
$fileinfo = array(
'contextid' => CONTEXT_MODULE, // ID of context
'component' => 'qtype_xdom', // usually = component name
'filearea' => 'qtype_xdom_scenebackground', // usually = table name
'itemid' => $args[0], // usually = ID of row in table
'filepath' => "/$args[1]/", // any path beginning and ending in /
'filename' => $args[2]); // any filename
$file = $fs->get_file($fileinfo['contextid'], $fileinfo['component'], $fileinfo['filearea'],
$fileinfo['itemid'], $fileinfo['filepath'], $fileinfo['filename']);
send_stored_file($file);
}
function get_all_scenes_id_name() {
global $DB;
return $DB->get_records_menu('qtype_xdom_scenes',NULL,NULL,'id,name');
}
function get_all_scenes() {
global $DB;
return $DB->get_records_sql("SELECT * FROM mdl_qtype_xdom_scenes");
}
function get_all_shapes() {
global $DB;
return $DB->get_records_sql("SELECT * FROM mdl_qtype_xdom_shapes");
}
function get_all_shapes_id_name() {
global $DB;
return $DB->get_records_menu('qtype_xdom_shapes',NULL,NULL,'id,name');
}
function get_shapes_from_scene($scene_id) {
global $DB;
return $DB->get_records_sql('SELECT mdl_qtype_xdom_sceneshapes.id,name,shapexdom FROM mdl_qtype_xdom_shapes
INNER JOIN mdl_qtype_xdom_sceneshapes ON mdl_qtype_xdom_shapes.id = mdl_qtype_xdom_sceneshapes.shape
WHERE scene=?',array($scene_id));
}
function get_all_background_scenes_id_name() {
global $DB;
return $DB->get_records_menu('qtype_xdom_scenebackground',NULL,NULL,'id,name');
}
function get_all_background_scenes() {
global $DB;
return $DB->get_records_sql("SELECT * FROM mdl_qtype_xdom_scenebackground");
}
function ubaci_folder($dir,$filepath) {
$fs = get_file_storage();
//$dir='C:\\wamp\www\modeli\novo\binGeo\\';
if (!is_dir($dir)) {
throw new moodle_exception($dir.' nije direktorijum.');
}
$dh = opendir($dir);
while (($file = readdir($dh)) !== false){
if ($file=='.' || $file=='..')
continue;
$fileinfo = array(
'contextid' => CONTEXT_MODULE, // ID of context
'component' => 'qtype_xdom', // usually = component name
'filearea' => 'qtype_xdom_scenebackground', // usually = table name
'itemid' => 3, // usually = ID of row in table
'filepath' => $filepath, // any path beginning and ending in /
'filename' => $file
);
$fs->create_file_from_pathname($fileinfo,$dir.$file);
//var_dump($file);
}
}
function izbrisi_file($filename,$itemid) {
$fs = get_file_storage();
$fileinfo = array(
'contextid' => CONTEXT_MODULE, // ID of context
'component' => 'qtype_xdom', // usually = component name
'filearea' => 'qtype_xdom_scenebackground', // usually = table name
'itemid' => $itemid, // usually = ID of row in table
'filepath' => '/x3d/', // any path beginning and ending in /
'filename' => $filename); // any filename
$file = $fs->delete_area_files($fileinfo['contextid'], $fileinfo['component'], $fileinfo['filearea'],
$fileinfo['itemid'], $fileinfo['filepath'], $fileinfo['filename']);
return $file;
}
function ubaci_fajl($name, $data,$id) {
$fs = get_file_storage();
$fileinfo = array(
'contextid' => CONTEXT_MODULE, // ID of context
'component' => 'qtype_xdom', // usually = component name
'filearea' => 'qtype_xdom_scenebackground', // usually = table name
'itemid' => $id, // usually = ID of row in table
'filepath' => '/x3d/', // any path beginning and ending in /
'filename' => "$name.x3d"); // any filename
//$file = $fs->create_file_from_pathname($fileinfo,$externalfilepath);
$file = $fs->create_file_from_string($fileinfo,$data);
return $file;
}
function save_new_scene($name, $data) {
global $DB;
$dataObj = new StdClass;
$dataObj->name = $name;
$dataObj->scenebackground = $data;
return $DB->insert_record('qtype_xdom_scenes',$dataObj);
}
function save_new_shape($name, $data){
global $DB;
$dataObj = new StdClass;
$dataObj->name = $name;
$dataObj->scenebackground = $data;
return $DB->insert_record('qtype_xdom_shapes',$dataObj);
}
function save_new_background_scene($name, $data){
global $DB;
$ok = null;
try {
$dataObj = new StdClass();
$dataObj->name = $name;
$dataObj->zipfilename = $name.'.x3d';
$id = $DB->insert_record("qtype_xdom_scenebackground", $dataObj);
if (is_number($id)) {
$ok = ubaci_fajl($name, $data, $id);
return true;
} else {
return false;
}
} catch (Exception $e) {
return false;
}
}
function delete_scene($id) {
global $DB;
try {
return $DB->delete_records('qtype_xdom_scenes',array('id'=>$id));
} catch(Exception $e) {
return false;
}
}
function delete_shape($id) {
global $DB;
try {
return $DB->delete_records('qtype_xdom_shapes',array('id'=>$id));
} catch(Exception $e) {
return false;
}
}