@@ -280,6 +280,7 @@ |
||
280 | 280 | } |
281 | 281 | /** |
282 | 282 | * Get dummy titles, descriptions and texts |
283 | + * @param string $type |
|
283 | 284 | */ |
284 | 285 | function get_dummy_content($type) |
285 | 286 | { |
@@ -20,289 +20,289 @@ |
||
20 | 20 | */ |
21 | 21 | class DummyCourseCreator |
22 | 22 | { |
23 | - /** |
|
24 | - * The dummy course |
|
25 | - */ |
|
26 | - public $course; |
|
27 | - /** |
|
28 | - * |
|
29 | - */ |
|
30 | - public $default_property = array(); |
|
23 | + /** |
|
24 | + * The dummy course |
|
25 | + */ |
|
26 | + public $course; |
|
27 | + /** |
|
28 | + * |
|
29 | + */ |
|
30 | + public $default_property = array(); |
|
31 | 31 | |
32 | - /** |
|
33 | - * Create the dummy course |
|
34 | - */ |
|
35 | - public function create_dummy_course($course_code) |
|
36 | - { |
|
37 | - $this->default_property['insert_user_id'] = '1'; |
|
38 | - $this->default_property['insert_date'] = date('Y-m-d H:i:s'); |
|
39 | - $this->default_property['lastedit_date'] = date('Y-m-d H:i:s'); |
|
40 | - $this->default_property['lastedit_user_id'] = '1'; |
|
41 | - $this->default_property['to_group_id'] = '0'; |
|
42 | - $this->default_property['to_user_id'] = null; |
|
43 | - $this->default_property['visibility'] = '1'; |
|
44 | - $this->default_property['start_visible'] = '0000-00-00 00:00:00'; |
|
45 | - $this->default_property['end_visible'] = '0000-00-00 00:00:00'; |
|
32 | + /** |
|
33 | + * Create the dummy course |
|
34 | + */ |
|
35 | + public function create_dummy_course($course_code) |
|
36 | + { |
|
37 | + $this->default_property['insert_user_id'] = '1'; |
|
38 | + $this->default_property['insert_date'] = date('Y-m-d H:i:s'); |
|
39 | + $this->default_property['lastedit_date'] = date('Y-m-d H:i:s'); |
|
40 | + $this->default_property['lastedit_user_id'] = '1'; |
|
41 | + $this->default_property['to_group_id'] = '0'; |
|
42 | + $this->default_property['to_user_id'] = null; |
|
43 | + $this->default_property['visibility'] = '1'; |
|
44 | + $this->default_property['start_visible'] = '0000-00-00 00:00:00'; |
|
45 | + $this->default_property['end_visible'] = '0000-00-00 00:00:00'; |
|
46 | 46 | |
47 | - $course = api_get_course_info($course_code); |
|
48 | - $this->course = new Course(); |
|
49 | - $tmp_path = api_get_path(SYS_COURSE_PATH).$course['directory'].'/document/tmp_'.uniqid(''); |
|
50 | - @mkdir($tmp_path, api_get_permissions_for_new_directories(), true); |
|
51 | - $this->course->backup_path = $tmp_path; |
|
52 | - $this->create_dummy_links(); |
|
53 | - $this->create_dummy_events(); |
|
54 | - $this->create_dummy_forums(); |
|
55 | - $this->create_dummy_announcements(); |
|
56 | - $this->create_dummy_documents(); |
|
57 | - $this->create_dummy_learnpaths(); |
|
58 | - $cr = new CourseRestorer($this->course); |
|
59 | - $cr->set_file_option(FILE_OVERWRITE); |
|
60 | - $cr->restore($course_code); |
|
61 | - rmdirr($tmp_path); |
|
62 | - } |
|
63 | - /** |
|
64 | - * Create dummy documents |
|
65 | - */ |
|
66 | - function create_dummy_documents() |
|
67 | - { |
|
68 | - $course = api_get_course_info(); |
|
69 | - $course_doc_path = $this->course->backup_path.'/document/'; |
|
70 | - $number_of_documents = rand(10, 30); |
|
71 | - $extensions = array ('html', 'doc'); |
|
72 | - $directories = array(); |
|
73 | - $property = $this->default_property; |
|
74 | - $property['lastedit_type'] = 'DocumentAdded'; |
|
75 | - $property['tool'] = TOOL_DOCUMENT; |
|
76 | - $doc_id = 0; |
|
77 | - for ($doc_id = 1; $doc_id < $number_of_documents; $doc_id ++) |
|
78 | - { |
|
79 | - $path = ''; |
|
80 | - $doc_type = rand(0, count($extensions) - 1); |
|
81 | - $extension = $extensions[$doc_type]; |
|
82 | - $filename = $this->get_dummy_content('title').'_'.$doc_id.'.'.$extension; |
|
83 | - $content = $this->get_dummy_content('text'); |
|
84 | - $dirs = rand(0, 3); |
|
85 | - for ($i = 0; $i < $dirs; $i ++) |
|
86 | - { |
|
87 | - $path .= 'directory/'; |
|
88 | - $directories[$path] = 1; |
|
89 | - } |
|
90 | - $dir_to_make = $course_doc_path.$path; |
|
91 | - if (!is_dir($dir_to_make)) |
|
92 | - { |
|
93 | - @mkdir($dir_to_make, api_get_permissions_for_new_directories(), true); |
|
94 | - } |
|
95 | - $file = $course_doc_path.$path.$filename; |
|
96 | - $fp = fopen($file, 'w'); |
|
97 | - fwrite($fp, $content); |
|
98 | - fclose($fp); |
|
99 | - $size = filesize($file); |
|
100 | - $document = new Document($doc_id, '/'.$path.$filename,$this->get_dummy_content('description'),$this->get_dummy_content('title'), 'file', $size); |
|
101 | - $document->item_properties[] = $property; |
|
102 | - $this->course->add_resource($document); |
|
103 | - } |
|
104 | - foreach($directories as $path => $flag) |
|
105 | - { |
|
106 | - $path = substr($path,0,strlen($path)-1); |
|
107 | - $document = new Document($doc_id++,'/'.$path, $this->get_dummy_content('description'),$this->get_dummy_content('title'),'folder',0); |
|
108 | - $property['lastedit_type'] = 'FolderCreated'; |
|
109 | - $document->item_properties[] = $property; |
|
110 | - $this->course->add_resource($document); |
|
111 | - } |
|
112 | - } |
|
113 | - /** |
|
114 | - * Create dummy announcements |
|
115 | - */ |
|
116 | - function create_dummy_announcements() |
|
117 | - { |
|
118 | - $property = $this->default_property; |
|
119 | - $property['lastedit_type'] = 'AnnouncementAdded'; |
|
120 | - $property['tool'] = TOOL_ANNOUNCEMENT; |
|
121 | - $number_of_announcements = rand(10, 30); |
|
122 | - for ($i = 0; $i < $number_of_announcements; $i ++) |
|
123 | - { |
|
124 | - $time = mktime(rand(1, 24), rand(1, 60), 0, rand(1, 12), rand(1, 28), intval(date('Y'))); |
|
125 | - $date = date('Y-m-d', $time); |
|
126 | - $announcement = new Announcement($i,$this->get_dummy_content('title'),$this->get_dummy_content('text'), $date,0); |
|
127 | - $announcement->item_properties[] = $property; |
|
128 | - $this->course->add_resource($announcement); |
|
129 | - } |
|
130 | - } |
|
131 | - /** |
|
132 | - * Create dummy events |
|
133 | - */ |
|
134 | - function create_dummy_events() |
|
135 | - { |
|
136 | - $number_of_events = rand(10, 30); |
|
137 | - $property = $this->default_property; |
|
138 | - $property['lastedit_type'] = 'AgendaAdded'; |
|
139 | - $property['tool'] = TOOL_CALENDAR_EVENT; |
|
140 | - for ($i = 0; $i < $number_of_events; $i ++) |
|
141 | - { |
|
142 | - $hour = rand(1,24); |
|
143 | - $minute = rand(1,60); |
|
144 | - $second = rand(1,60); |
|
145 | - $day = rand(1,28); |
|
146 | - $month = rand(1,12); |
|
147 | - $year = intval(date('Y')); |
|
148 | - $time = mktime($hour,$minute,$second,$month,$day,$year); |
|
149 | - $start_date = date('Y-m-d H:m:s', $time); |
|
150 | - $hour = rand($hour,24); |
|
151 | - $minute = rand($minute,60); |
|
152 | - $second = rand($second,60); |
|
153 | - $day = rand($day,28); |
|
154 | - $month = rand($month,12); |
|
155 | - $year = intval(date('Y')); |
|
156 | - $time = mktime($hour,$minute,$second,$month,$day,$year); |
|
157 | - $end_date = date('Y-m-d H:m:s', $time); |
|
158 | - $event = new CalendarEvent( |
|
159 | - $i, |
|
160 | - $this->get_dummy_content('title'), |
|
161 | - $this->get_dummy_content('text'), |
|
162 | - $start_date, |
|
163 | - $end_date |
|
164 | - ); |
|
165 | - $event->item_properties[] = $property; |
|
166 | - $this->course->add_resource($event); |
|
167 | - } |
|
168 | - } |
|
169 | - /** |
|
170 | - * Create dummy links |
|
171 | - */ |
|
172 | - function create_dummy_links() |
|
173 | - { |
|
174 | - // create categorys |
|
175 | - $number_of_categories = rand(5, 10); |
|
176 | - for ($i = 0; $i < $number_of_categories; $i ++) |
|
177 | - { |
|
178 | - $linkcat = new LinkCategory($i, $this->get_dummy_content('title'), $this->get_dummy_content('description'),$i); |
|
179 | - $this->course->add_resource($linkcat); |
|
180 | - } |
|
181 | - // create links |
|
182 | - $number_of_links = rand(5, 50); |
|
183 | - $on_homepage = rand(0,20) == 0 ? 1 : 0; |
|
184 | - $property = $this->default_property; |
|
185 | - $property['lastedit_type'] = 'LinkAdded'; |
|
186 | - $property['tool'] = TOOL_LINK; |
|
187 | - for ($i = 0; $i < $number_of_links; $i ++) |
|
188 | - { |
|
189 | - $link = new Link($i, $this->get_dummy_content('title'), 'http://www.google.com/search?q='.$this->get_dummy_content('title'), $this->get_dummy_content('description'), rand(0, $number_of_categories -1),$on_homepage); |
|
190 | - $link->item_properties[] = $property; |
|
191 | - $this->course->add_resource($link); |
|
192 | - } |
|
193 | - } |
|
194 | - /** |
|
195 | - * Create dummy forums |
|
196 | - */ |
|
197 | - function create_dummy_forums() |
|
198 | - { |
|
199 | - $number_of_categories = rand(2, 6); |
|
200 | - $number_of_forums = rand(5, 50); |
|
201 | - $number_of_topics = rand(30, 100); |
|
202 | - $number_of_posts = rand(100, 1000); |
|
203 | - $last_forum_post = array (); |
|
204 | - $last_topic_post = array (); |
|
205 | - // create categorys |
|
206 | - $order = 1; |
|
207 | - for ($i = 1; $i <= $number_of_categories; $i ++) |
|
208 | - { |
|
209 | - $forumcat = new ForumCategory($i, $this->get_dummy_content('title'), $this->get_dummy_content('description'), $order, 0, 0); |
|
210 | - $this->course->add_resource($forumcat); |
|
211 | - $order++; |
|
212 | - } |
|
213 | - // create posts |
|
214 | - for ($post_id = 1; $post_id <= $number_of_posts; $post_id ++) |
|
215 | - { |
|
216 | - $topic_id = rand(1, $number_of_topics); |
|
217 | - $last_topic_post[$topic_id] = $post_id; |
|
218 | - $post = new ForumPost($post_id, $this->get_dummy_content('title'), $this->get_dummy_content('text'), date('Y-m-d H:i:s'), 1, 'Portal Administrator', 0, 0, $topic_id, 0, 1); |
|
219 | - $this->course->add_resource($post); |
|
220 | - } |
|
221 | - // create topics |
|
222 | - for ($topic_id = 1; $topic_id <= $number_of_topics; $topic_id ++) |
|
223 | - { |
|
224 | - $forum_id = rand(1, $number_of_forums); |
|
225 | - $last_forum_post[$forum_id] = $last_topic_post[$topic_id]; |
|
226 | - $topic = new ForumTopic($topic_id, $this->get_dummy_content('title'), '2011-03-31 12:10:00', 'Chamilo', 'Administrator', 0, $forum_id, $last_topic_post[$topic_id]); |
|
227 | - $this->course->add_resource($topic); |
|
228 | - } |
|
229 | - // create forums |
|
230 | - for ($forum_id = 1; $forum_id <= $number_of_forums; $forum_id ++) |
|
231 | - { |
|
232 | - $forum = new Forum($forum_id, $this->get_dummy_content('title'),$this->get_dummy_content('description'), rand(1, $number_of_categories), $last_forum_post[$forum_id]); |
|
233 | - $this->course->add_resource($forum); |
|
234 | - } |
|
235 | - } |
|
236 | - /** |
|
237 | - * Create dummy learnpaths |
|
238 | - */ |
|
239 | - function create_dummy_learnpaths() |
|
240 | - { |
|
241 | - $number_of_learnpaths = rand(3,5); |
|
242 | - $global_item_id = 1; |
|
243 | - for($i=1; $i<=$number_of_learnpaths;$i++) |
|
244 | - { |
|
245 | - $chapters = array(); |
|
246 | - $number_of_chapters = rand(1,6); |
|
247 | - for($chapter_id = 1; $chapter_id <= $number_of_chapters; $chapter_id++) |
|
248 | - { |
|
249 | - $chapter['name'] = $this->get_dummy_content('title'); |
|
250 | - $chapter['description'] = $this->get_dummy_content('description'); |
|
251 | - $chapter['display_order'] = $chapter_id; |
|
252 | - $chapter['items'] = array(); |
|
253 | - $number_of_items = rand(5,20); |
|
254 | - for( $item_id = 1; $item_id<$number_of_items; $item_id++) |
|
255 | - { |
|
256 | - $types = array(RESOURCE_ANNOUNCEMENT, RESOURCE_EVENT, RESOURCE_DOCUMENT,RESOURCE_LINK,RESOURCE_FORUM,RESOURCE_FORUMPOST,RESOURCE_FORUMTOPIC); |
|
257 | - $type = $types[rand(0,count($types)-1)]; |
|
258 | - $resources = $this->course->resources[$type]; |
|
259 | - $resource = $resources[rand(0,count($resources)-1)]; |
|
260 | - $item = array(); |
|
261 | - $item['type'] = $resource->type; |
|
262 | - $item['id'] = $resource->source_id; |
|
263 | - $item['display_order'] = $item_id; |
|
264 | - $item['title'] = $this->get_dummy_content('title'); |
|
265 | - $item['description'] = $this->get_dummy_content('description'); |
|
266 | - $item['ref_id'] = $global_item_id; |
|
267 | - if( rand(0,5) == 1 && $item_id > 1) |
|
268 | - { |
|
269 | - $item['prereq_type'] = 'i'; |
|
270 | - $item['prereq'] = rand($global_item_id - $item_id,$global_item_id-1); |
|
271 | - } |
|
272 | - $chapter['items'][] = $item; |
|
273 | - $global_item_id++; |
|
274 | - } |
|
275 | - $chapters[] = $chapter; |
|
276 | - } |
|
277 | - $lp = new CourseCopyLearnpath($i,$this->get_dummy_content('title'),$this->get_dummy_content('description'),1,$chapters); |
|
278 | - $this->course->add_resource($lp); |
|
279 | - } |
|
280 | - } |
|
281 | - /** |
|
282 | - * Get dummy titles, descriptions and texts |
|
283 | - */ |
|
284 | - function get_dummy_content($type) |
|
285 | - { |
|
286 | - $dummy_text = 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Quisque lectus. Duis sodales. Vivamus et nunc. Phasellus interdum est a lorem. Fusce venenatis luctus lectus. Mauris quis turpis ac erat rhoncus suscipit. Phasellus elit dui, semper at, porta ut, egestas ac, enim. Quisque pellentesque, nisl nec consequat mollis, ipsum justo pellentesque nibh, non faucibus odio ante at lorem. Donec vitae pede ut felis ultricies semper. Suspendisse velit nibh, interdum quis, gravida nec, dapibus ac, leo. Cras id sem ut tellus tincidunt scelerisque. Aenean ac magna feugiat dolor accumsan dignissim. Integer eget nisl. |
|
47 | + $course = api_get_course_info($course_code); |
|
48 | + $this->course = new Course(); |
|
49 | + $tmp_path = api_get_path(SYS_COURSE_PATH).$course['directory'].'/document/tmp_'.uniqid(''); |
|
50 | + @mkdir($tmp_path, api_get_permissions_for_new_directories(), true); |
|
51 | + $this->course->backup_path = $tmp_path; |
|
52 | + $this->create_dummy_links(); |
|
53 | + $this->create_dummy_events(); |
|
54 | + $this->create_dummy_forums(); |
|
55 | + $this->create_dummy_announcements(); |
|
56 | + $this->create_dummy_documents(); |
|
57 | + $this->create_dummy_learnpaths(); |
|
58 | + $cr = new CourseRestorer($this->course); |
|
59 | + $cr->set_file_option(FILE_OVERWRITE); |
|
60 | + $cr->restore($course_code); |
|
61 | + rmdirr($tmp_path); |
|
62 | + } |
|
63 | + /** |
|
64 | + * Create dummy documents |
|
65 | + */ |
|
66 | + function create_dummy_documents() |
|
67 | + { |
|
68 | + $course = api_get_course_info(); |
|
69 | + $course_doc_path = $this->course->backup_path.'/document/'; |
|
70 | + $number_of_documents = rand(10, 30); |
|
71 | + $extensions = array ('html', 'doc'); |
|
72 | + $directories = array(); |
|
73 | + $property = $this->default_property; |
|
74 | + $property['lastedit_type'] = 'DocumentAdded'; |
|
75 | + $property['tool'] = TOOL_DOCUMENT; |
|
76 | + $doc_id = 0; |
|
77 | + for ($doc_id = 1; $doc_id < $number_of_documents; $doc_id ++) |
|
78 | + { |
|
79 | + $path = ''; |
|
80 | + $doc_type = rand(0, count($extensions) - 1); |
|
81 | + $extension = $extensions[$doc_type]; |
|
82 | + $filename = $this->get_dummy_content('title').'_'.$doc_id.'.'.$extension; |
|
83 | + $content = $this->get_dummy_content('text'); |
|
84 | + $dirs = rand(0, 3); |
|
85 | + for ($i = 0; $i < $dirs; $i ++) |
|
86 | + { |
|
87 | + $path .= 'directory/'; |
|
88 | + $directories[$path] = 1; |
|
89 | + } |
|
90 | + $dir_to_make = $course_doc_path.$path; |
|
91 | + if (!is_dir($dir_to_make)) |
|
92 | + { |
|
93 | + @mkdir($dir_to_make, api_get_permissions_for_new_directories(), true); |
|
94 | + } |
|
95 | + $file = $course_doc_path.$path.$filename; |
|
96 | + $fp = fopen($file, 'w'); |
|
97 | + fwrite($fp, $content); |
|
98 | + fclose($fp); |
|
99 | + $size = filesize($file); |
|
100 | + $document = new Document($doc_id, '/'.$path.$filename,$this->get_dummy_content('description'),$this->get_dummy_content('title'), 'file', $size); |
|
101 | + $document->item_properties[] = $property; |
|
102 | + $this->course->add_resource($document); |
|
103 | + } |
|
104 | + foreach($directories as $path => $flag) |
|
105 | + { |
|
106 | + $path = substr($path,0,strlen($path)-1); |
|
107 | + $document = new Document($doc_id++,'/'.$path, $this->get_dummy_content('description'),$this->get_dummy_content('title'),'folder',0); |
|
108 | + $property['lastedit_type'] = 'FolderCreated'; |
|
109 | + $document->item_properties[] = $property; |
|
110 | + $this->course->add_resource($document); |
|
111 | + } |
|
112 | + } |
|
113 | + /** |
|
114 | + * Create dummy announcements |
|
115 | + */ |
|
116 | + function create_dummy_announcements() |
|
117 | + { |
|
118 | + $property = $this->default_property; |
|
119 | + $property['lastedit_type'] = 'AnnouncementAdded'; |
|
120 | + $property['tool'] = TOOL_ANNOUNCEMENT; |
|
121 | + $number_of_announcements = rand(10, 30); |
|
122 | + for ($i = 0; $i < $number_of_announcements; $i ++) |
|
123 | + { |
|
124 | + $time = mktime(rand(1, 24), rand(1, 60), 0, rand(1, 12), rand(1, 28), intval(date('Y'))); |
|
125 | + $date = date('Y-m-d', $time); |
|
126 | + $announcement = new Announcement($i,$this->get_dummy_content('title'),$this->get_dummy_content('text'), $date,0); |
|
127 | + $announcement->item_properties[] = $property; |
|
128 | + $this->course->add_resource($announcement); |
|
129 | + } |
|
130 | + } |
|
131 | + /** |
|
132 | + * Create dummy events |
|
133 | + */ |
|
134 | + function create_dummy_events() |
|
135 | + { |
|
136 | + $number_of_events = rand(10, 30); |
|
137 | + $property = $this->default_property; |
|
138 | + $property['lastedit_type'] = 'AgendaAdded'; |
|
139 | + $property['tool'] = TOOL_CALENDAR_EVENT; |
|
140 | + for ($i = 0; $i < $number_of_events; $i ++) |
|
141 | + { |
|
142 | + $hour = rand(1,24); |
|
143 | + $minute = rand(1,60); |
|
144 | + $second = rand(1,60); |
|
145 | + $day = rand(1,28); |
|
146 | + $month = rand(1,12); |
|
147 | + $year = intval(date('Y')); |
|
148 | + $time = mktime($hour,$minute,$second,$month,$day,$year); |
|
149 | + $start_date = date('Y-m-d H:m:s', $time); |
|
150 | + $hour = rand($hour,24); |
|
151 | + $minute = rand($minute,60); |
|
152 | + $second = rand($second,60); |
|
153 | + $day = rand($day,28); |
|
154 | + $month = rand($month,12); |
|
155 | + $year = intval(date('Y')); |
|
156 | + $time = mktime($hour,$minute,$second,$month,$day,$year); |
|
157 | + $end_date = date('Y-m-d H:m:s', $time); |
|
158 | + $event = new CalendarEvent( |
|
159 | + $i, |
|
160 | + $this->get_dummy_content('title'), |
|
161 | + $this->get_dummy_content('text'), |
|
162 | + $start_date, |
|
163 | + $end_date |
|
164 | + ); |
|
165 | + $event->item_properties[] = $property; |
|
166 | + $this->course->add_resource($event); |
|
167 | + } |
|
168 | + } |
|
169 | + /** |
|
170 | + * Create dummy links |
|
171 | + */ |
|
172 | + function create_dummy_links() |
|
173 | + { |
|
174 | + // create categorys |
|
175 | + $number_of_categories = rand(5, 10); |
|
176 | + for ($i = 0; $i < $number_of_categories; $i ++) |
|
177 | + { |
|
178 | + $linkcat = new LinkCategory($i, $this->get_dummy_content('title'), $this->get_dummy_content('description'),$i); |
|
179 | + $this->course->add_resource($linkcat); |
|
180 | + } |
|
181 | + // create links |
|
182 | + $number_of_links = rand(5, 50); |
|
183 | + $on_homepage = rand(0,20) == 0 ? 1 : 0; |
|
184 | + $property = $this->default_property; |
|
185 | + $property['lastedit_type'] = 'LinkAdded'; |
|
186 | + $property['tool'] = TOOL_LINK; |
|
187 | + for ($i = 0; $i < $number_of_links; $i ++) |
|
188 | + { |
|
189 | + $link = new Link($i, $this->get_dummy_content('title'), 'http://www.google.com/search?q='.$this->get_dummy_content('title'), $this->get_dummy_content('description'), rand(0, $number_of_categories -1),$on_homepage); |
|
190 | + $link->item_properties[] = $property; |
|
191 | + $this->course->add_resource($link); |
|
192 | + } |
|
193 | + } |
|
194 | + /** |
|
195 | + * Create dummy forums |
|
196 | + */ |
|
197 | + function create_dummy_forums() |
|
198 | + { |
|
199 | + $number_of_categories = rand(2, 6); |
|
200 | + $number_of_forums = rand(5, 50); |
|
201 | + $number_of_topics = rand(30, 100); |
|
202 | + $number_of_posts = rand(100, 1000); |
|
203 | + $last_forum_post = array (); |
|
204 | + $last_topic_post = array (); |
|
205 | + // create categorys |
|
206 | + $order = 1; |
|
207 | + for ($i = 1; $i <= $number_of_categories; $i ++) |
|
208 | + { |
|
209 | + $forumcat = new ForumCategory($i, $this->get_dummy_content('title'), $this->get_dummy_content('description'), $order, 0, 0); |
|
210 | + $this->course->add_resource($forumcat); |
|
211 | + $order++; |
|
212 | + } |
|
213 | + // create posts |
|
214 | + for ($post_id = 1; $post_id <= $number_of_posts; $post_id ++) |
|
215 | + { |
|
216 | + $topic_id = rand(1, $number_of_topics); |
|
217 | + $last_topic_post[$topic_id] = $post_id; |
|
218 | + $post = new ForumPost($post_id, $this->get_dummy_content('title'), $this->get_dummy_content('text'), date('Y-m-d H:i:s'), 1, 'Portal Administrator', 0, 0, $topic_id, 0, 1); |
|
219 | + $this->course->add_resource($post); |
|
220 | + } |
|
221 | + // create topics |
|
222 | + for ($topic_id = 1; $topic_id <= $number_of_topics; $topic_id ++) |
|
223 | + { |
|
224 | + $forum_id = rand(1, $number_of_forums); |
|
225 | + $last_forum_post[$forum_id] = $last_topic_post[$topic_id]; |
|
226 | + $topic = new ForumTopic($topic_id, $this->get_dummy_content('title'), '2011-03-31 12:10:00', 'Chamilo', 'Administrator', 0, $forum_id, $last_topic_post[$topic_id]); |
|
227 | + $this->course->add_resource($topic); |
|
228 | + } |
|
229 | + // create forums |
|
230 | + for ($forum_id = 1; $forum_id <= $number_of_forums; $forum_id ++) |
|
231 | + { |
|
232 | + $forum = new Forum($forum_id, $this->get_dummy_content('title'),$this->get_dummy_content('description'), rand(1, $number_of_categories), $last_forum_post[$forum_id]); |
|
233 | + $this->course->add_resource($forum); |
|
234 | + } |
|
235 | + } |
|
236 | + /** |
|
237 | + * Create dummy learnpaths |
|
238 | + */ |
|
239 | + function create_dummy_learnpaths() |
|
240 | + { |
|
241 | + $number_of_learnpaths = rand(3,5); |
|
242 | + $global_item_id = 1; |
|
243 | + for($i=1; $i<=$number_of_learnpaths;$i++) |
|
244 | + { |
|
245 | + $chapters = array(); |
|
246 | + $number_of_chapters = rand(1,6); |
|
247 | + for($chapter_id = 1; $chapter_id <= $number_of_chapters; $chapter_id++) |
|
248 | + { |
|
249 | + $chapter['name'] = $this->get_dummy_content('title'); |
|
250 | + $chapter['description'] = $this->get_dummy_content('description'); |
|
251 | + $chapter['display_order'] = $chapter_id; |
|
252 | + $chapter['items'] = array(); |
|
253 | + $number_of_items = rand(5,20); |
|
254 | + for( $item_id = 1; $item_id<$number_of_items; $item_id++) |
|
255 | + { |
|
256 | + $types = array(RESOURCE_ANNOUNCEMENT, RESOURCE_EVENT, RESOURCE_DOCUMENT,RESOURCE_LINK,RESOURCE_FORUM,RESOURCE_FORUMPOST,RESOURCE_FORUMTOPIC); |
|
257 | + $type = $types[rand(0,count($types)-1)]; |
|
258 | + $resources = $this->course->resources[$type]; |
|
259 | + $resource = $resources[rand(0,count($resources)-1)]; |
|
260 | + $item = array(); |
|
261 | + $item['type'] = $resource->type; |
|
262 | + $item['id'] = $resource->source_id; |
|
263 | + $item['display_order'] = $item_id; |
|
264 | + $item['title'] = $this->get_dummy_content('title'); |
|
265 | + $item['description'] = $this->get_dummy_content('description'); |
|
266 | + $item['ref_id'] = $global_item_id; |
|
267 | + if( rand(0,5) == 1 && $item_id > 1) |
|
268 | + { |
|
269 | + $item['prereq_type'] = 'i'; |
|
270 | + $item['prereq'] = rand($global_item_id - $item_id,$global_item_id-1); |
|
271 | + } |
|
272 | + $chapter['items'][] = $item; |
|
273 | + $global_item_id++; |
|
274 | + } |
|
275 | + $chapters[] = $chapter; |
|
276 | + } |
|
277 | + $lp = new CourseCopyLearnpath($i,$this->get_dummy_content('title'),$this->get_dummy_content('description'),1,$chapters); |
|
278 | + $this->course->add_resource($lp); |
|
279 | + } |
|
280 | + } |
|
281 | + /** |
|
282 | + * Get dummy titles, descriptions and texts |
|
283 | + */ |
|
284 | + function get_dummy_content($type) |
|
285 | + { |
|
286 | + $dummy_text = 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Quisque lectus. Duis sodales. Vivamus et nunc. Phasellus interdum est a lorem. Fusce venenatis luctus lectus. Mauris quis turpis ac erat rhoncus suscipit. Phasellus elit dui, semper at, porta ut, egestas ac, enim. Quisque pellentesque, nisl nec consequat mollis, ipsum justo pellentesque nibh, non faucibus odio ante at lorem. Donec vitae pede ut felis ultricies semper. Suspendisse velit nibh, interdum quis, gravida nec, dapibus ac, leo. Cras id sem ut tellus tincidunt scelerisque. Aenean ac magna feugiat dolor accumsan dignissim. Integer eget nisl. |
|
287 | 287 | Ut sit amet nulla. Vestibulum venenatis posuere mauris. Nullam magna leo, blandit luctus, consequat quis, gravida nec, justo. Nam pede. Etiam ut nisl. In at quam scelerisque sapien faucibus commodo. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos hymenaeos. Proin mattis lorem quis nunc. Praesent placerat ligula id elit. Aenean blandit, purus sit amet pharetra auctor, libero orci rutrum felis, sit amet sodales mauris ipsum ultricies sapien. Vivamus wisi. Cras elit elit, ullamcorper ac, interdum nec, pulvinar nec, lacus. In lacus. Vivamus auctor, arcu vitae tincidunt porta, eros lacus tristique justo, vitae semper risus neque eget massa. Vivamus turpis. |
288 | 288 | Aenean ac wisi non enim aliquam scelerisque. Praesent eget mi. Vestibulum volutpat pulvinar justo. Phasellus sapien ante, pharetra id, bibendum sed, porta non, purus. Maecenas leo velit, luctus quis, porta non, feugiat sit amet, sapien. Proin vitae augue ut massa adipiscing placerat. Morbi ac risus. Proin dapibus eros egestas quam. Fusce fermentum lobortis elit. Duis lectus tellus, convallis nec, lobortis vel, accumsan ut, nunc. Nunc est. Donec ullamcorper laoreet quam. |
289 | 289 | Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos hymenaeos. Suspendisse potenti. Mauris mi. Vivamus risus lacus, faucibus sit amet, sollicitudin a, blandit et, justo. In hendrerit. Sed imperdiet, eros at fringilla tempor, turpis augue semper enim, quis rhoncus nibh enim quis dui. Sed massa sapien, mattis et, laoreet sit amet, dignissim nec, urna. Integer laoreet quam quis lectus. Curabitur convallis gravida dui. Nam metus. Ut sit amet augue in nibh interdum scelerisque. Donec venenatis, lacus et pulvinar euismod, libero massa condimentum pede, commodo tristique nunc massa eu quam. Donec vulputate. Aenean in nibh. Phasellus porttitor. Donec molestie, sem ac porttitor vulputate, mauris dui egestas libero, ac lobortis dolor sem vel ligula. Nam vulputate pretium libero. Cras accumsan. Vivamus lacinia sapien sit amet elit. |
290 | 290 | Duis bibendum elementum justo. Duis posuere. Fusce nulla odio, posuere eget, condimentum nec, venenatis eu, elit. In hac habitasse platea dictumst. Aenean ac sem in enim imperdiet feugiat. Integer tincidunt lectus at elit. Integer magna lacus, vehicula quis, eleifend eget, suscipit vitae, leo. Nunc porta augue nec enim. Curabitur vehicula volutpat enim. Aliquam consequat. Vestibulum rhoncus tellus vitae erat. Integer est. Quisque fermentum leo nec odio. Suspendisse lobortis sollicitudin augue. Nullam urna mi, suscipit eu, sagittis laoreet, ultrices ac, sem. Aliquam enim tortor, hendrerit non, cursus a, tristique sit amet, sapien. Suspendisse potenti. Aenean semper placerat neque.'; |
291 | - switch($type) |
|
292 | - { |
|
293 | - case 'description': |
|
294 | - $descriptions = explode(".",$dummy_text); |
|
295 | - return $descriptions[rand(0,count($descriptions)-1)]; |
|
296 | - break; |
|
297 | - case 'title': |
|
298 | - $dummy_text = str_replace(array("\n",'.',',',"\t"),array(' ','','',' '),$dummy_text); |
|
299 | - $titles = explode(" ",$dummy_text); |
|
300 | - return trim($titles[rand(0,count($titles)-1)]); |
|
301 | - break; |
|
302 | - case 'text': |
|
303 | - $texts = explode("\n",$dummy_text); |
|
304 | - return $texts[rand(0,count($texts)-1)]; |
|
305 | - break; |
|
306 | - } |
|
307 | - } |
|
291 | + switch($type) |
|
292 | + { |
|
293 | + case 'description': |
|
294 | + $descriptions = explode(".",$dummy_text); |
|
295 | + return $descriptions[rand(0,count($descriptions)-1)]; |
|
296 | + break; |
|
297 | + case 'title': |
|
298 | + $dummy_text = str_replace(array("\n",'.',',',"\t"),array(' ','','',' '),$dummy_text); |
|
299 | + $titles = explode(" ",$dummy_text); |
|
300 | + return trim($titles[rand(0,count($titles)-1)]); |
|
301 | + break; |
|
302 | + case 'text': |
|
303 | + $texts = explode("\n",$dummy_text); |
|
304 | + return $texts[rand(0,count($texts)-1)]; |
|
305 | + break; |
|
306 | + } |
|
307 | + } |
|
308 | 308 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | $this->default_property['to_user_id'] = null; |
43 | 43 | $this->default_property['visibility'] = '1'; |
44 | 44 | $this->default_property['start_visible'] = '0000-00-00 00:00:00'; |
45 | - $this->default_property['end_visible'] = '0000-00-00 00:00:00'; |
|
45 | + $this->default_property['end_visible'] = '0000-00-00 00:00:00'; |
|
46 | 46 | |
47 | 47 | $course = api_get_course_info($course_code); |
48 | 48 | $this->course = new Course(); |
@@ -68,13 +68,13 @@ discard block |
||
68 | 68 | $course = api_get_course_info(); |
69 | 69 | $course_doc_path = $this->course->backup_path.'/document/'; |
70 | 70 | $number_of_documents = rand(10, 30); |
71 | - $extensions = array ('html', 'doc'); |
|
71 | + $extensions = array('html', 'doc'); |
|
72 | 72 | $directories = array(); |
73 | 73 | $property = $this->default_property; |
74 | 74 | $property['lastedit_type'] = 'DocumentAdded'; |
75 | 75 | $property['tool'] = TOOL_DOCUMENT; |
76 | 76 | $doc_id = 0; |
77 | - for ($doc_id = 1; $doc_id < $number_of_documents; $doc_id ++) |
|
77 | + for ($doc_id = 1; $doc_id < $number_of_documents; $doc_id++) |
|
78 | 78 | { |
79 | 79 | $path = ''; |
80 | 80 | $doc_type = rand(0, count($extensions) - 1); |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | $filename = $this->get_dummy_content('title').'_'.$doc_id.'.'.$extension; |
83 | 83 | $content = $this->get_dummy_content('text'); |
84 | 84 | $dirs = rand(0, 3); |
85 | - for ($i = 0; $i < $dirs; $i ++) |
|
85 | + for ($i = 0; $i < $dirs; $i++) |
|
86 | 86 | { |
87 | 87 | $path .= 'directory/'; |
88 | 88 | $directories[$path] = 1; |
@@ -97,14 +97,14 @@ discard block |
||
97 | 97 | fwrite($fp, $content); |
98 | 98 | fclose($fp); |
99 | 99 | $size = filesize($file); |
100 | - $document = new Document($doc_id, '/'.$path.$filename,$this->get_dummy_content('description'),$this->get_dummy_content('title'), 'file', $size); |
|
100 | + $document = new Document($doc_id, '/'.$path.$filename, $this->get_dummy_content('description'), $this->get_dummy_content('title'), 'file', $size); |
|
101 | 101 | $document->item_properties[] = $property; |
102 | 102 | $this->course->add_resource($document); |
103 | 103 | } |
104 | - foreach($directories as $path => $flag) |
|
104 | + foreach ($directories as $path => $flag) |
|
105 | 105 | { |
106 | - $path = substr($path,0,strlen($path)-1); |
|
107 | - $document = new Document($doc_id++,'/'.$path, $this->get_dummy_content('description'),$this->get_dummy_content('title'),'folder',0); |
|
106 | + $path = substr($path, 0, strlen($path) - 1); |
|
107 | + $document = new Document($doc_id++, '/'.$path, $this->get_dummy_content('description'), $this->get_dummy_content('title'), 'folder', 0); |
|
108 | 108 | $property['lastedit_type'] = 'FolderCreated'; |
109 | 109 | $document->item_properties[] = $property; |
110 | 110 | $this->course->add_resource($document); |
@@ -119,11 +119,11 @@ discard block |
||
119 | 119 | $property['lastedit_type'] = 'AnnouncementAdded'; |
120 | 120 | $property['tool'] = TOOL_ANNOUNCEMENT; |
121 | 121 | $number_of_announcements = rand(10, 30); |
122 | - for ($i = 0; $i < $number_of_announcements; $i ++) |
|
122 | + for ($i = 0; $i < $number_of_announcements; $i++) |
|
123 | 123 | { |
124 | 124 | $time = mktime(rand(1, 24), rand(1, 60), 0, rand(1, 12), rand(1, 28), intval(date('Y'))); |
125 | 125 | $date = date('Y-m-d', $time); |
126 | - $announcement = new Announcement($i,$this->get_dummy_content('title'),$this->get_dummy_content('text'), $date,0); |
|
126 | + $announcement = new Announcement($i, $this->get_dummy_content('title'), $this->get_dummy_content('text'), $date, 0); |
|
127 | 127 | $announcement->item_properties[] = $property; |
128 | 128 | $this->course->add_resource($announcement); |
129 | 129 | } |
@@ -137,23 +137,23 @@ discard block |
||
137 | 137 | $property = $this->default_property; |
138 | 138 | $property['lastedit_type'] = 'AgendaAdded'; |
139 | 139 | $property['tool'] = TOOL_CALENDAR_EVENT; |
140 | - for ($i = 0; $i < $number_of_events; $i ++) |
|
140 | + for ($i = 0; $i < $number_of_events; $i++) |
|
141 | 141 | { |
142 | - $hour = rand(1,24); |
|
143 | - $minute = rand(1,60); |
|
144 | - $second = rand(1,60); |
|
145 | - $day = rand(1,28); |
|
146 | - $month = rand(1,12); |
|
142 | + $hour = rand(1, 24); |
|
143 | + $minute = rand(1, 60); |
|
144 | + $second = rand(1, 60); |
|
145 | + $day = rand(1, 28); |
|
146 | + $month = rand(1, 12); |
|
147 | 147 | $year = intval(date('Y')); |
148 | - $time = mktime($hour,$minute,$second,$month,$day,$year); |
|
148 | + $time = mktime($hour, $minute, $second, $month, $day, $year); |
|
149 | 149 | $start_date = date('Y-m-d H:m:s', $time); |
150 | - $hour = rand($hour,24); |
|
151 | - $minute = rand($minute,60); |
|
152 | - $second = rand($second,60); |
|
153 | - $day = rand($day,28); |
|
154 | - $month = rand($month,12); |
|
150 | + $hour = rand($hour, 24); |
|
151 | + $minute = rand($minute, 60); |
|
152 | + $second = rand($second, 60); |
|
153 | + $day = rand($day, 28); |
|
154 | + $month = rand($month, 12); |
|
155 | 155 | $year = intval(date('Y')); |
156 | - $time = mktime($hour,$minute,$second,$month,$day,$year); |
|
156 | + $time = mktime($hour, $minute, $second, $month, $day, $year); |
|
157 | 157 | $end_date = date('Y-m-d H:m:s', $time); |
158 | 158 | $event = new CalendarEvent( |
159 | 159 | $i, |
@@ -173,20 +173,20 @@ discard block |
||
173 | 173 | { |
174 | 174 | // create categorys |
175 | 175 | $number_of_categories = rand(5, 10); |
176 | - for ($i = 0; $i < $number_of_categories; $i ++) |
|
176 | + for ($i = 0; $i < $number_of_categories; $i++) |
|
177 | 177 | { |
178 | - $linkcat = new LinkCategory($i, $this->get_dummy_content('title'), $this->get_dummy_content('description'),$i); |
|
178 | + $linkcat = new LinkCategory($i, $this->get_dummy_content('title'), $this->get_dummy_content('description'), $i); |
|
179 | 179 | $this->course->add_resource($linkcat); |
180 | 180 | } |
181 | 181 | // create links |
182 | 182 | $number_of_links = rand(5, 50); |
183 | - $on_homepage = rand(0,20) == 0 ? 1 : 0; |
|
183 | + $on_homepage = rand(0, 20) == 0 ? 1 : 0; |
|
184 | 184 | $property = $this->default_property; |
185 | 185 | $property['lastedit_type'] = 'LinkAdded'; |
186 | 186 | $property['tool'] = TOOL_LINK; |
187 | - for ($i = 0; $i < $number_of_links; $i ++) |
|
187 | + for ($i = 0; $i < $number_of_links; $i++) |
|
188 | 188 | { |
189 | - $link = new Link($i, $this->get_dummy_content('title'), 'http://www.google.com/search?q='.$this->get_dummy_content('title'), $this->get_dummy_content('description'), rand(0, $number_of_categories -1),$on_homepage); |
|
189 | + $link = new Link($i, $this->get_dummy_content('title'), 'http://www.google.com/search?q='.$this->get_dummy_content('title'), $this->get_dummy_content('description'), rand(0, $number_of_categories - 1), $on_homepage); |
|
190 | 190 | $link->item_properties[] = $property; |
191 | 191 | $this->course->add_resource($link); |
192 | 192 | } |
@@ -200,18 +200,18 @@ discard block |
||
200 | 200 | $number_of_forums = rand(5, 50); |
201 | 201 | $number_of_topics = rand(30, 100); |
202 | 202 | $number_of_posts = rand(100, 1000); |
203 | - $last_forum_post = array (); |
|
204 | - $last_topic_post = array (); |
|
203 | + $last_forum_post = array(); |
|
204 | + $last_topic_post = array(); |
|
205 | 205 | // create categorys |
206 | 206 | $order = 1; |
207 | - for ($i = 1; $i <= $number_of_categories; $i ++) |
|
207 | + for ($i = 1; $i <= $number_of_categories; $i++) |
|
208 | 208 | { |
209 | 209 | $forumcat = new ForumCategory($i, $this->get_dummy_content('title'), $this->get_dummy_content('description'), $order, 0, 0); |
210 | 210 | $this->course->add_resource($forumcat); |
211 | 211 | $order++; |
212 | 212 | } |
213 | 213 | // create posts |
214 | - for ($post_id = 1; $post_id <= $number_of_posts; $post_id ++) |
|
214 | + for ($post_id = 1; $post_id <= $number_of_posts; $post_id++) |
|
215 | 215 | { |
216 | 216 | $topic_id = rand(1, $number_of_topics); |
217 | 217 | $last_topic_post[$topic_id] = $post_id; |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | $this->course->add_resource($post); |
220 | 220 | } |
221 | 221 | // create topics |
222 | - for ($topic_id = 1; $topic_id <= $number_of_topics; $topic_id ++) |
|
222 | + for ($topic_id = 1; $topic_id <= $number_of_topics; $topic_id++) |
|
223 | 223 | { |
224 | 224 | $forum_id = rand(1, $number_of_forums); |
225 | 225 | $last_forum_post[$forum_id] = $last_topic_post[$topic_id]; |
@@ -227,9 +227,9 @@ discard block |
||
227 | 227 | $this->course->add_resource($topic); |
228 | 228 | } |
229 | 229 | // create forums |
230 | - for ($forum_id = 1; $forum_id <= $number_of_forums; $forum_id ++) |
|
230 | + for ($forum_id = 1; $forum_id <= $number_of_forums; $forum_id++) |
|
231 | 231 | { |
232 | - $forum = new Forum($forum_id, $this->get_dummy_content('title'),$this->get_dummy_content('description'), rand(1, $number_of_categories), $last_forum_post[$forum_id]); |
|
232 | + $forum = new Forum($forum_id, $this->get_dummy_content('title'), $this->get_dummy_content('description'), rand(1, $number_of_categories), $last_forum_post[$forum_id]); |
|
233 | 233 | $this->course->add_resource($forum); |
234 | 234 | } |
235 | 235 | } |
@@ -238,25 +238,25 @@ discard block |
||
238 | 238 | */ |
239 | 239 | function create_dummy_learnpaths() |
240 | 240 | { |
241 | - $number_of_learnpaths = rand(3,5); |
|
241 | + $number_of_learnpaths = rand(3, 5); |
|
242 | 242 | $global_item_id = 1; |
243 | - for($i=1; $i<=$number_of_learnpaths;$i++) |
|
243 | + for ($i = 1; $i <= $number_of_learnpaths; $i++) |
|
244 | 244 | { |
245 | 245 | $chapters = array(); |
246 | - $number_of_chapters = rand(1,6); |
|
247 | - for($chapter_id = 1; $chapter_id <= $number_of_chapters; $chapter_id++) |
|
246 | + $number_of_chapters = rand(1, 6); |
|
247 | + for ($chapter_id = 1; $chapter_id <= $number_of_chapters; $chapter_id++) |
|
248 | 248 | { |
249 | 249 | $chapter['name'] = $this->get_dummy_content('title'); |
250 | 250 | $chapter['description'] = $this->get_dummy_content('description'); |
251 | 251 | $chapter['display_order'] = $chapter_id; |
252 | 252 | $chapter['items'] = array(); |
253 | - $number_of_items = rand(5,20); |
|
254 | - for( $item_id = 1; $item_id<$number_of_items; $item_id++) |
|
253 | + $number_of_items = rand(5, 20); |
|
254 | + for ($item_id = 1; $item_id < $number_of_items; $item_id++) |
|
255 | 255 | { |
256 | - $types = array(RESOURCE_ANNOUNCEMENT, RESOURCE_EVENT, RESOURCE_DOCUMENT,RESOURCE_LINK,RESOURCE_FORUM,RESOURCE_FORUMPOST,RESOURCE_FORUMTOPIC); |
|
257 | - $type = $types[rand(0,count($types)-1)]; |
|
256 | + $types = array(RESOURCE_ANNOUNCEMENT, RESOURCE_EVENT, RESOURCE_DOCUMENT, RESOURCE_LINK, RESOURCE_FORUM, RESOURCE_FORUMPOST, RESOURCE_FORUMTOPIC); |
|
257 | + $type = $types[rand(0, count($types) - 1)]; |
|
258 | 258 | $resources = $this->course->resources[$type]; |
259 | - $resource = $resources[rand(0,count($resources)-1)]; |
|
259 | + $resource = $resources[rand(0, count($resources) - 1)]; |
|
260 | 260 | $item = array(); |
261 | 261 | $item['type'] = $resource->type; |
262 | 262 | $item['id'] = $resource->source_id; |
@@ -264,17 +264,17 @@ discard block |
||
264 | 264 | $item['title'] = $this->get_dummy_content('title'); |
265 | 265 | $item['description'] = $this->get_dummy_content('description'); |
266 | 266 | $item['ref_id'] = $global_item_id; |
267 | - if( rand(0,5) == 1 && $item_id > 1) |
|
267 | + if (rand(0, 5) == 1 && $item_id > 1) |
|
268 | 268 | { |
269 | 269 | $item['prereq_type'] = 'i'; |
270 | - $item['prereq'] = rand($global_item_id - $item_id,$global_item_id-1); |
|
270 | + $item['prereq'] = rand($global_item_id - $item_id, $global_item_id - 1); |
|
271 | 271 | } |
272 | 272 | $chapter['items'][] = $item; |
273 | 273 | $global_item_id++; |
274 | 274 | } |
275 | 275 | $chapters[] = $chapter; |
276 | 276 | } |
277 | - $lp = new CourseCopyLearnpath($i,$this->get_dummy_content('title'),$this->get_dummy_content('description'),1,$chapters); |
|
277 | + $lp = new CourseCopyLearnpath($i, $this->get_dummy_content('title'), $this->get_dummy_content('description'), 1, $chapters); |
|
278 | 278 | $this->course->add_resource($lp); |
279 | 279 | } |
280 | 280 | } |
@@ -288,20 +288,20 @@ discard block |
||
288 | 288 | Aenean ac wisi non enim aliquam scelerisque. Praesent eget mi. Vestibulum volutpat pulvinar justo. Phasellus sapien ante, pharetra id, bibendum sed, porta non, purus. Maecenas leo velit, luctus quis, porta non, feugiat sit amet, sapien. Proin vitae augue ut massa adipiscing placerat. Morbi ac risus. Proin dapibus eros egestas quam. Fusce fermentum lobortis elit. Duis lectus tellus, convallis nec, lobortis vel, accumsan ut, nunc. Nunc est. Donec ullamcorper laoreet quam. |
289 | 289 | Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos hymenaeos. Suspendisse potenti. Mauris mi. Vivamus risus lacus, faucibus sit amet, sollicitudin a, blandit et, justo. In hendrerit. Sed imperdiet, eros at fringilla tempor, turpis augue semper enim, quis rhoncus nibh enim quis dui. Sed massa sapien, mattis et, laoreet sit amet, dignissim nec, urna. Integer laoreet quam quis lectus. Curabitur convallis gravida dui. Nam metus. Ut sit amet augue in nibh interdum scelerisque. Donec venenatis, lacus et pulvinar euismod, libero massa condimentum pede, commodo tristique nunc massa eu quam. Donec vulputate. Aenean in nibh. Phasellus porttitor. Donec molestie, sem ac porttitor vulputate, mauris dui egestas libero, ac lobortis dolor sem vel ligula. Nam vulputate pretium libero. Cras accumsan. Vivamus lacinia sapien sit amet elit. |
290 | 290 | Duis bibendum elementum justo. Duis posuere. Fusce nulla odio, posuere eget, condimentum nec, venenatis eu, elit. In hac habitasse platea dictumst. Aenean ac sem in enim imperdiet feugiat. Integer tincidunt lectus at elit. Integer magna lacus, vehicula quis, eleifend eget, suscipit vitae, leo. Nunc porta augue nec enim. Curabitur vehicula volutpat enim. Aliquam consequat. Vestibulum rhoncus tellus vitae erat. Integer est. Quisque fermentum leo nec odio. Suspendisse lobortis sollicitudin augue. Nullam urna mi, suscipit eu, sagittis laoreet, ultrices ac, sem. Aliquam enim tortor, hendrerit non, cursus a, tristique sit amet, sapien. Suspendisse potenti. Aenean semper placerat neque.'; |
291 | - switch($type) |
|
291 | + switch ($type) |
|
292 | 292 | { |
293 | 293 | case 'description': |
294 | - $descriptions = explode(".",$dummy_text); |
|
295 | - return $descriptions[rand(0,count($descriptions)-1)]; |
|
294 | + $descriptions = explode(".", $dummy_text); |
|
295 | + return $descriptions[rand(0, count($descriptions) - 1)]; |
|
296 | 296 | break; |
297 | 297 | case 'title': |
298 | - $dummy_text = str_replace(array("\n",'.',',',"\t"),array(' ','','',' '),$dummy_text); |
|
299 | - $titles = explode(" ",$dummy_text); |
|
300 | - return trim($titles[rand(0,count($titles)-1)]); |
|
298 | + $dummy_text = str_replace(array("\n", '.', ',', "\t"), array(' ', '', '', ' '), $dummy_text); |
|
299 | + $titles = explode(" ", $dummy_text); |
|
300 | + return trim($titles[rand(0, count($titles) - 1)]); |
|
301 | 301 | break; |
302 | 302 | case 'text': |
303 | - $texts = explode("\n",$dummy_text); |
|
304 | - return $texts[rand(0,count($texts)-1)]; |
|
303 | + $texts = explode("\n", $dummy_text); |
|
304 | + return $texts[rand(0, count($texts) - 1)]; |
|
305 | 305 | break; |
306 | 306 | } |
307 | 307 | } |
@@ -50,9 +50,6 @@ |
||
50 | 50 | * @param int $id |
51 | 51 | * @param string $title |
52 | 52 | * @param string $content |
53 | - * @param string $date |
|
54 | - * @param string $hour |
|
55 | - * @param int $duration |
|
56 | 53 | */ |
57 | 54 | public function __construct( |
58 | 55 | $id, |
@@ -66,19 +66,19 @@ |
||
66 | 66 | $attachment_comment = null, |
67 | 67 | $all_day = 0 |
68 | 68 | ) { |
69 | - parent::__construct($id, RESOURCE_EVENT); |
|
69 | + parent::__construct($id, RESOURCE_EVENT); |
|
70 | 70 | |
71 | - $this->title = $title; |
|
72 | - $this->content = $content; |
|
73 | - $this->start_date = $start_date; |
|
74 | - $this->end_date = $end_date; |
|
75 | - $this->all_day = $all_day; |
|
71 | + $this->title = $title; |
|
72 | + $this->content = $content; |
|
73 | + $this->start_date = $start_date; |
|
74 | + $this->end_date = $end_date; |
|
75 | + $this->all_day = $all_day; |
|
76 | 76 | |
77 | - $this->attachment_path = $attachment_path; |
|
78 | - $this->attachment_filename = $attachment_filename; |
|
79 | - $this->attachment_size = $attachment_size; |
|
80 | - $this->attachment_comment = $attachment_comment; |
|
81 | - } |
|
77 | + $this->attachment_path = $attachment_path; |
|
78 | + $this->attachment_filename = $attachment_filename; |
|
79 | + $this->attachment_size = $attachment_size; |
|
80 | + $this->attachment_comment = $attachment_comment; |
|
81 | + } |
|
82 | 82 | |
83 | 83 | /** |
84 | 84 | * Show this Event |
@@ -115,6 +115,9 @@ |
||
115 | 115 | $this->answers[] = $answer; |
116 | 116 | } |
117 | 117 | |
118 | + /** |
|
119 | + * @param QuizQuestionOption $option_obj |
|
120 | + */ |
|
118 | 121 | public function add_option($option_obj) |
119 | 122 | { |
120 | 123 | $this->question_options[$option_obj->obj->id] = $option_obj; |
@@ -128,7 +128,7 @@ |
||
128 | 128 | |
129 | 129 | /** |
130 | 130 | * Resturns the type of this resource |
131 | - * @return constant The type. |
|
131 | + * @return integer The type. |
|
132 | 132 | */ |
133 | 133 | public function get_type() |
134 | 134 | { |
@@ -65,6 +65,9 @@ |
||
65 | 65 | |
66 | 66 | /* FUNCTIONS */ |
67 | 67 | |
68 | +/** |
|
69 | + * @param string $name |
|
70 | + */ |
|
68 | 71 | function make_select_session_list($name, $sessions, $attr = array()) |
69 | 72 | { |
70 | 73 |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | $nameTools = get_lang('CopyCourse'); |
49 | 49 | $returnLink = api_get_path( |
50 | 50 | WEB_CODE_PATH |
51 | - ) . 'course_info/maintenance_coach.php?' . api_get_cidreq(); |
|
51 | + ).'course_info/maintenance_coach.php?'.api_get_cidreq(); |
|
52 | 52 | $interbreadcrumb[] = array( |
53 | 53 | 'url' => $returnLink, |
54 | 54 | 'name' => get_lang('Maintenance') |
@@ -71,29 +71,29 @@ discard block |
||
71 | 71 | $attrs = ''; |
72 | 72 | if (count($attr) > 0) { |
73 | 73 | foreach ($attr as $key => $value) { |
74 | - $attrs .= ' ' . $key . '="' . $value . '"'; |
|
74 | + $attrs .= ' '.$key.'="'.$value.'"'; |
|
75 | 75 | } |
76 | 76 | } |
77 | - $output = '<select name="' . $name . '" ' . $attrs . '>'; |
|
77 | + $output = '<select name="'.$name.'" '.$attrs.'>'; |
|
78 | 78 | |
79 | 79 | if (count($sessions) == 0) { |
80 | - $output .= '<option value = "0">' . get_lang( |
|
80 | + $output .= '<option value = "0">'.get_lang( |
|
81 | 81 | 'ThereIsNotStillASession' |
82 | - ) . '</option>'; |
|
82 | + ).'</option>'; |
|
83 | 83 | } else { |
84 | - $output .= '<option value = "0">' . get_lang( |
|
84 | + $output .= '<option value = "0">'.get_lang( |
|
85 | 85 | 'SelectASession' |
86 | - ) . '</option>'; |
|
86 | + ).'</option>'; |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | if (is_array($sessions)) { |
90 | 90 | foreach ($sessions as $session) { |
91 | 91 | $category_name = ''; |
92 | 92 | if (!empty($session['category_name'])) { |
93 | - $category_name = ' (' . $session['category_name'] . ')'; |
|
93 | + $category_name = ' ('.$session['category_name'].')'; |
|
94 | 94 | } |
95 | 95 | |
96 | - $output .= '<option value="' . $session['id'] . '">' . $session['name'] . ' ' . $category_name . '</option>'; |
|
96 | + $output .= '<option value="'.$session['id'].'">'.$session['name'].' '.$category_name.'</option>'; |
|
97 | 97 | } |
98 | 98 | } |
99 | 99 | $output .= '</select>'; |
@@ -118,43 +118,43 @@ discard block |
||
118 | 118 | // Actions |
119 | 119 | $html .= '<div class="actions">'; |
120 | 120 | // Link back to the documents overview |
121 | - $html .= '<a href="' . $returnLink . '">' . Display::return_icon( |
|
122 | - 'back.png', get_lang('BackTo') . ' ' . get_lang('Maintenance'), '', ICON_SIZE_MEDIUM |
|
123 | - ) . '</a>'; |
|
121 | + $html .= '<a href="'.$returnLink.'">'.Display::return_icon( |
|
122 | + 'back.png', get_lang('BackTo').' '.get_lang('Maintenance'), '', ICON_SIZE_MEDIUM |
|
123 | + ).'</a>'; |
|
124 | 124 | $html .= '</div>'; |
125 | 125 | |
126 | 126 | $html .= Display::return_message( |
127 | 127 | get_lang('CopyCourseFromSessionToSessionExplanation') |
128 | 128 | ); |
129 | 129 | |
130 | - $html .= '<form name="formulaire" method="post" action="' . api_get_self( |
|
131 | - ) . '?' . api_get_cidreq() . '" >'; |
|
130 | + $html .= '<form name="formulaire" method="post" action="'.api_get_self( |
|
131 | + ).'?'.api_get_cidreq().'" >'; |
|
132 | 132 | $html .= '<table border="0" cellpadding="5" cellspacing="0" width="100%">'; |
133 | 133 | |
134 | 134 | // Source |
135 | - $html .= '<tr><td width="15%"><b>' . get_lang( |
|
135 | + $html .= '<tr><td width="15%"><b>'.get_lang( |
|
136 | 136 | 'OriginCoursesFromSession' |
137 | - ) . ':</b></td>'; |
|
138 | - $html .= '<td width="10%" align="left">' . api_get_session_name( |
|
137 | + ).':</b></td>'; |
|
138 | + $html .= '<td width="10%" align="left">'.api_get_session_name( |
|
139 | 139 | $sessionId |
140 | - ) . '</td>'; |
|
140 | + ).'</td>'; |
|
141 | 141 | $html .= '<td width="50%">'; |
142 | - $html .= "{$courseInfo['title']} ({$courseInfo['code']})" . '</td></tr>'; |
|
142 | + $html .= "{$courseInfo['title']} ({$courseInfo['code']})".'</td></tr>'; |
|
143 | 143 | |
144 | 144 | // Destination |
145 | - $html .= '<tr><td width="15%"><b>' . get_lang( |
|
145 | + $html .= '<tr><td width="15%"><b>'.get_lang( |
|
146 | 146 | 'DestinationCoursesFromSession' |
147 | - ) . ':</b></td>'; |
|
147 | + ).':</b></td>'; |
|
148 | 148 | $html .= '<td width="10%" align="left"><div id="ajax_sessions_list_destination">'; |
149 | 149 | $html .= '<select name="sessions_list_destination" onchange="javascript: xajax_searchCourses(this.value,\'destination\');">'; |
150 | 150 | if (empty($sessions)) { |
151 | - $html .= '<option value = "0">' . get_lang( |
|
151 | + $html .= '<option value = "0">'.get_lang( |
|
152 | 152 | 'ThereIsNotStillASession' |
153 | - ) . '</option>'; |
|
153 | + ).'</option>'; |
|
154 | 154 | } else { |
155 | - $html .= '<option value = "0">' . get_lang( |
|
155 | + $html .= '<option value = "0">'.get_lang( |
|
156 | 156 | 'SelectASession' |
157 | - ) . '</option>'; |
|
157 | + ).'</option>'; |
|
158 | 158 | foreach ($sessions as $session) { |
159 | 159 | if ($session['id'] == $sessionId) { |
160 | 160 | continue; |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | continue; |
165 | 165 | } |
166 | 166 | |
167 | - $html .= '<option value="' . $session['id'] . '">' . $session['name'] . '</option>'; |
|
167 | + $html .= '<option value="'.$session['id'].'">'.$session['name'].'</option>'; |
|
168 | 168 | } |
169 | 169 | } |
170 | 170 | |
@@ -176,17 +176,17 @@ discard block |
||
176 | 176 | $html .= '</tr></table>'; |
177 | 177 | |
178 | 178 | $html .= "<fieldset>"; |
179 | - $html .= '<legend>' . get_lang('TypeOfCopy') . ' <small>(' . get_lang('CopyOnlySessionItems') . ')</small></legend>'; |
|
179 | + $html .= '<legend>'.get_lang('TypeOfCopy').' <small>('.get_lang('CopyOnlySessionItems').')</small></legend>'; |
|
180 | 180 | $html .= '<label class="radio"><input type="radio" id="copy_option_1" name="copy_option" value="full_copy" checked="checked"/>'; |
181 | - $html .= get_lang('FullCopy') . '</label>'; |
|
181 | + $html .= get_lang('FullCopy').'</label>'; |
|
182 | 182 | $html .= '<label class="radio"><input type="radio" id="copy_option_2" name="copy_option" value="select_items"/>'; |
183 | - $html .= ' ' . get_lang('LetMeSelectItems') . '</label><br/>'; |
|
183 | + $html .= ' '.get_lang('LetMeSelectItems').'</label><br/>'; |
|
184 | 184 | |
185 | 185 | $html .= "</fieldset>"; |
186 | 186 | |
187 | - $html .= '<button class="save" type="submit" onclick="javascript:if(!confirm(' . "'" . addslashes( |
|
187 | + $html .= '<button class="save" type="submit" onclick="javascript:if(!confirm('."'".addslashes( |
|
188 | 188 | api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES) |
189 | - ) . "'" . ')) return false;">' . get_lang('CopyCourse') . '</button>'; |
|
189 | + )."'".')) return false;">'.get_lang('CopyCourse').'</button>'; |
|
190 | 190 | $html .= '</form>'; |
191 | 191 | echo $html; |
192 | 192 | } |
@@ -212,10 +212,10 @@ discard block |
||
212 | 212 | |
213 | 213 | $courseTitle = str_replace("'", "\'", $course['title']); |
214 | 214 | |
215 | - $return .= '<option value="' . $course['code'] . '" title="' . @htmlspecialchars( |
|
216 | - $course['title'] . ' (' . $course['visual_code'] . ')', ENT_QUOTES, api_get_system_encoding() |
|
217 | - ) . '">' . |
|
218 | - $course['title'] . ' (' . $course['visual_code'] . ')</option>'; |
|
215 | + $return .= '<option value="'.$course['code'].'" title="'.@htmlspecialchars( |
|
216 | + $course['title'].' ('.$course['visual_code'].')', ENT_QUOTES, api_get_system_encoding() |
|
217 | + ).'">'. |
|
218 | + $course['title'].' ('.$course['visual_code'].')</option>'; |
|
219 | 219 | } |
220 | 220 | $return .= '</select>'; |
221 | 221 | $_SESSION['course_list_destination'] = $course_list_destination; |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | /* HTML head extra */ |
234 | 234 | |
235 | 235 | $htmlHeadXtra[] = $xajax->getJavascript( |
236 | - api_get_path(WEB_LIBRARY_PATH) . 'xajax/' |
|
236 | + api_get_path(WEB_LIBRARY_PATH).'xajax/' |
|
237 | 237 | ); |
238 | 238 | $htmlHeadXtra[] = '<script> |
239 | 239 | function checkSelected(id_select,id_radio,id_title,id_destination) { |
@@ -378,13 +378,13 @@ discard block |
||
378 | 378 | |
379 | 379 | CourseSelectForm :: display_form($course, $hiddenFields, true); |
380 | 380 | |
381 | - echo '<div style="float:right"><a href="javascript:window.history.go(-1);">' . |
|
381 | + echo '<div style="float:right"><a href="javascript:window.history.go(-1);">'. |
|
382 | 382 | Display::return_icon( |
383 | - 'back.png', get_lang('Back') . ' ' . get_lang('To') . ' ' . get_lang( |
|
383 | + 'back.png', get_lang('Back').' '.get_lang('To').' '.get_lang( |
|
384 | 384 | 'PlatformAdmin' |
385 | 385 | ), array('style' => 'vertical-align:middle') |
386 | - ) . |
|
387 | - get_lang('Back') . '</a></div>'; |
|
386 | + ). |
|
387 | + get_lang('Back').'</a></div>'; |
|
388 | 388 | } else { |
389 | 389 | Display::display_error_message( |
390 | 390 | get_lang('You must select a course from original session and select a destination session') |
@@ -50,6 +50,7 @@ discard block |
||
50 | 50 | /** |
51 | 51 | * Returns a quarter from a month |
52 | 52 | * @param string The month (digit), with or without leading 0 |
53 | + * @param string $month |
|
53 | 54 | * @return int The yearly quarter (1, 2, 3 or 4) in which this month lies |
54 | 55 | */ |
55 | 56 | function getQuarter($month) |
@@ -96,6 +97,7 @@ discard block |
||
96 | 97 | /** |
97 | 98 | * Returns the first month of the quarter |
98 | 99 | * @param int Quarter |
100 | + * @param integer $quarter |
|
99 | 101 | * @return string Number of the month, with leading 0 |
100 | 102 | */ |
101 | 103 | function getQuarterFirstMonth($quarter) |
@@ -116,6 +118,7 @@ discard block |
||
116 | 118 | /** |
117 | 119 | * Get the quarter in Roman letters |
118 | 120 | * @param int Quarter |
121 | + * @param integer $quarter |
|
119 | 122 | * @return string Roman letters |
120 | 123 | */ |
121 | 124 | function getQuarterRoman($quarter) |
@@ -1,11 +1,11 @@ |
||
1 | 1 | <?php |
2 | 2 | /* For licensing terms, see /license.txt */ |
3 | 3 | /** |
4 | - * Create course sessions procedure. It creates sessions for courses that haven't it yet. |
|
5 | - * If today is greater than OFFSET, it will create them also for the next quarter |
|
6 | - * @package chamilo.cron |
|
7 | - * @author Imanol Losada <[email protected]> |
|
8 | - */ |
|
4 | + * Create course sessions procedure. It creates sessions for courses that haven't it yet. |
|
5 | + * If today is greater than OFFSET, it will create them also for the next quarter |
|
6 | + * @package chamilo.cron |
|
7 | + * @author Imanol Losada <[email protected]> |
|
8 | + */ |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * Initialization |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | exit; //do not run from browser |
15 | 15 | } |
16 | 16 | |
17 | -require_once __DIR__ . "/../inc/global.inc.php"; |
|
17 | +require_once __DIR__."/../inc/global.inc.php"; |
|
18 | 18 | |
19 | 19 | // First day of the current month to create sessions and add courses for the next month (e.g. "07") |
20 | 20 | define("OFFSET", "15"); |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | { |
42 | 42 | $startDate = $initialDate ? $initialDate : date("Y-m-01"); |
43 | 43 | $month = getQuarterFirstMonth(getQuarter(date('m', $startDate))); |
44 | - $startDate = substr($startDate, 0, 5) . $month . '-01'; |
|
44 | + $startDate = substr($startDate, 0, 5).$month.'-01'; |
|
45 | 45 | $nextQuarterStartDate = date('Y-m-d', api_strtotime($startDate.' + 3 month')); |
46 | 46 | $endDate = date('Y-m-d', api_strtotime($nextQuarterStartDate.' - 1 minute')); |
47 | 47 | return array('startDate' => $startDate, 'endDate' => $endDate); |
@@ -145,8 +145,7 @@ discard block |
||
145 | 145 | { |
146 | 146 | echo "\n"; |
147 | 147 | echo $courses ? |
148 | - "Creating sessions and adding courses for the period between ".$startDate." and ".$endDate : |
|
149 | - "Every course is already in session for the period between ".$startDate." and ".$endDate; |
|
148 | + "Creating sessions and adding courses for the period between ".$startDate." and ".$endDate : "Every course is already in session for the period between ".$startDate." and ".$endDate; |
|
150 | 149 | echo "\n=====================================================================================\n\n"; |
151 | 150 | // Loop through courses creating one session per each and adding them |
152 | 151 | foreach ($courses as $course) { |
@@ -155,8 +154,8 @@ discard block |
||
155 | 154 | $year = date("Y", api_strtotime($startDate)); |
156 | 155 | $quarter = getQuarter($month); |
157 | 156 | $quarter = getQuarterRoman($quarter); |
158 | - $period = $year . '-' . $quarter; |
|
159 | - $sessionName = '[' . $period . '] ' . $course['title']; |
|
157 | + $period = $year.'-'.$quarter; |
|
158 | + $sessionName = '['.$period.'] '.$course['title']; |
|
160 | 159 | $sessionId = SessionManager::create_session( |
161 | 160 | $sessionName, |
162 | 161 | $startDate, |
@@ -175,7 +174,7 @@ discard block |
||
175 | 174 | } |
176 | 175 | |
177 | 176 | // Starts the script |
178 | -echo "Starting process..." . PHP_EOL; |
|
177 | +echo "Starting process...".PHP_EOL; |
|
179 | 178 | // Get first active administrator |
180 | 179 | $administrators = array_reverse(UserManager::get_all_administrators()); |
181 | 180 | $lastingAdministrators = count($administrators); |
@@ -196,7 +195,7 @@ discard block |
||
196 | 195 | |
197 | 196 | // Creates course sessions for the following month |
198 | 197 | $offsetDay = intval(substr($dates['endDate'], 8, 2)) - OFFSET; |
199 | -if (date("Y-m-d") >= date(substr($dates['endDate'], 0, 8) . $offsetDay)) { |
|
198 | +if (date("Y-m-d") >= date(substr($dates['endDate'], 0, 8).$offsetDay)) { |
|
200 | 199 | $dates = getQuarterFirstAndLastDates(date("Y-m-d", api_strtotime(date("Y-m-01")." + 3 month"))); |
201 | 200 | // Get courses that don't have any session the next month |
202 | 201 | $courses = CourseManager::getCoursesWithoutSession($dates['startDate'], $dates['endDate']); |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | public $conditions; |
49 | 49 | |
50 | 50 | /** |
51 | - * @param Logger $logger |
|
51 | + * @param Monolog\Logger $logger |
|
52 | 52 | * @param array |
53 | 53 | */ |
54 | 54 | public function __construct($logger, $conditions) |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
69 | - * @return mixed |
|
69 | + * @return boolean |
|
70 | 70 | */ |
71 | 71 | public function getDumpValues() |
72 | 72 | { |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /* For licensing terms, see /license.txt */ |
3 | 3 | |
4 | -if (PHP_SAPI !='cli') { |
|
4 | +if (PHP_SAPI != 'cli') { |
|
5 | 5 | die('Run this script through the command line or comment this line in the code'); |
6 | 6 | } |
7 | 7 | |
@@ -365,11 +365,11 @@ discard block |
||
365 | 365 | $row = $this->cleanUserRow($row); |
366 | 366 | |
367 | 367 | $user_id = UserManager::get_user_id_from_original_id( |
368 | - $row['extra_' . $this->extraFieldIdNameList['user']], |
|
368 | + $row['extra_'.$this->extraFieldIdNameList['user']], |
|
369 | 369 | $this->extraFieldIdNameList['user'] |
370 | 370 | ); |
371 | - $userInfo = array(); |
|
372 | - $userInfoByOfficialCode = null; |
|
371 | + $userInfo = array(); |
|
372 | + $userInfoByOfficialCode = null; |
|
373 | 373 | |
374 | 374 | if (!empty($user_id)) { |
375 | 375 | $userInfo = api_get_user_info($user_id); |
@@ -423,7 +423,7 @@ discard block |
||
423 | 423 | $result = UserManager::update_user( |
424 | 424 | $userInfo['user_id'], |
425 | 425 | $row['firstname'], // <<-- changed |
426 | - $row['lastname'], // <<-- changed |
|
426 | + $row['lastname'], // <<-- changed |
|
427 | 427 | $userInfo['username'], |
428 | 428 | null, //$password = null, |
429 | 429 | $row['auth_source'], |
@@ -557,7 +557,7 @@ discard block |
||
557 | 557 | |
558 | 558 | if ($row['action'] == 'delete') { |
559 | 559 | // Inactive one year later |
560 | - $userInfo['expiration_date'] = api_get_utc_datetime(api_strtotime(time() + 365*24*60*60)); |
|
560 | + $userInfo['expiration_date'] = api_get_utc_datetime(api_strtotime(time() + 365 * 24 * 60 * 60)); |
|
561 | 561 | } |
562 | 562 | |
563 | 563 | $password = $row['password']; // change password |
@@ -606,8 +606,8 @@ discard block |
||
606 | 606 | $result = UserManager::update_user( |
607 | 607 | $userInfo['user_id'], |
608 | 608 | $row['firstname'], // <<-- changed |
609 | - $row['lastname'], // <<-- changed |
|
610 | - $row['username'], // <<-- changed |
|
609 | + $row['lastname'], // <<-- changed |
|
610 | + $row['username'], // <<-- changed |
|
611 | 611 | $password, //$password = null, |
612 | 612 | $row['auth_source'], |
613 | 613 | $email, |
@@ -674,7 +674,7 @@ discard block |
||
674 | 674 | $data = Import::csv_to_array($file); |
675 | 675 | |
676 | 676 | if (!empty($data)) { |
677 | - $this->logger->addInfo(count($data) . " records found."); |
|
677 | + $this->logger->addInfo(count($data)." records found."); |
|
678 | 678 | $eventsToCreate = array(); |
679 | 679 | $errorFound = false; |
680 | 680 | foreach ($data as $row) { |
@@ -688,7 +688,7 @@ discard block |
||
688 | 688 | ); |
689 | 689 | } |
690 | 690 | |
691 | - $courseCode = null; |
|
691 | + $courseCode = null; |
|
692 | 692 | if (isset($row['coursecode'])) { |
693 | 693 | $courseCode = $row['coursecode']; |
694 | 694 | } |
@@ -742,7 +742,7 @@ discard block |
||
742 | 742 | } |
743 | 743 | |
744 | 744 | $date = $row['date']; |
745 | - $startTime = $row['time_start']; |
|
745 | + $startTime = $row['time_start']; |
|
746 | 746 | $endTime = $row['time_end']; |
747 | 747 | $title = $row['title']; |
748 | 748 | $comment = $row['comment']; |
@@ -966,7 +966,7 @@ discard block |
||
966 | 966 | $row = $this->cleanCourseRow($row); |
967 | 967 | |
968 | 968 | $courseId = CourseManager::get_course_id_from_original_id( |
969 | - $row['extra_' . $this->extraFieldIdNameList['course']], |
|
969 | + $row['extra_'.$this->extraFieldIdNameList['course']], |
|
970 | 970 | $this->extraFieldIdNameList['course'] |
971 | 971 | ); |
972 | 972 | |
@@ -1084,7 +1084,7 @@ discard block |
||
1084 | 1084 | $data = Import::csv_reader($file); |
1085 | 1085 | |
1086 | 1086 | if (!empty($data)) { |
1087 | - $this->logger->addInfo(count($data) . " records found."); |
|
1087 | + $this->logger->addInfo(count($data)." records found."); |
|
1088 | 1088 | foreach ($data as $row) { |
1089 | 1089 | $chamiloUserName = $row['UserName']; |
1090 | 1090 | $chamiloCourseCode = $row['CourseCode']; |
@@ -1126,7 +1126,7 @@ discard block |
||
1126 | 1126 | ); |
1127 | 1127 | |
1128 | 1128 | $this->logger->addError( |
1129 | - "User '$chamiloUserName' was remove from Session: #$chamiloSessionId - Course: " . $courseInfo['code'] |
|
1129 | + "User '$chamiloUserName' was remove from Session: #$chamiloSessionId - Course: ".$courseInfo['code'] |
|
1130 | 1130 | ); |
1131 | 1131 | |
1132 | 1132 | } |
@@ -1143,7 +1143,7 @@ discard block |
||
1143 | 1143 | $data = Import::csv_reader($file); |
1144 | 1144 | |
1145 | 1145 | if (!empty($data)) { |
1146 | - $this->logger->addInfo(count($data) . " records found."); |
|
1146 | + $this->logger->addInfo(count($data)." records found."); |
|
1147 | 1147 | foreach ($data as $row) { |
1148 | 1148 | $chamiloUserName = $row['UserName']; |
1149 | 1149 | $chamiloCourseCode = $row['CourseCode']; |
@@ -1198,7 +1198,7 @@ discard block |
||
1198 | 1198 | } |
1199 | 1199 | |
1200 | 1200 | $this->logger->addError( |
1201 | - "User '$chamiloUserName' with status $type was added to session: #$chamiloSessionId - Course: " . $courseInfo['code'] |
|
1201 | + "User '$chamiloUserName' with status $type was added to session: #$chamiloSessionId - Course: ".$courseInfo['code'] |
|
1202 | 1202 | ); |
1203 | 1203 | } |
1204 | 1204 | } |
@@ -1441,7 +1441,7 @@ discard block |
||
1441 | 1441 | */ |
1442 | 1442 | private function importSessions($file, $moveFile = true, &$teacherBackup = array(), &$groupBackup = array()) |
1443 | 1443 | { |
1444 | - $avoid = null; |
|
1444 | + $avoid = null; |
|
1445 | 1445 | if (isset($this->conditions['importSessions']) && |
1446 | 1446 | isset($this->conditions['importSessions']['update']) |
1447 | 1447 | ) { |
@@ -1486,7 +1486,7 @@ discard block |
||
1486 | 1486 | $data = Import::csv_reader($file); |
1487 | 1487 | |
1488 | 1488 | if (!empty($data)) { |
1489 | - $this->logger->addInfo(count($data) . " records found."); |
|
1489 | + $this->logger->addInfo(count($data)." records found."); |
|
1490 | 1490 | foreach ($data as $row) { |
1491 | 1491 | $chamiloUserName = $row['UserName']; |
1492 | 1492 | $chamiloCourseCode = $row['CourseCode']; |
@@ -1533,7 +1533,7 @@ discard block |
||
1533 | 1533 | } |
1534 | 1534 | |
1535 | 1535 | $this->logger->addError( |
1536 | - "User '$chamiloUserName' with status $type was added to session: #$chamiloSessionId - Course: " . $courseInfo['code'] |
|
1536 | + "User '$chamiloUserName' with status $type was added to session: #$chamiloSessionId - Course: ".$courseInfo['code'] |
|
1537 | 1537 | ); |
1538 | 1538 | } |
1539 | 1539 | } |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | * @param string $author |
267 | 267 | * @param string $filename |
268 | 268 | * @param int $filesize |
269 | - * @param array $recipient_ids |
|
269 | + * @param unknown_type|null $recipient_ids |
|
270 | 270 | */ |
271 | 271 | public function _createNewSentWork($uploader_id, $title, $description, $author, $filename, $filesize, $recipient_ids) |
272 | 272 | { |
@@ -584,6 +584,7 @@ discard block |
||
584 | 584 | |
585 | 585 | /** |
586 | 586 | * Deletes all the received categories and work of this person |
587 | + * @param integer $id |
|
587 | 588 | */ |
588 | 589 | function deleteReceivedWorkFolder($id) |
589 | 590 | { |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | $action = isset($_GET['action']) ? $_GET['action'] : null; |
185 | 185 | |
186 | 186 | // Do some sanity checks |
187 | - $id = intval($id); |
|
187 | + $id = intval($id); |
|
188 | 188 | |
189 | 189 | // Get the data from DB |
190 | 190 | $sql = "SELECT uploader_id, filename, filesize, title, description, author, upload_date, last_upload_date, cat_id |
@@ -226,14 +226,14 @@ discard block |
||
226 | 226 | $row_feedback['feedback'] = Security::remove_XSS($row_feedback['feedback']); |
227 | 227 | $feedback2[] = $row_feedback; |
228 | 228 | } |
229 | - $this->feedback2= $feedback2; |
|
229 | + $this->feedback2 = $feedback2; |
|
230 | 230 | } |
231 | 231 | } |
232 | 232 | } |
233 | 233 | |
234 | 234 | class Dropbox_SentWork extends Dropbox_Work |
235 | 235 | { |
236 | - public $recipients; //array of ['id']['name'] arrays |
|
236 | + public $recipients; //array of ['id']['name'] arrays |
|
237 | 237 | |
238 | 238 | /** |
239 | 239 | * Constructor calls private functions to create a new work or retreive an existing work from DB |
@@ -290,15 +290,15 @@ discard block |
||
290 | 290 | settype($uploader_id, 'integer') or die(get_lang('GeneralError').' (code 208)'); // Set $uploader_id to correct type |
291 | 291 | |
292 | 292 | $justSubmit = false; |
293 | - if ( is_int($recipient_ids)) { |
|
293 | + if (is_int($recipient_ids)) { |
|
294 | 294 | $justSubmit = true; |
295 | 295 | $recipient_ids = array($recipient_ids + $this->id); |
296 | - } elseif ( count($recipient_ids) == 0) { |
|
296 | + } elseif (count($recipient_ids) == 0) { |
|
297 | 297 | $justSubmit = true; |
298 | 298 | $recipient_ids = array($uploader_id); |
299 | 299 | } |
300 | 300 | |
301 | - if (! is_array($recipient_ids) || count($recipient_ids) == 0) { |
|
301 | + if (!is_array($recipient_ids) || count($recipient_ids) == 0) { |
|
302 | 302 | die(get_lang('GeneralError').' (code 209)'); |
303 | 303 | } |
304 | 304 | |
@@ -313,11 +313,11 @@ discard block |
||
313 | 313 | $table_person = $dropbox_cnf['tbl_person']; |
314 | 314 | $session_id = api_get_session_id(); |
315 | 315 | $uploader_id = $this->uploader_id; |
316 | - $user = api_get_user_id(); |
|
316 | + $user = api_get_user_id(); |
|
317 | 317 | // Insert data in dropbox_post and dropbox_person table for each recipient |
318 | 318 | foreach ($this->recipients as $rec) { |
319 | - $file_id = (int)$this->id; |
|
320 | - $user_id = (int)$rec['id']; |
|
319 | + $file_id = (int) $this->id; |
|
320 | + $user_id = (int) $rec['id']; |
|
321 | 321 | $sql = "INSERT INTO $table_post (c_id, file_id, dest_user_id, session_id) |
322 | 322 | VALUES ($course_id, $file_id, $user_id, $session_id)"; |
323 | 323 | Database::query($sql); |
@@ -333,7 +333,7 @@ discard block |
||
333 | 333 | |
334 | 334 | // Do not add recipient in person table if mailing zip or just upload. |
335 | 335 | if (!$justSubmit) { |
336 | - Database::query($sql); // If work already exists no error is generated |
|
336 | + Database::query($sql); // If work already exists no error is generated |
|
337 | 337 | } |
338 | 338 | } |
339 | 339 | |
@@ -342,7 +342,7 @@ discard block |
||
342 | 342 | $ownerid = getUserOwningThisMailing($ownerid); |
343 | 343 | } |
344 | 344 | if (($recipid = $rec["id"]) > $dropbox_cnf['mailingIdBase']) { |
345 | - $recipid = $ownerid; // mailing file recipient = mailing id, not a person |
|
345 | + $recipid = $ownerid; // mailing file recipient = mailing id, not a person |
|
346 | 346 | } |
347 | 347 | api_item_property_update( |
348 | 348 | $_course, |
@@ -401,13 +401,13 @@ discard block |
||
401 | 401 | class Dropbox_Person |
402 | 402 | { |
403 | 403 | // The receivedWork and the sentWork arrays are sorted. |
404 | - public $receivedWork; // an array of Dropbox_Work objects |
|
405 | - public $sentWork; // an array of Dropbox_SentWork objects |
|
404 | + public $receivedWork; // an array of Dropbox_Work objects |
|
405 | + public $sentWork; // an array of Dropbox_SentWork objects |
|
406 | 406 | |
407 | 407 | public $userId = 0; |
408 | 408 | public $isCourseAdmin = false; |
409 | 409 | public $isCourseTutor = false; |
410 | - public $_orderBy = ''; // private property that determines by which field |
|
410 | + public $_orderBy = ''; // private property that determines by which field |
|
411 | 411 | |
412 | 412 | /** |
413 | 413 | * Constructor for recreating the Dropbox_Person object |
@@ -506,7 +506,7 @@ discard block |
||
506 | 506 | */ |
507 | 507 | function orderSentWork($sort) |
508 | 508 | { |
509 | - switch($sort) { |
|
509 | + switch ($sort) { |
|
510 | 510 | case 'lastDate': |
511 | 511 | $this->_orderBy = 'last_upload_date'; |
512 | 512 | break; |
@@ -539,7 +539,7 @@ discard block |
||
539 | 539 | */ |
540 | 540 | function orderReceivedWork($sort) |
541 | 541 | { |
542 | - switch($sort) { |
|
542 | + switch ($sort) { |
|
543 | 543 | case 'lastDate': |
544 | 544 | $this->_orderBy = 'last_upload_date'; |
545 | 545 | break; |
@@ -632,7 +632,7 @@ discard block |
||
632 | 632 | $sql = "DELETE FROM ".$dropbox_cnf['tbl_person']." |
633 | 633 | WHERE c_id = $course_id AND user_id = '".$this->userId."' AND file_id ='".$id."'"; |
634 | 634 | Database::query($sql); |
635 | - removeUnusedFiles(); // Check for unused files |
|
635 | + removeUnusedFiles(); // Check for unused files |
|
636 | 636 | } |
637 | 637 | |
638 | 638 | /** |
@@ -649,7 +649,7 @@ discard block |
||
649 | 649 | Database::query($sql); |
650 | 650 | removeMoreIfMailing($w->id); |
651 | 651 | } |
652 | - removeUnusedFiles(); // Check for unused files |
|
652 | + removeUnusedFiles(); // Check for unused files |
|
653 | 653 | } |
654 | 654 | |
655 | 655 | /** |
@@ -683,7 +683,7 @@ discard block |
||
683 | 683 | WHERE c_id = $course_id AND user_id='".$this->userId."' AND file_id='".$id."'"; |
684 | 684 | Database::query($sql); |
685 | 685 | removeMoreIfMailing($id); |
686 | - removeUnusedFiles(); // Check for unused files |
|
686 | + removeUnusedFiles(); // Check for unused files |
|
687 | 687 | } |
688 | 688 | |
689 | 689 | /** |
@@ -705,7 +705,7 @@ discard block |
||
705 | 705 | $wi = -1; |
706 | 706 | foreach ($this->receivedWork as $w) { |
707 | 707 | $wi++; |
708 | - if ($w->id == $id){ |
|
708 | + if ($w->id == $id) { |
|
709 | 709 | $found = true; |
710 | 710 | break; |
711 | 711 | } // foreach (... as $wi -> $w) gives error 221! (no idea why...) |
@@ -303,7 +303,9 @@ discard block |
||
303 | 303 | } |
304 | 304 | |
305 | 305 | foreach ($recipient_ids as $rec) { |
306 | - if (empty($rec)) die(get_lang('GeneralError').' (code 210)'); |
|
306 | + if (empty($rec)) { |
|
307 | + die(get_lang('GeneralError').' (code 210)'); |
|
308 | + } |
|
307 | 309 | //if (!isCourseMember($rec)) die(); //cannot sent document to someone outside of course |
308 | 310 | //this check is done when validating submitted data |
309 | 311 | $this->recipients[] = array('id' => $rec, 'name' => getUserNameFromId($rec)); |
@@ -593,13 +595,19 @@ discard block |
||
593 | 595 | $id = intval($id); |
594 | 596 | $sql = "DELETE FROM ".$dropbox_cnf['tbl_file']." |
595 | 597 | WHERE c_id = $course_id AND cat_id = '".$id."' "; |
596 | - if (!Database::query($sql)) return false; |
|
598 | + if (!Database::query($sql)) { |
|
599 | + return false; |
|
600 | + } |
|
597 | 601 | $sql = "DELETE FROM ".$dropbox_cnf['tbl_category']." |
598 | 602 | WHERE c_id = $course_id AND cat_id = '".$id."' "; |
599 | - if (!Database::query($sql)) return false; |
|
603 | + if (!Database::query($sql)) { |
|
604 | + return false; |
|
605 | + } |
|
600 | 606 | $sql = "DELETE FROM ".$dropbox_cnf['tbl_post']." |
601 | 607 | WHERE c_id = $course_id AND cat_id = '".$id."' "; |
602 | - if (!Database::query($sql)) return false; |
|
608 | + if (!Database::query($sql)) { |
|
609 | + return false; |
|
610 | + } |
|
603 | 611 | return true; |
604 | 612 | } |
605 | 613 |
@@ -77,20 +77,20 @@ discard block |
||
77 | 77 | } |
78 | 78 | } |
79 | 79 | |
80 | - /** |
|
81 | - * private function creating a new work object |
|
82 | - * |
|
83 | - * @param int $uploader_id |
|
84 | - * @param string $title |
|
85 | - * @param string $description |
|
86 | - * @param string $author |
|
87 | - * @param string $filename |
|
88 | - * @param int $filesize |
|
89 | - * |
|
90 | - * @todo $author was originally a field but this has now been replaced by the first and lastname of the uploader (to prevent anonymous uploads) |
|
91 | - * As a consequence this parameter can be removed |
|
92 | - */ |
|
93 | - public function _createNewWork($uploader_id, $title, $description, $author, $filename, $filesize) |
|
80 | + /** |
|
81 | + * private function creating a new work object |
|
82 | + * |
|
83 | + * @param int $uploader_id |
|
84 | + * @param string $title |
|
85 | + * @param string $description |
|
86 | + * @param string $author |
|
87 | + * @param string $filename |
|
88 | + * @param int $filesize |
|
89 | + * |
|
90 | + * @todo $author was originally a field but this has now been replaced by the first and lastname of the uploader (to prevent anonymous uploads) |
|
91 | + * As a consequence this parameter can be removed |
|
92 | + */ |
|
93 | + public function _createNewWork($uploader_id, $title, $description, $author, $filename, $filesize) |
|
94 | 94 | { |
95 | 95 | $dropbox_cnf = getDropboxConf(); |
96 | 96 | |
@@ -108,17 +108,17 @@ discard block |
||
108 | 108 | // Check if object exists already. If it does, the old object is used |
109 | 109 | // with updated information (authors, description, upload_date) |
110 | 110 | $this->isOldWork = false; |
111 | - $sql = "SELECT id, upload_date FROM ".$dropbox_cnf['tbl_file']." |
|
111 | + $sql = "SELECT id, upload_date FROM ".$dropbox_cnf['tbl_file']." |
|
112 | 112 | WHERE c_id = $course_id AND filename = '".Database::escape_string($this->filename)."'"; |
113 | 113 | $result = Database::query($sql); |
114 | - $res = Database::fetch_array($result); |
|
115 | - if ($res) { |
|
116 | - $this->isOldWork = true; |
|
117 | - } |
|
118 | - // Insert or update the dropbox_file table and set the id property |
|
119 | - if ($this->isOldWork) { |
|
120 | - $this->id = $res['id']; |
|
121 | - $this->upload_date = $res['upload_date']; |
|
114 | + $res = Database::fetch_array($result); |
|
115 | + if ($res) { |
|
116 | + $this->isOldWork = true; |
|
117 | + } |
|
118 | + // Insert or update the dropbox_file table and set the id property |
|
119 | + if ($this->isOldWork) { |
|
120 | + $this->id = $res['id']; |
|
121 | + $this->upload_date = $res['upload_date']; |
|
122 | 122 | |
123 | 123 | $params = [ |
124 | 124 | 'filesize' => $this->filesize, |
@@ -135,9 +135,9 @@ discard block |
||
135 | 135 | ['c_id = ? AND id = ?' => [$course_id, $this->id]] |
136 | 136 | ); |
137 | 137 | |
138 | - } else { |
|
139 | - $this->upload_date = $this->last_upload_date; |
|
140 | - $params = [ |
|
138 | + } else { |
|
139 | + $this->upload_date = $this->last_upload_date; |
|
140 | + $params = [ |
|
141 | 141 | 'c_id' => $course_id, |
142 | 142 | 'uploader_id' => $this->uploader_id, |
143 | 143 | 'filename' => $this->filename, |
@@ -148,14 +148,14 @@ discard block |
||
148 | 148 | 'upload_date' => $this->upload_date, |
149 | 149 | 'last_upload_date' => $this->last_upload_date, |
150 | 150 | 'session_id' => api_get_session_id(), |
151 | - ]; |
|
152 | - $this->id = Database::insert($dropbox_cnf['tbl_file'], $params); |
|
151 | + ]; |
|
152 | + $this->id = Database::insert($dropbox_cnf['tbl_file'], $params); |
|
153 | 153 | |
154 | - if ($this->id) { |
|
155 | - $sql = "UPDATE ".$dropbox_cnf['tbl_file']." SET id = iid WHERE iid = {$this->id}"; |
|
156 | - Database::query($sql); |
|
157 | - } |
|
158 | - } |
|
154 | + if ($this->id) { |
|
155 | + $sql = "UPDATE ".$dropbox_cnf['tbl_file']." SET id = iid WHERE iid = {$this->id}"; |
|
156 | + Database::query($sql); |
|
157 | + } |
|
158 | + } |
|
159 | 159 | |
160 | 160 | $sql = "SELECT count(file_id) as count |
161 | 161 | FROM ".$dropbox_cnf['tbl_person']." |
@@ -169,16 +169,16 @@ discard block |
||
169 | 169 | VALUES ($course_id, ".intval($this->id)." , ".intval($this->uploader_id).")"; |
170 | 170 | Database::query($sql); |
171 | 171 | } |
172 | - } |
|
173 | - |
|
174 | - /** |
|
175 | - * private function creating existing object by retreiving info from db |
|
176 | - * |
|
177 | - * @param int $id |
|
178 | - */ |
|
179 | - public function _createExistingWork($id) |
|
172 | + } |
|
173 | + |
|
174 | + /** |
|
175 | + * private function creating existing object by retreiving info from db |
|
176 | + * |
|
177 | + * @param int $id |
|
178 | + */ |
|
179 | + public function _createExistingWork($id) |
|
180 | 180 | { |
181 | - $course_id = api_get_course_int_id(); |
|
181 | + $course_id = api_get_course_int_id(); |
|
182 | 182 | $dropbox_cnf = getDropboxConf(); |
183 | 183 | |
184 | 184 | $action = isset($_GET['action']) ? $_GET['action'] : null; |
@@ -228,52 +228,52 @@ discard block |
||
228 | 228 | } |
229 | 229 | $this->feedback2= $feedback2; |
230 | 230 | } |
231 | - } |
|
231 | + } |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | class Dropbox_SentWork extends Dropbox_Work |
235 | 235 | { |
236 | - public $recipients; //array of ['id']['name'] arrays |
|
237 | - |
|
238 | - /** |
|
239 | - * Constructor calls private functions to create a new work or retreive an existing work from DB |
|
240 | - * depending on the number of parameters |
|
241 | - * |
|
242 | - * @param unknown_type $arg1 |
|
243 | - * @param unknown_type $arg2 |
|
244 | - * @param unknown_type $arg3 |
|
245 | - * @param unknown_type $arg4 |
|
246 | - * @param unknown_type $arg5 |
|
247 | - * @param unknown_type $arg6 |
|
248 | - * @param unknown_type $arg7 |
|
249 | - * @return Dropbox_SentWork |
|
250 | - */ |
|
251 | - function Dropbox_SentWork($arg1, $arg2 = null, $arg3 = null, $arg4 = null, $arg5 = null, $arg6 = null, $arg7 = null) |
|
236 | + public $recipients; //array of ['id']['name'] arrays |
|
237 | + |
|
238 | + /** |
|
239 | + * Constructor calls private functions to create a new work or retreive an existing work from DB |
|
240 | + * depending on the number of parameters |
|
241 | + * |
|
242 | + * @param unknown_type $arg1 |
|
243 | + * @param unknown_type $arg2 |
|
244 | + * @param unknown_type $arg3 |
|
245 | + * @param unknown_type $arg4 |
|
246 | + * @param unknown_type $arg5 |
|
247 | + * @param unknown_type $arg6 |
|
248 | + * @param unknown_type $arg7 |
|
249 | + * @return Dropbox_SentWork |
|
250 | + */ |
|
251 | + function Dropbox_SentWork($arg1, $arg2 = null, $arg3 = null, $arg4 = null, $arg5 = null, $arg6 = null, $arg7 = null) |
|
252 | 252 | { |
253 | - if (func_num_args() > 1) { |
|
254 | - $this->_createNewSentWork($arg1, $arg2, $arg3, $arg4, $arg5, $arg6, $arg7); |
|
255 | - } else { |
|
256 | - $this->_createExistingSentWork($arg1); |
|
257 | - } |
|
258 | - } |
|
259 | - |
|
260 | - /** |
|
261 | - * private function creating a new SentWork object |
|
262 | - * |
|
263 | - * @param int $uploader_id |
|
264 | - * @param string $title |
|
265 | - * @param string $description |
|
266 | - * @param string $author |
|
267 | - * @param string $filename |
|
268 | - * @param int $filesize |
|
269 | - * @param array $recipient_ids |
|
270 | - */ |
|
271 | - public function _createNewSentWork($uploader_id, $title, $description, $author, $filename, $filesize, $recipient_ids) |
|
253 | + if (func_num_args() > 1) { |
|
254 | + $this->_createNewSentWork($arg1, $arg2, $arg3, $arg4, $arg5, $arg6, $arg7); |
|
255 | + } else { |
|
256 | + $this->_createExistingSentWork($arg1); |
|
257 | + } |
|
258 | + } |
|
259 | + |
|
260 | + /** |
|
261 | + * private function creating a new SentWork object |
|
262 | + * |
|
263 | + * @param int $uploader_id |
|
264 | + * @param string $title |
|
265 | + * @param string $description |
|
266 | + * @param string $author |
|
267 | + * @param string $filename |
|
268 | + * @param int $filesize |
|
269 | + * @param array $recipient_ids |
|
270 | + */ |
|
271 | + public function _createNewSentWork($uploader_id, $title, $description, $author, $filename, $filesize, $recipient_ids) |
|
272 | 272 | { |
273 | 273 | $dropbox_cnf = getDropboxConf(); |
274 | 274 | $_course = api_get_course_info(); |
275 | 275 | |
276 | - // Call constructor of Dropbox_Work object |
|
276 | + // Call constructor of Dropbox_Work object |
|
277 | 277 | $this->Dropbox_Work( |
278 | 278 | $uploader_id, |
279 | 279 | $title, |
@@ -283,44 +283,44 @@ discard block |
||
283 | 283 | $filesize |
284 | 284 | ); |
285 | 285 | |
286 | - $course_id = api_get_course_int_id(); |
|
287 | - |
|
288 | - // Do sanity checks on recipient_ids array & property fillin |
|
289 | - // The sanity check for ex-coursemembers is already done in base constructor |
|
290 | - settype($uploader_id, 'integer') or die(get_lang('GeneralError').' (code 208)'); // Set $uploader_id to correct type |
|
286 | + $course_id = api_get_course_int_id(); |
|
291 | 287 | |
292 | - $justSubmit = false; |
|
293 | - if ( is_int($recipient_ids)) { |
|
294 | - $justSubmit = true; |
|
295 | - $recipient_ids = array($recipient_ids + $this->id); |
|
296 | - } elseif ( count($recipient_ids) == 0) { |
|
297 | - $justSubmit = true; |
|
298 | - $recipient_ids = array($uploader_id); |
|
299 | - } |
|
288 | + // Do sanity checks on recipient_ids array & property fillin |
|
289 | + // The sanity check for ex-coursemembers is already done in base constructor |
|
290 | + settype($uploader_id, 'integer') or die(get_lang('GeneralError').' (code 208)'); // Set $uploader_id to correct type |
|
291 | + |
|
292 | + $justSubmit = false; |
|
293 | + if ( is_int($recipient_ids)) { |
|
294 | + $justSubmit = true; |
|
295 | + $recipient_ids = array($recipient_ids + $this->id); |
|
296 | + } elseif ( count($recipient_ids) == 0) { |
|
297 | + $justSubmit = true; |
|
298 | + $recipient_ids = array($uploader_id); |
|
299 | + } |
|
300 | 300 | |
301 | - if (! is_array($recipient_ids) || count($recipient_ids) == 0) { |
|
302 | - die(get_lang('GeneralError').' (code 209)'); |
|
303 | - } |
|
301 | + if (! is_array($recipient_ids) || count($recipient_ids) == 0) { |
|
302 | + die(get_lang('GeneralError').' (code 209)'); |
|
303 | + } |
|
304 | 304 | |
305 | - foreach ($recipient_ids as $rec) { |
|
306 | - if (empty($rec)) die(get_lang('GeneralError').' (code 210)'); |
|
307 | - //if (!isCourseMember($rec)) die(); //cannot sent document to someone outside of course |
|
308 | - //this check is done when validating submitted data |
|
309 | - $this->recipients[] = array('id' => $rec, 'name' => getUserNameFromId($rec)); |
|
310 | - } |
|
305 | + foreach ($recipient_ids as $rec) { |
|
306 | + if (empty($rec)) die(get_lang('GeneralError').' (code 210)'); |
|
307 | + //if (!isCourseMember($rec)) die(); //cannot sent document to someone outside of course |
|
308 | + //this check is done when validating submitted data |
|
309 | + $this->recipients[] = array('id' => $rec, 'name' => getUserNameFromId($rec)); |
|
310 | + } |
|
311 | 311 | |
312 | 312 | $table_post = $dropbox_cnf['tbl_post']; |
313 | 313 | $table_person = $dropbox_cnf['tbl_person']; |
314 | 314 | $session_id = api_get_session_id(); |
315 | 315 | $uploader_id = $this->uploader_id; |
316 | 316 | $user = api_get_user_id(); |
317 | - // Insert data in dropbox_post and dropbox_person table for each recipient |
|
318 | - foreach ($this->recipients as $rec) { |
|
317 | + // Insert data in dropbox_post and dropbox_person table for each recipient |
|
318 | + foreach ($this->recipients as $rec) { |
|
319 | 319 | $file_id = (int)$this->id; |
320 | 320 | $user_id = (int)$rec['id']; |
321 | - $sql = "INSERT INTO $table_post (c_id, file_id, dest_user_id, session_id) |
|
321 | + $sql = "INSERT INTO $table_post (c_id, file_id, dest_user_id, session_id) |
|
322 | 322 | VALUES ($course_id, $file_id, $user_id, $session_id)"; |
323 | - Database::query($sql); |
|
323 | + Database::query($sql); |
|
324 | 324 | // If work already exists no error is generated |
325 | 325 | |
326 | 326 | /** |
@@ -337,13 +337,13 @@ discard block |
||
337 | 337 | } |
338 | 338 | } |
339 | 339 | |
340 | - // Update item_property table for each recipient |
|
341 | - if (($ownerid = $this->uploader_id) > $dropbox_cnf['mailingIdBase']) { |
|
342 | - $ownerid = getUserOwningThisMailing($ownerid); |
|
343 | - } |
|
344 | - if (($recipid = $rec["id"]) > $dropbox_cnf['mailingIdBase']) { |
|
345 | - $recipid = $ownerid; // mailing file recipient = mailing id, not a person |
|
346 | - } |
|
340 | + // Update item_property table for each recipient |
|
341 | + if (($ownerid = $this->uploader_id) > $dropbox_cnf['mailingIdBase']) { |
|
342 | + $ownerid = getUserOwningThisMailing($ownerid); |
|
343 | + } |
|
344 | + if (($recipid = $rec["id"]) > $dropbox_cnf['mailingIdBase']) { |
|
345 | + $recipid = $ownerid; // mailing file recipient = mailing id, not a person |
|
346 | + } |
|
347 | 347 | api_item_property_update( |
348 | 348 | $_course, |
349 | 349 | TOOL_DROPBOX, |
@@ -353,92 +353,92 @@ discard block |
||
353 | 353 | null, |
354 | 354 | $recipid |
355 | 355 | ); |
356 | - } |
|
357 | - } |
|
358 | - |
|
359 | - /** |
|
360 | - * private function creating existing object by retreiving info from db |
|
361 | - * |
|
362 | - * @param unknown_type $id |
|
363 | - */ |
|
364 | - function _createExistingSentWork($id) |
|
356 | + } |
|
357 | + } |
|
358 | + |
|
359 | + /** |
|
360 | + * private function creating existing object by retreiving info from db |
|
361 | + * |
|
362 | + * @param unknown_type $id |
|
363 | + */ |
|
364 | + function _createExistingSentWork($id) |
|
365 | 365 | { |
366 | 366 | $dropbox_cnf = getDropboxConf(); |
367 | 367 | $id = intval($id); |
368 | 368 | |
369 | - $course_id = api_get_course_int_id(); |
|
369 | + $course_id = api_get_course_int_id(); |
|
370 | 370 | |
371 | - // Call constructor of Dropbox_Work object |
|
372 | - $this->Dropbox_Work($id); |
|
371 | + // Call constructor of Dropbox_Work object |
|
372 | + $this->Dropbox_Work($id); |
|
373 | 373 | |
374 | - // Fill in recipients array |
|
375 | - $this->recipients = array(); |
|
376 | - $sql = "SELECT dest_user_id, feedback_date, feedback |
|
374 | + // Fill in recipients array |
|
375 | + $this->recipients = array(); |
|
376 | + $sql = "SELECT dest_user_id, feedback_date, feedback |
|
377 | 377 | FROM ".$dropbox_cnf['tbl_post']." |
378 | 378 | WHERE c_id = $course_id AND file_id = ".intval($id).""; |
379 | 379 | $result = Database::query($sql); |
380 | - while ($res = Database::fetch_array($result, 'ASSOC')) { |
|
381 | - |
|
382 | - // Check for deleted users |
|
383 | - $dest_user_id = $res['dest_user_id']; |
|
384 | - $user_info = api_get_user_info($dest_user_id); |
|
385 | - //$this->category = $res['cat_id']; |
|
386 | - if (!$user_info) { |
|
387 | - $this->recipients[] = array('id' => -1, 'name' => get_lang('Unknown', '')); |
|
388 | - } else { |
|
389 | - $this->recipients[] = array( |
|
380 | + while ($res = Database::fetch_array($result, 'ASSOC')) { |
|
381 | + |
|
382 | + // Check for deleted users |
|
383 | + $dest_user_id = $res['dest_user_id']; |
|
384 | + $user_info = api_get_user_info($dest_user_id); |
|
385 | + //$this->category = $res['cat_id']; |
|
386 | + if (!$user_info) { |
|
387 | + $this->recipients[] = array('id' => -1, 'name' => get_lang('Unknown', '')); |
|
388 | + } else { |
|
389 | + $this->recipients[] = array( |
|
390 | 390 | 'id' => $dest_user_id, |
391 | 391 | 'name' => $user_info['complete_name'], |
392 | 392 | 'user_id' => $dest_user_id, |
393 | - 'feedback_date' => $res['feedback_date'], |
|
393 | + 'feedback_date' => $res['feedback_date'], |
|
394 | 394 | 'feedback' => $res['feedback'] |
395 | 395 | ); |
396 | - } |
|
397 | - } |
|
398 | - } |
|
396 | + } |
|
397 | + } |
|
398 | + } |
|
399 | 399 | } |
400 | 400 | |
401 | 401 | class Dropbox_Person |
402 | 402 | { |
403 | - // The receivedWork and the sentWork arrays are sorted. |
|
404 | - public $receivedWork; // an array of Dropbox_Work objects |
|
405 | - public $sentWork; // an array of Dropbox_SentWork objects |
|
406 | - |
|
407 | - public $userId = 0; |
|
408 | - public $isCourseAdmin = false; |
|
409 | - public $isCourseTutor = false; |
|
410 | - public $_orderBy = ''; // private property that determines by which field |
|
411 | - |
|
412 | - /** |
|
413 | - * Constructor for recreating the Dropbox_Person object |
|
414 | - * |
|
415 | - * @param int $userId |
|
416 | - * @param bool $isCourseAdmin |
|
417 | - * @param bool $isCourseTutor |
|
418 | - * @return Dropbox_Person |
|
419 | - */ |
|
420 | - function Dropbox_Person($userId, $isCourseAdmin, $isCourseTutor) |
|
403 | + // The receivedWork and the sentWork arrays are sorted. |
|
404 | + public $receivedWork; // an array of Dropbox_Work objects |
|
405 | + public $sentWork; // an array of Dropbox_SentWork objects |
|
406 | + |
|
407 | + public $userId = 0; |
|
408 | + public $isCourseAdmin = false; |
|
409 | + public $isCourseTutor = false; |
|
410 | + public $_orderBy = ''; // private property that determines by which field |
|
411 | + |
|
412 | + /** |
|
413 | + * Constructor for recreating the Dropbox_Person object |
|
414 | + * |
|
415 | + * @param int $userId |
|
416 | + * @param bool $isCourseAdmin |
|
417 | + * @param bool $isCourseTutor |
|
418 | + * @return Dropbox_Person |
|
419 | + */ |
|
420 | + function Dropbox_Person($userId, $isCourseAdmin, $isCourseTutor) |
|
421 | 421 | { |
422 | - $course_id = api_get_course_int_id(); |
|
422 | + $course_id = api_get_course_int_id(); |
|
423 | 423 | |
424 | - // Fill in properties |
|
424 | + // Fill in properties |
|
425 | 425 | $this->userId = $userId; |
426 | 426 | $this->isCourseAdmin = $isCourseAdmin; |
427 | 427 | $this->isCourseTutor = $isCourseTutor; |
428 | 428 | $this->receivedWork = array(); |
429 | 429 | $this->sentWork = array(); |
430 | 430 | |
431 | - // Note: perhaps include an ex coursemember check to delete old files |
|
431 | + // Note: perhaps include an ex coursemember check to delete old files |
|
432 | 432 | |
433 | - $session_id = api_get_session_id(); |
|
434 | - $condition_session = api_get_session_condition($session_id); |
|
433 | + $session_id = api_get_session_id(); |
|
434 | + $condition_session = api_get_session_condition($session_id); |
|
435 | 435 | |
436 | - $post_tbl = Database::get_course_table(TABLE_DROPBOX_POST); |
|
437 | - $person_tbl = Database::get_course_table(TABLE_DROPBOX_PERSON); |
|
438 | - $file_tbl = Database::get_course_table(TABLE_DROPBOX_FILE); |
|
436 | + $post_tbl = Database::get_course_table(TABLE_DROPBOX_POST); |
|
437 | + $person_tbl = Database::get_course_table(TABLE_DROPBOX_PERSON); |
|
438 | + $file_tbl = Database::get_course_table(TABLE_DROPBOX_FILE); |
|
439 | 439 | |
440 | 440 | // Find all entries where this person is the recipient |
441 | - $sql = "SELECT DISTINCT r.file_id, r.cat_id |
|
441 | + $sql = "SELECT DISTINCT r.file_id, r.cat_id |
|
442 | 442 | FROM $post_tbl r |
443 | 443 | INNER JOIN $person_tbl p |
444 | 444 | ON (r.file_id = p.file_id AND r.c_id = $course_id AND p.c_id = $course_id ) |
@@ -447,12 +447,12 @@ discard block |
||
447 | 447 | r.dest_user_id = ".intval($this->userId)." $condition_session "; |
448 | 448 | |
449 | 449 | $result = Database::query($sql); |
450 | - while ($res = Database::fetch_array($result)) { |
|
451 | - $temp = new Dropbox_Work($res['file_id']); |
|
452 | - $temp->category = $res['cat_id']; |
|
453 | - $this->receivedWork[] = $temp; |
|
454 | - } |
|
455 | - // Find all entries where this person is the sender/uploader |
|
450 | + while ($res = Database::fetch_array($result)) { |
|
451 | + $temp = new Dropbox_Work($res['file_id']); |
|
452 | + $temp->category = $res['cat_id']; |
|
453 | + $this->receivedWork[] = $temp; |
|
454 | + } |
|
455 | + // Find all entries where this person is the sender/uploader |
|
456 | 456 | $sql = "SELECT DISTINCT f.id |
457 | 457 | FROM $file_tbl f |
458 | 458 | INNER JOIN $person_tbl p |
@@ -463,260 +463,260 @@ discard block |
||
463 | 463 | $condition_session |
464 | 464 | "; |
465 | 465 | $result = Database::query($sql); |
466 | - while ($res = Database::fetch_array($result)) { |
|
467 | - $this->sentWork[] = new Dropbox_SentWork($res['id']); |
|
468 | - } |
|
469 | - } |
|
470 | - |
|
471 | - /** |
|
472 | - * This private method is used by the usort function in the |
|
473 | - * orderSentWork and orderReceivedWork methods. |
|
474 | - * It compares 2 work-objects by 1 of the properties of that object, dictated by the |
|
475 | - * private property _orderBy |
|
476 | - * |
|
477 | - * @param unknown_type $a |
|
478 | - * @param unknown_type $b |
|
479 | - * @return -1, 0 or 1 dependent of the result of the comparison. |
|
480 | - */ |
|
481 | - function _cmpWork($a, $b) |
|
466 | + while ($res = Database::fetch_array($result)) { |
|
467 | + $this->sentWork[] = new Dropbox_SentWork($res['id']); |
|
468 | + } |
|
469 | + } |
|
470 | + |
|
471 | + /** |
|
472 | + * This private method is used by the usort function in the |
|
473 | + * orderSentWork and orderReceivedWork methods. |
|
474 | + * It compares 2 work-objects by 1 of the properties of that object, dictated by the |
|
475 | + * private property _orderBy |
|
476 | + * |
|
477 | + * @param unknown_type $a |
|
478 | + * @param unknown_type $b |
|
479 | + * @return -1, 0 or 1 dependent of the result of the comparison. |
|
480 | + */ |
|
481 | + function _cmpWork($a, $b) |
|
482 | 482 | { |
483 | - $sort = $this->_orderBy; |
|
484 | - $aval = $a->$sort; |
|
485 | - $bval = $b->$sort; |
|
486 | - if ($sort == 'recipients') { |
|
487 | - // The recipients property is an array so we do the comparison based |
|
488 | - // on the first item of the recipients array |
|
489 | - $aval = $aval[0]['name']; |
|
490 | - $bval = $bval[0]['name']; |
|
491 | - } |
|
492 | - if ($sort == 'filesize') { // Filesize is not a string, so we use other comparison technique |
|
493 | - return $aval < $bval ? -1 : 1; |
|
494 | - } elseif ($sort == 'title') { // Natural order for sorting titles is more "human-friendly" |
|
495 | - return api_strnatcmp($aval, $bval); |
|
496 | - } else { |
|
497 | - return api_strcasecmp($aval, $bval); |
|
498 | - } |
|
499 | - } |
|
500 | - |
|
501 | - /** |
|
502 | - * A method that sorts the objects in the sentWork array, dependent on the $sort parameter. |
|
503 | - * $sort can be lastDate, firstDate, title, size, ... |
|
504 | - * |
|
505 | - * @param unknown_type $sort |
|
506 | - */ |
|
507 | - function orderSentWork($sort) |
|
483 | + $sort = $this->_orderBy; |
|
484 | + $aval = $a->$sort; |
|
485 | + $bval = $b->$sort; |
|
486 | + if ($sort == 'recipients') { |
|
487 | + // The recipients property is an array so we do the comparison based |
|
488 | + // on the first item of the recipients array |
|
489 | + $aval = $aval[0]['name']; |
|
490 | + $bval = $bval[0]['name']; |
|
491 | + } |
|
492 | + if ($sort == 'filesize') { // Filesize is not a string, so we use other comparison technique |
|
493 | + return $aval < $bval ? -1 : 1; |
|
494 | + } elseif ($sort == 'title') { // Natural order for sorting titles is more "human-friendly" |
|
495 | + return api_strnatcmp($aval, $bval); |
|
496 | + } else { |
|
497 | + return api_strcasecmp($aval, $bval); |
|
498 | + } |
|
499 | + } |
|
500 | + |
|
501 | + /** |
|
502 | + * A method that sorts the objects in the sentWork array, dependent on the $sort parameter. |
|
503 | + * $sort can be lastDate, firstDate, title, size, ... |
|
504 | + * |
|
505 | + * @param unknown_type $sort |
|
506 | + */ |
|
507 | + function orderSentWork($sort) |
|
508 | 508 | { |
509 | - switch($sort) { |
|
510 | - case 'lastDate': |
|
511 | - $this->_orderBy = 'last_upload_date'; |
|
512 | - break; |
|
513 | - case 'firstDate': |
|
514 | - $this->_orderBy = 'upload_date'; |
|
515 | - break; |
|
516 | - case 'title': |
|
517 | - $this->_orderBy = 'title'; |
|
518 | - break; |
|
519 | - case 'size': |
|
520 | - $this->_orderBy = 'filesize'; |
|
521 | - break; |
|
522 | - case 'author': |
|
523 | - $this->_orderBy = 'author'; |
|
524 | - break; |
|
525 | - case 'recipient': |
|
526 | - $this->_orderBy = 'recipients'; |
|
527 | - break; |
|
528 | - default: |
|
529 | - $this->_orderBy = 'last_upload_date'; |
|
530 | - } |
|
531 | - |
|
532 | - usort($this->sentWork, array($this, '_cmpWork')); |
|
533 | - } |
|
534 | - |
|
535 | - /** |
|
536 | - * method that sorts the objects in the receivedWork array, dependent on the $sort parameter. |
|
537 | - * $sort can be lastDate, firstDate, title, size, ... |
|
538 | - * @param unknown_type $sort |
|
539 | - */ |
|
540 | - function orderReceivedWork($sort) |
|
509 | + switch($sort) { |
|
510 | + case 'lastDate': |
|
511 | + $this->_orderBy = 'last_upload_date'; |
|
512 | + break; |
|
513 | + case 'firstDate': |
|
514 | + $this->_orderBy = 'upload_date'; |
|
515 | + break; |
|
516 | + case 'title': |
|
517 | + $this->_orderBy = 'title'; |
|
518 | + break; |
|
519 | + case 'size': |
|
520 | + $this->_orderBy = 'filesize'; |
|
521 | + break; |
|
522 | + case 'author': |
|
523 | + $this->_orderBy = 'author'; |
|
524 | + break; |
|
525 | + case 'recipient': |
|
526 | + $this->_orderBy = 'recipients'; |
|
527 | + break; |
|
528 | + default: |
|
529 | + $this->_orderBy = 'last_upload_date'; |
|
530 | + } |
|
531 | + |
|
532 | + usort($this->sentWork, array($this, '_cmpWork')); |
|
533 | + } |
|
534 | + |
|
535 | + /** |
|
536 | + * method that sorts the objects in the receivedWork array, dependent on the $sort parameter. |
|
537 | + * $sort can be lastDate, firstDate, title, size, ... |
|
538 | + * @param unknown_type $sort |
|
539 | + */ |
|
540 | + function orderReceivedWork($sort) |
|
541 | 541 | { |
542 | - switch($sort) { |
|
543 | - case 'lastDate': |
|
544 | - $this->_orderBy = 'last_upload_date'; |
|
545 | - break; |
|
546 | - case 'firstDate': |
|
547 | - $this->_orderBy = 'upload_date'; |
|
548 | - break; |
|
549 | - case 'title': |
|
550 | - $this->_orderBy = 'title'; |
|
551 | - break; |
|
552 | - case 'size': |
|
553 | - $this->_orderBy = 'filesize'; |
|
554 | - break; |
|
555 | - case 'author': |
|
556 | - $this->_orderBy = 'author'; |
|
557 | - break; |
|
558 | - case 'sender': |
|
559 | - $this->_orderBy = 'uploaderName'; |
|
560 | - break; |
|
561 | - default: |
|
562 | - $this->_orderBy = 'last_upload_date'; |
|
563 | - } |
|
564 | - |
|
565 | - usort($this->receivedWork, array($this, '_cmpWork')); |
|
566 | - } |
|
567 | - |
|
568 | - /** |
|
569 | - * Deletes all the received work of this person |
|
570 | - */ |
|
571 | - function deleteAllReceivedWork() |
|
542 | + switch($sort) { |
|
543 | + case 'lastDate': |
|
544 | + $this->_orderBy = 'last_upload_date'; |
|
545 | + break; |
|
546 | + case 'firstDate': |
|
547 | + $this->_orderBy = 'upload_date'; |
|
548 | + break; |
|
549 | + case 'title': |
|
550 | + $this->_orderBy = 'title'; |
|
551 | + break; |
|
552 | + case 'size': |
|
553 | + $this->_orderBy = 'filesize'; |
|
554 | + break; |
|
555 | + case 'author': |
|
556 | + $this->_orderBy = 'author'; |
|
557 | + break; |
|
558 | + case 'sender': |
|
559 | + $this->_orderBy = 'uploaderName'; |
|
560 | + break; |
|
561 | + default: |
|
562 | + $this->_orderBy = 'last_upload_date'; |
|
563 | + } |
|
564 | + |
|
565 | + usort($this->receivedWork, array($this, '_cmpWork')); |
|
566 | + } |
|
567 | + |
|
568 | + /** |
|
569 | + * Deletes all the received work of this person |
|
570 | + */ |
|
571 | + function deleteAllReceivedWork() |
|
572 | 572 | { |
573 | - $course_id = api_get_course_int_id(); |
|
573 | + $course_id = api_get_course_int_id(); |
|
574 | 574 | $dropbox_cnf = getDropboxConf(); |
575 | - // Delete entries in person table concerning received works |
|
576 | - foreach ($this->receivedWork as $w) { |
|
575 | + // Delete entries in person table concerning received works |
|
576 | + foreach ($this->receivedWork as $w) { |
|
577 | 577 | $sql = "DELETE FROM ".$dropbox_cnf['tbl_person']." |
578 | 578 | WHERE c_id = $course_id AND user_id='".$this->userId."' AND file_id='".$w->id."'"; |
579 | - Database::query($sql); |
|
580 | - } |
|
579 | + Database::query($sql); |
|
580 | + } |
|
581 | 581 | // Check for unused files |
582 | - removeUnusedFiles(); |
|
583 | - } |
|
582 | + removeUnusedFiles(); |
|
583 | + } |
|
584 | 584 | |
585 | - /** |
|
586 | - * Deletes all the received categories and work of this person |
|
587 | - */ |
|
588 | - function deleteReceivedWorkFolder($id) |
|
585 | + /** |
|
586 | + * Deletes all the received categories and work of this person |
|
587 | + */ |
|
588 | + function deleteReceivedWorkFolder($id) |
|
589 | 589 | { |
590 | 590 | $dropbox_cnf = getDropboxConf(); |
591 | 591 | $course_id = api_get_course_int_id(); |
592 | 592 | |
593 | - $id = intval($id); |
|
594 | - $sql = "DELETE FROM ".$dropbox_cnf['tbl_file']." |
|
593 | + $id = intval($id); |
|
594 | + $sql = "DELETE FROM ".$dropbox_cnf['tbl_file']." |
|
595 | 595 | WHERE c_id = $course_id AND cat_id = '".$id."' "; |
596 | - if (!Database::query($sql)) return false; |
|
597 | - $sql = "DELETE FROM ".$dropbox_cnf['tbl_category']." |
|
596 | + if (!Database::query($sql)) return false; |
|
597 | + $sql = "DELETE FROM ".$dropbox_cnf['tbl_category']." |
|
598 | 598 | WHERE c_id = $course_id AND cat_id = '".$id."' "; |
599 | - if (!Database::query($sql)) return false; |
|
600 | - $sql = "DELETE FROM ".$dropbox_cnf['tbl_post']." |
|
599 | + if (!Database::query($sql)) return false; |
|
600 | + $sql = "DELETE FROM ".$dropbox_cnf['tbl_post']." |
|
601 | 601 | WHERE c_id = $course_id AND cat_id = '".$id."' "; |
602 | - if (!Database::query($sql)) return false; |
|
603 | - return true; |
|
604 | - } |
|
605 | - |
|
606 | - /** |
|
607 | - * Deletes a received dropbox file of this person with id=$id |
|
608 | - * |
|
609 | - * @param integer $id |
|
610 | - */ |
|
611 | - function deleteReceivedWork($id) |
|
602 | + if (!Database::query($sql)) return false; |
|
603 | + return true; |
|
604 | + } |
|
605 | + |
|
606 | + /** |
|
607 | + * Deletes a received dropbox file of this person with id=$id |
|
608 | + * |
|
609 | + * @param integer $id |
|
610 | + */ |
|
611 | + function deleteReceivedWork($id) |
|
612 | 612 | { |
613 | - $course_id = api_get_course_int_id(); |
|
613 | + $course_id = api_get_course_int_id(); |
|
614 | 614 | $dropbox_cnf = getDropboxConf(); |
615 | - $id = intval($id); |
|
616 | - |
|
617 | - // index check |
|
618 | - $found = false; |
|
619 | - foreach ($this->receivedWork as $w) { |
|
620 | - if ($w->id == $id) { |
|
621 | - $found = true; |
|
622 | - break; |
|
623 | - } |
|
624 | - } |
|
625 | - |
|
626 | - if (!$found) { |
|
627 | - if (!$this->deleteReceivedWorkFolder($id)) { |
|
628 | - die(get_lang('GeneralError').' (code 216)'); |
|
629 | - } |
|
630 | - } |
|
631 | - // Delete entries in person table concerning received works |
|
615 | + $id = intval($id); |
|
616 | + |
|
617 | + // index check |
|
618 | + $found = false; |
|
619 | + foreach ($this->receivedWork as $w) { |
|
620 | + if ($w->id == $id) { |
|
621 | + $found = true; |
|
622 | + break; |
|
623 | + } |
|
624 | + } |
|
625 | + |
|
626 | + if (!$found) { |
|
627 | + if (!$this->deleteReceivedWorkFolder($id)) { |
|
628 | + die(get_lang('GeneralError').' (code 216)'); |
|
629 | + } |
|
630 | + } |
|
631 | + // Delete entries in person table concerning received works |
|
632 | 632 | $sql = "DELETE FROM ".$dropbox_cnf['tbl_person']." |
633 | 633 | WHERE c_id = $course_id AND user_id = '".$this->userId."' AND file_id ='".$id."'"; |
634 | - Database::query($sql); |
|
635 | - removeUnusedFiles(); // Check for unused files |
|
636 | - } |
|
637 | - |
|
638 | - /** |
|
639 | - * Deletes all the sent dropbox files of this person |
|
640 | - */ |
|
641 | - function deleteAllSentWork() |
|
634 | + Database::query($sql); |
|
635 | + removeUnusedFiles(); // Check for unused files |
|
636 | + } |
|
637 | + |
|
638 | + /** |
|
639 | + * Deletes all the sent dropbox files of this person |
|
640 | + */ |
|
641 | + function deleteAllSentWork() |
|
642 | 642 | { |
643 | - $course_id = api_get_course_int_id(); |
|
643 | + $course_id = api_get_course_int_id(); |
|
644 | 644 | $dropbox_cnf = getDropboxConf(); |
645 | - //delete entries in person table concerning sent works |
|
646 | - foreach ($this->sentWork as $w) { |
|
645 | + //delete entries in person table concerning sent works |
|
646 | + foreach ($this->sentWork as $w) { |
|
647 | 647 | $sql = "DELETE FROM ".$dropbox_cnf['tbl_person']." |
648 | 648 | WHERE c_id = $course_id AND user_id='".$this->userId."' AND file_id='".$w->id."'"; |
649 | - Database::query($sql); |
|
650 | - removeMoreIfMailing($w->id); |
|
651 | - } |
|
652 | - removeUnusedFiles(); // Check for unused files |
|
653 | - } |
|
654 | - |
|
655 | - /** |
|
656 | - * Deletes a sent dropbox file of this person with id=$id |
|
657 | - * |
|
658 | - * @param unknown_type $id |
|
659 | - */ |
|
660 | - function deleteSentWork($id) |
|
649 | + Database::query($sql); |
|
650 | + removeMoreIfMailing($w->id); |
|
651 | + } |
|
652 | + removeUnusedFiles(); // Check for unused files |
|
653 | + } |
|
654 | + |
|
655 | + /** |
|
656 | + * Deletes a sent dropbox file of this person with id=$id |
|
657 | + * |
|
658 | + * @param unknown_type $id |
|
659 | + */ |
|
660 | + function deleteSentWork($id) |
|
661 | 661 | { |
662 | - $course_id = api_get_course_int_id(); |
|
662 | + $course_id = api_get_course_int_id(); |
|
663 | 663 | $dropbox_cnf = getDropboxConf(); |
664 | 664 | |
665 | - $id = intval($id); |
|
666 | - |
|
667 | - // index check |
|
668 | - $found = false; |
|
669 | - foreach ($this->sentWork as $w) { |
|
670 | - if ($w->id == $id) { |
|
671 | - $found = true; |
|
672 | - break; |
|
673 | - } |
|
674 | - } |
|
675 | - if (!$found) { |
|
676 | - if (!$this->deleteReceivedWorkFolder($id)) { |
|
677 | - die(get_lang('GeneralError').' (code 219)'); |
|
678 | - } |
|
679 | - } |
|
680 | - //$file_id = $this->sentWork[$index]->id; |
|
681 | - // Delete entries in person table concerning sent works |
|
665 | + $id = intval($id); |
|
666 | + |
|
667 | + // index check |
|
668 | + $found = false; |
|
669 | + foreach ($this->sentWork as $w) { |
|
670 | + if ($w->id == $id) { |
|
671 | + $found = true; |
|
672 | + break; |
|
673 | + } |
|
674 | + } |
|
675 | + if (!$found) { |
|
676 | + if (!$this->deleteReceivedWorkFolder($id)) { |
|
677 | + die(get_lang('GeneralError').' (code 219)'); |
|
678 | + } |
|
679 | + } |
|
680 | + //$file_id = $this->sentWork[$index]->id; |
|
681 | + // Delete entries in person table concerning sent works |
|
682 | 682 | $sql = "DELETE FROM ".$dropbox_cnf['tbl_person']." |
683 | 683 | WHERE c_id = $course_id AND user_id='".$this->userId."' AND file_id='".$id."'"; |
684 | - Database::query($sql); |
|
685 | - removeMoreIfMailing($id); |
|
686 | - removeUnusedFiles(); // Check for unused files |
|
687 | - } |
|
688 | - |
|
689 | - /** |
|
690 | - * Updates feedback for received work of this person with id=$id |
|
691 | - * |
|
692 | - * @param string $id |
|
693 | - * @param string $text |
|
694 | - */ |
|
695 | - function updateFeedback($id, $text) |
|
684 | + Database::query($sql); |
|
685 | + removeMoreIfMailing($id); |
|
686 | + removeUnusedFiles(); // Check for unused files |
|
687 | + } |
|
688 | + |
|
689 | + /** |
|
690 | + * Updates feedback for received work of this person with id=$id |
|
691 | + * |
|
692 | + * @param string $id |
|
693 | + * @param string $text |
|
694 | + */ |
|
695 | + function updateFeedback($id, $text) |
|
696 | 696 | { |
697 | - $course_id = api_get_course_int_id(); |
|
697 | + $course_id = api_get_course_int_id(); |
|
698 | 698 | $_course = api_get_course_info(); |
699 | 699 | $dropbox_cnf = getDropboxConf(); |
700 | 700 | |
701 | - $id = intval($id); |
|
702 | - |
|
703 | - // index check |
|
704 | - $found = false; |
|
705 | - $wi = -1; |
|
706 | - foreach ($this->receivedWork as $w) { |
|
707 | - $wi++; |
|
708 | - if ($w->id == $id){ |
|
709 | - $found = true; |
|
710 | - break; |
|
711 | - } // foreach (... as $wi -> $w) gives error 221! (no idea why...) |
|
712 | - } |
|
713 | - if (!$found) { |
|
714 | - die(get_lang('GeneralError').' (code 221)'); |
|
715 | - } |
|
716 | - |
|
717 | - $feedback_date = api_get_utc_datetime(); |
|
718 | - $this->receivedWork[$wi]->feedback_date = $feedback_date; |
|
719 | - $this->receivedWork[$wi]->feedback = $text; |
|
701 | + $id = intval($id); |
|
702 | + |
|
703 | + // index check |
|
704 | + $found = false; |
|
705 | + $wi = -1; |
|
706 | + foreach ($this->receivedWork as $w) { |
|
707 | + $wi++; |
|
708 | + if ($w->id == $id){ |
|
709 | + $found = true; |
|
710 | + break; |
|
711 | + } // foreach (... as $wi -> $w) gives error 221! (no idea why...) |
|
712 | + } |
|
713 | + if (!$found) { |
|
714 | + die(get_lang('GeneralError').' (code 221)'); |
|
715 | + } |
|
716 | + |
|
717 | + $feedback_date = api_get_utc_datetime(); |
|
718 | + $this->receivedWork[$wi]->feedback_date = $feedback_date; |
|
719 | + $this->receivedWork[$wi]->feedback = $text; |
|
720 | 720 | |
721 | 721 | $params = [ |
722 | 722 | 'feedback_date' => $feedback_date, |
@@ -734,11 +734,11 @@ discard block |
||
734 | 734 | ] |
735 | 735 | ); |
736 | 736 | |
737 | - // Update item_property table |
|
737 | + // Update item_property table |
|
738 | 738 | |
739 | - if (($ownerid = $this->receivedWork[$wi]->uploader_id) > $dropbox_cnf['mailingIdBase']) { |
|
740 | - $ownerid = getUserOwningThisMailing($ownerid); |
|
741 | - } |
|
739 | + if (($ownerid = $this->receivedWork[$wi]->uploader_id) > $dropbox_cnf['mailingIdBase']) { |
|
740 | + $ownerid = getUserOwningThisMailing($ownerid); |
|
741 | + } |
|
742 | 742 | api_item_property_update( |
743 | 743 | $_course, |
744 | 744 | TOOL_DROPBOX, |
@@ -749,31 +749,31 @@ discard block |
||
749 | 749 | $ownerid |
750 | 750 | ); |
751 | 751 | |
752 | - } |
|
752 | + } |
|
753 | 753 | |
754 | - /** |
|
755 | - * Filter the received work |
|
756 | - * @param string $type |
|
757 | - * @param string $value |
|
758 | - */ |
|
759 | - function filter_received_work($type, $value) |
|
754 | + /** |
|
755 | + * Filter the received work |
|
756 | + * @param string $type |
|
757 | + * @param string $value |
|
758 | + */ |
|
759 | + function filter_received_work($type, $value) |
|
760 | 760 | { |
761 | 761 | $dropbox_cnf = getDropboxConf(); |
762 | - $new_received_work = array(); |
|
763 | - foreach ($this->receivedWork as $work) { |
|
764 | - switch ($type) { |
|
765 | - case 'uploader_id': |
|
766 | - if ($work->uploader_id == $value || |
|
767 | - ($work->uploader_id > $dropbox_cnf['mailingIdBase'] && |
|
762 | + $new_received_work = array(); |
|
763 | + foreach ($this->receivedWork as $work) { |
|
764 | + switch ($type) { |
|
765 | + case 'uploader_id': |
|
766 | + if ($work->uploader_id == $value || |
|
767 | + ($work->uploader_id > $dropbox_cnf['mailingIdBase'] && |
|
768 | 768 | getUserOwningThisMailing($work->uploader_id) == $value) |
769 | 769 | ) { |
770 | - $new_received_work[] = $work; |
|
771 | - } |
|
772 | - break; |
|
773 | - default: |
|
774 | - $new_received_work[] = $work; |
|
775 | - } |
|
776 | - } |
|
777 | - $this->receivedWork = $new_received_work; |
|
778 | - } |
|
770 | + $new_received_work[] = $work; |
|
771 | + } |
|
772 | + break; |
|
773 | + default: |
|
774 | + $new_received_work[] = $work; |
|
775 | + } |
|
776 | + } |
|
777 | + $this->receivedWork = $new_received_work; |
|
778 | + } |
|
779 | 779 | } |
@@ -186,6 +186,7 @@ discard block |
||
186 | 186 | * Reads answer information from the data base ordered by parameter |
187 | 187 | * @param string Field we want to order by |
188 | 188 | * @param string DESC or ASC |
189 | + * @param string $field |
|
189 | 190 | * @author Frederic Vauthier |
190 | 191 | */ |
191 | 192 | public function readOrderedBy($field, $order='ASC') |
@@ -300,6 +301,7 @@ discard block |
||
300 | 301 | * returns the question ID of the destination question |
301 | 302 | * |
302 | 303 | * @author Julio Montoya |
304 | + * @param integer $id |
|
303 | 305 | * @return integer - the question ID |
304 | 306 | */ |
305 | 307 | public function selectDestination($id) |
@@ -321,6 +323,7 @@ discard block |
||
321 | 323 | |
322 | 324 | /** |
323 | 325 | * return array answer by id else return a bool |
326 | + * @param integer $auto_id |
|
324 | 327 | */ |
325 | 328 | public function selectAnswerByAutoId($auto_id) |
326 | 329 | { |
@@ -435,6 +438,7 @@ discard block |
||
435 | 438 | * |
436 | 439 | * @author Olivier Brouckaert |
437 | 440 | * @param - integer $id - answer ID |
441 | + * @param integer $id |
|
438 | 442 | * @return integer - 0 if bad answer, not 0 if good answer |
439 | 443 | */ |
440 | 444 | public function isCorrect($id) |
@@ -447,6 +451,7 @@ discard block |
||
447 | 451 | * |
448 | 452 | * @author Olivier Brouckaert |
449 | 453 | * @param - integer $id - answer ID |
454 | + * @param integer $id |
|
450 | 455 | * @return string - answer comment |
451 | 456 | */ |
452 | 457 | public function selectComment($id) |
@@ -459,6 +464,7 @@ discard block |
||
459 | 464 | * |
460 | 465 | * @author Olivier Brouckaert |
461 | 466 | * @param - integer $id - answer ID |
467 | + * @param integer $id |
|
462 | 468 | * @return integer - answer weighting |
463 | 469 | */ |
464 | 470 | public function selectWeighting($id) |
@@ -483,6 +489,7 @@ discard block |
||
483 | 489 | * |
484 | 490 | * @author Olivier Brouckaert |
485 | 491 | * @param integer Answer ID |
492 | + * @param integer $id |
|
486 | 493 | * @return integer Answer position |
487 | 494 | */ |
488 | 495 | public function selectHotspotCoordinates($id) |
@@ -495,6 +502,7 @@ discard block |
||
495 | 502 | * |
496 | 503 | * @author Toon Keppens |
497 | 504 | * @param integer Answer ID |
505 | + * @param integer $id |
|
498 | 506 | * @return integer Answer position |
499 | 507 | */ |
500 | 508 | public function selectHotspotType($id) |
@@ -550,6 +558,7 @@ discard block |
||
550 | 558 | * @param string $destination |
551 | 559 | * @param string $hotspot_coordinates |
552 | 560 | * @param string $hotspot_type |
561 | + * @param integer $autoId |
|
553 | 562 | */ |
554 | 563 | public function updateAnswers( |
555 | 564 | $autoId, |
@@ -720,6 +729,7 @@ discard block |
||
720 | 729 | * @author Olivier Brouckaert |
721 | 730 | * @param int question id |
722 | 731 | * @param array destination course info (result of the function api_get_course_info() ) |
732 | + * @param string $newQuestionId |
|
723 | 733 | */ |
724 | 734 | public function duplicate($newQuestionId, $course_info = null) |
725 | 735 | { |
@@ -155,12 +155,12 @@ discard block |
||
155 | 155 | return []; |
156 | 156 | } |
157 | 157 | |
158 | - /** |
|
159 | - * returns all answer ids from this question Id |
|
160 | - * |
|
161 | - * @author Yoselyn Castillo |
|
162 | - * @return array - $id (answer ids) |
|
163 | - */ |
|
158 | + /** |
|
159 | + * returns all answer ids from this question Id |
|
160 | + * |
|
161 | + * @author Yoselyn Castillo |
|
162 | + * @return array - $id (answer ids) |
|
163 | + */ |
|
164 | 164 | public function selectAnswerId() |
165 | 165 | { |
166 | 166 | $TBL_ANSWER = Database::get_course_table(TABLE_QUIZ_ANSWER); |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | } |
181 | 181 | |
182 | 182 | return $id; |
183 | - } |
|
183 | + } |
|
184 | 184 | |
185 | 185 | /** |
186 | 186 | * Reads answer information from the data base ordered by parameter |
@@ -190,23 +190,23 @@ discard block |
||
190 | 190 | */ |
191 | 191 | public function readOrderedBy($field, $order='ASC') |
192 | 192 | { |
193 | - $field = Database::escape_string($field); |
|
194 | - if (empty($field)) { |
|
195 | - $field = 'position'; |
|
196 | - } |
|
193 | + $field = Database::escape_string($field); |
|
194 | + if (empty($field)) { |
|
195 | + $field = 'position'; |
|
196 | + } |
|
197 | 197 | |
198 | - if ($order != 'ASC' && $order!='DESC') { |
|
199 | - $order = 'ASC'; |
|
200 | - } |
|
198 | + if ($order != 'ASC' && $order!='DESC') { |
|
199 | + $order = 'ASC'; |
|
200 | + } |
|
201 | 201 | |
202 | - $TBL_ANSWER = Database::get_course_table(TABLE_QUIZ_ANSWER); |
|
203 | - $TBL_QUIZ = Database::get_course_table(TABLE_QUIZ_QUESTION); |
|
204 | - $questionId = intval($this->questionId); |
|
202 | + $TBL_ANSWER = Database::get_course_table(TABLE_QUIZ_ANSWER); |
|
203 | + $TBL_QUIZ = Database::get_course_table(TABLE_QUIZ_QUESTION); |
|
204 | + $questionId = intval($this->questionId); |
|
205 | 205 | |
206 | - $sql = "SELECT type FROM $TBL_QUIZ |
|
206 | + $sql = "SELECT type FROM $TBL_QUIZ |
|
207 | 207 | WHERE c_id = {$this->course_id} AND id = $questionId"; |
208 | - $result_question = Database::query($sql); |
|
209 | - $questionType = Database::fetch_array($result_question); |
|
208 | + $result_question = Database::query($sql); |
|
209 | + $questionType = Database::fetch_array($result_question); |
|
210 | 210 | |
211 | 211 | if ($questionType['type'] == DRAGGABLE) { |
212 | 212 | // Random is done by submit.js.tpl |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | return true; |
216 | 216 | } |
217 | 217 | |
218 | - $sql = "SELECT |
|
218 | + $sql = "SELECT |
|
219 | 219 | answer, |
220 | 220 | correct, |
221 | 221 | comment, |
@@ -230,16 +230,16 @@ discard block |
||
230 | 230 | c_id = {$this->course_id} AND |
231 | 231 | question_id='".$questionId."' |
232 | 232 | ORDER BY $field $order"; |
233 | - $result=Database::query($sql); |
|
234 | - |
|
235 | - $i = 1; |
|
236 | - // while a record is found |
|
237 | - $doubt_data = null; |
|
238 | - while ($object = Database::fetch_object($result)) { |
|
239 | - if ($questionType['type'] == UNIQUE_ANSWER_NO_OPTION && $object->position == 666) { |
|
240 | - $doubt_data = $object; |
|
233 | + $result=Database::query($sql); |
|
234 | + |
|
235 | + $i = 1; |
|
236 | + // while a record is found |
|
237 | + $doubt_data = null; |
|
238 | + while ($object = Database::fetch_object($result)) { |
|
239 | + if ($questionType['type'] == UNIQUE_ANSWER_NO_OPTION && $object->position == 666) { |
|
240 | + $doubt_data = $object; |
|
241 | 241 | continue; |
242 | - } |
|
242 | + } |
|
243 | 243 | $this->answer[$i] = $object->answer; |
244 | 244 | $this->correct[$i] = $object->correct; |
245 | 245 | $this->comment[$i] = $object->comment; |
@@ -248,9 +248,9 @@ discard block |
||
248 | 248 | $this->destination[$i] = $object->destination; |
249 | 249 | $this->autoId[$i] = $object->id_auto; |
250 | 250 | $i++; |
251 | - } |
|
251 | + } |
|
252 | 252 | |
253 | - if ($questionType['type'] == UNIQUE_ANSWER_NO_OPTION && !empty($doubt_data)) { |
|
253 | + if ($questionType['type'] == UNIQUE_ANSWER_NO_OPTION && !empty($doubt_data)) { |
|
254 | 254 | $this->answer[$i] = $doubt_data->answer; |
255 | 255 | $this->correct[$i] = $doubt_data->correct; |
256 | 256 | $this->comment[$i] = $doubt_data->comment; |
@@ -259,86 +259,86 @@ discard block |
||
259 | 259 | $this->destination[$i] = $doubt_data->destination; |
260 | 260 | $this->autoId[$i] = $doubt_data->id_auto; |
261 | 261 | $i++; |
262 | - } |
|
262 | + } |
|
263 | 263 | $this->nbrAnswers = $i-1; |
264 | - } |
|
265 | - |
|
266 | - /** |
|
267 | - * returns the autoincrement id identificator |
|
268 | - * |
|
269 | - * @author Juan Carlos Ra�a |
|
270 | - * @return integer - answer num |
|
271 | - */ |
|
264 | + } |
|
265 | + |
|
266 | + /** |
|
267 | + * returns the autoincrement id identificator |
|
268 | + * |
|
269 | + * @author Juan Carlos Ra�a |
|
270 | + * @return integer - answer num |
|
271 | + */ |
|
272 | 272 | public function selectAutoId($id) |
273 | 273 | { |
274 | - return isset($this->autoId[$id]) ? $this->autoId[$id] : null; |
|
275 | - } |
|
276 | - |
|
277 | - /** |
|
278 | - * returns the number of answers in this question |
|
279 | - * |
|
280 | - * @author Olivier Brouckaert |
|
281 | - * @return integer - number of answers |
|
282 | - */ |
|
283 | - public function selectNbrAnswers() |
|
274 | + return isset($this->autoId[$id]) ? $this->autoId[$id] : null; |
|
275 | + } |
|
276 | + |
|
277 | + /** |
|
278 | + * returns the number of answers in this question |
|
279 | + * |
|
280 | + * @author Olivier Brouckaert |
|
281 | + * @return integer - number of answers |
|
282 | + */ |
|
283 | + public function selectNbrAnswers() |
|
284 | 284 | { |
285 | - return $this->nbrAnswers; |
|
286 | - } |
|
287 | - |
|
288 | - /** |
|
289 | - * returns the question ID which the answers belong to |
|
290 | - * |
|
291 | - * @author Olivier Brouckaert |
|
292 | - * @return integer - the question ID |
|
293 | - */ |
|
294 | - public function selectQuestionId() |
|
285 | + return $this->nbrAnswers; |
|
286 | + } |
|
287 | + |
|
288 | + /** |
|
289 | + * returns the question ID which the answers belong to |
|
290 | + * |
|
291 | + * @author Olivier Brouckaert |
|
292 | + * @return integer - the question ID |
|
293 | + */ |
|
294 | + public function selectQuestionId() |
|
295 | 295 | { |
296 | - return $this->questionId; |
|
297 | - } |
|
298 | - |
|
299 | - /** |
|
300 | - * returns the question ID of the destination question |
|
301 | - * |
|
302 | - * @author Julio Montoya |
|
303 | - * @return integer - the question ID |
|
304 | - */ |
|
305 | - public function selectDestination($id) |
|
296 | + return $this->questionId; |
|
297 | + } |
|
298 | + |
|
299 | + /** |
|
300 | + * returns the question ID of the destination question |
|
301 | + * |
|
302 | + * @author Julio Montoya |
|
303 | + * @return integer - the question ID |
|
304 | + */ |
|
305 | + public function selectDestination($id) |
|
306 | 306 | { |
307 | - return isset($this->destination[$id]) ? $this->destination[$id] : null; |
|
308 | - } |
|
307 | + return isset($this->destination[$id]) ? $this->destination[$id] : null; |
|
308 | + } |
|
309 | 309 | |
310 | 310 | /** |
311 | - * returns the answer title |
|
312 | - * |
|
313 | - * @author Olivier Brouckaert |
|
314 | - * @param - integer $id - answer ID |
|
315 | - * @return string - answer title |
|
316 | - */ |
|
317 | - public function selectAnswer($id) |
|
318 | - { |
|
319 | - return isset($this->answer[$id]) ? $this->answer[$id] : null; |
|
320 | - } |
|
321 | - |
|
322 | - /** |
|
323 | - * return array answer by id else return a bool |
|
324 | - */ |
|
325 | - public function selectAnswerByAutoId($auto_id) |
|
326 | - { |
|
327 | - $TBL_ANSWER = Database::get_course_table(TABLE_QUIZ_ANSWER); |
|
328 | - |
|
329 | - $auto_id = intval($auto_id); |
|
330 | - $sql = "SELECT id, answer, id_auto FROM $TBL_ANSWER |
|
311 | + * returns the answer title |
|
312 | + * |
|
313 | + * @author Olivier Brouckaert |
|
314 | + * @param - integer $id - answer ID |
|
315 | + * @return string - answer title |
|
316 | + */ |
|
317 | + public function selectAnswer($id) |
|
318 | + { |
|
319 | + return isset($this->answer[$id]) ? $this->answer[$id] : null; |
|
320 | + } |
|
321 | + |
|
322 | + /** |
|
323 | + * return array answer by id else return a bool |
|
324 | + */ |
|
325 | + public function selectAnswerByAutoId($auto_id) |
|
326 | + { |
|
327 | + $TBL_ANSWER = Database::get_course_table(TABLE_QUIZ_ANSWER); |
|
328 | + |
|
329 | + $auto_id = intval($auto_id); |
|
330 | + $sql = "SELECT id, answer, id_auto FROM $TBL_ANSWER |
|
331 | 331 | WHERE c_id = {$this->course_id} AND id_auto='$auto_id'"; |
332 | - $rs = Database::query($sql); |
|
332 | + $rs = Database::query($sql); |
|
333 | 333 | |
334 | - if (Database::num_rows($rs) > 0) { |
|
335 | - $row = Database::fetch_array($rs, 'ASSOC'); |
|
334 | + if (Database::num_rows($rs) > 0) { |
|
335 | + $row = Database::fetch_array($rs, 'ASSOC'); |
|
336 | 336 | |
337 | - return $row; |
|
338 | - } |
|
337 | + return $row; |
|
338 | + } |
|
339 | 339 | |
340 | - return false; |
|
341 | - } |
|
340 | + return false; |
|
341 | + } |
|
342 | 342 | |
343 | 343 | /** |
344 | 344 | * returns the answer title from an answer's position |
@@ -347,18 +347,18 @@ discard block |
||
347 | 347 | * @param - integer $id - answer ID |
348 | 348 | * @return bool - answer title |
349 | 349 | */ |
350 | - public function selectAnswerIdByPosition($pos) |
|
351 | - { |
|
352 | - foreach ($this->position as $k => $v) { |
|
353 | - if ($v != $pos) { |
|
354 | - continue; |
|
355 | - } |
|
350 | + public function selectAnswerIdByPosition($pos) |
|
351 | + { |
|
352 | + foreach ($this->position as $k => $v) { |
|
353 | + if ($v != $pos) { |
|
354 | + continue; |
|
355 | + } |
|
356 | 356 | |
357 | - return $k; |
|
358 | - } |
|
357 | + return $k; |
|
358 | + } |
|
359 | 359 | |
360 | - return false; |
|
361 | - } |
|
360 | + return false; |
|
361 | + } |
|
362 | 362 | |
363 | 363 | /** |
364 | 364 | * Returns a list of answers |
@@ -367,18 +367,18 @@ discard block |
||
367 | 367 | * of (id, answer, comment, grade) and grade=weighting |
368 | 368 | */ |
369 | 369 | public function getAnswersList($decode = false) |
370 | - { |
|
371 | - $list = array(); |
|
372 | - for ($i = 1; $i <= $this->nbrAnswers; $i++) { |
|
373 | - if (!empty($this->answer[$i])) { |
|
374 | - |
|
375 | - //Avoid problems when parsing elements with accents |
|
376 | - if ($decode) { |
|
377 | - $this->answer[$i] = api_html_entity_decode($this->answer[$i], ENT_QUOTES, api_get_system_encoding()); |
|
378 | - $this->comment[$i] = api_html_entity_decode($this->comment[$i], ENT_QUOTES, api_get_system_encoding()); |
|
379 | - } |
|
380 | - |
|
381 | - $list[] = array( |
|
370 | + { |
|
371 | + $list = array(); |
|
372 | + for ($i = 1; $i <= $this->nbrAnswers; $i++) { |
|
373 | + if (!empty($this->answer[$i])) { |
|
374 | + |
|
375 | + //Avoid problems when parsing elements with accents |
|
376 | + if ($decode) { |
|
377 | + $this->answer[$i] = api_html_entity_decode($this->answer[$i], ENT_QUOTES, api_get_system_encoding()); |
|
378 | + $this->comment[$i] = api_html_entity_decode($this->comment[$i], ENT_QUOTES, api_get_system_encoding()); |
|
379 | + } |
|
380 | + |
|
381 | + $list[] = array( |
|
382 | 382 | 'id' => $i, |
383 | 383 | 'answer' => $this->answer[$i], |
384 | 384 | 'comment' => $this->comment[$i], |
@@ -387,134 +387,134 @@ discard block |
||
387 | 387 | 'hotspot_type' => $this->hotspot_type[$i], |
388 | 388 | 'correct' => $this->correct[$i], |
389 | 389 | 'destination' => $this->destination[$i] |
390 | - ); |
|
390 | + ); |
|
391 | + } |
|
391 | 392 | } |
392 | - } |
|
393 | 393 | |
394 | - return $list; |
|
395 | - } |
|
394 | + return $list; |
|
395 | + } |
|
396 | 396 | |
397 | - /** |
|
398 | - * Returns a list of grades |
|
399 | - * @author Yannick Warnier <[email protected]> |
|
400 | - * @return array List of grades where grade=weighting (?) |
|
401 | - */ |
|
397 | + /** |
|
398 | + * Returns a list of grades |
|
399 | + * @author Yannick Warnier <[email protected]> |
|
400 | + * @return array List of grades where grade=weighting (?) |
|
401 | + */ |
|
402 | 402 | public function getGradesList() |
403 | - { |
|
404 | - $list = array(); |
|
405 | - for ($i = 0; $i<$this->nbrAnswers;$i++){ |
|
406 | - if(!empty($this->answer[$i])){ |
|
407 | - $list[$i] = $this->weighting[$i]; |
|
408 | - } |
|
409 | - } |
|
410 | - return $list; |
|
411 | - } |
|
412 | - |
|
413 | - /** |
|
414 | - * Returns the question type |
|
415 | - * @author Yannick Warnier <[email protected]> |
|
416 | - * @return integer The type of the question this answer is bound to |
|
417 | - */ |
|
403 | + { |
|
404 | + $list = array(); |
|
405 | + for ($i = 0; $i<$this->nbrAnswers;$i++){ |
|
406 | + if(!empty($this->answer[$i])){ |
|
407 | + $list[$i] = $this->weighting[$i]; |
|
408 | + } |
|
409 | + } |
|
410 | + return $list; |
|
411 | + } |
|
412 | + |
|
413 | + /** |
|
414 | + * Returns the question type |
|
415 | + * @author Yannick Warnier <[email protected]> |
|
416 | + * @return integer The type of the question this answer is bound to |
|
417 | + */ |
|
418 | 418 | public function getQuestionType() |
419 | - { |
|
420 | - $TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION); |
|
421 | - $sql = "SELECT type FROM $TBL_QUESTIONS |
|
419 | + { |
|
420 | + $TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION); |
|
421 | + $sql = "SELECT type FROM $TBL_QUESTIONS |
|
422 | 422 | WHERE c_id = {$this->course_id} AND id = '".$this->questionId."'"; |
423 | - $res = Database::query($sql); |
|
424 | - if (Database::num_rows($res)<=0){ |
|
425 | - return null; |
|
426 | - } |
|
427 | - $row = Database::fetch_array($res); |
|
428 | - |
|
429 | - return $row['type']; |
|
430 | - } |
|
431 | - |
|
432 | - |
|
433 | - /** |
|
434 | - * tells if answer is correct or not |
|
435 | - * |
|
436 | - * @author Olivier Brouckaert |
|
437 | - * @param - integer $id - answer ID |
|
438 | - * @return integer - 0 if bad answer, not 0 if good answer |
|
439 | - */ |
|
423 | + $res = Database::query($sql); |
|
424 | + if (Database::num_rows($res)<=0){ |
|
425 | + return null; |
|
426 | + } |
|
427 | + $row = Database::fetch_array($res); |
|
428 | + |
|
429 | + return $row['type']; |
|
430 | + } |
|
431 | + |
|
432 | + |
|
433 | + /** |
|
434 | + * tells if answer is correct or not |
|
435 | + * |
|
436 | + * @author Olivier Brouckaert |
|
437 | + * @param - integer $id - answer ID |
|
438 | + * @return integer - 0 if bad answer, not 0 if good answer |
|
439 | + */ |
|
440 | 440 | public function isCorrect($id) |
441 | - { |
|
442 | - return isset($this->correct[$id]) ? $this->correct[$id] : null; |
|
443 | - } |
|
444 | - |
|
445 | - /** |
|
446 | - * returns answer comment |
|
447 | - * |
|
448 | - * @author Olivier Brouckaert |
|
449 | - * @param - integer $id - answer ID |
|
450 | - * @return string - answer comment |
|
451 | - */ |
|
441 | + { |
|
442 | + return isset($this->correct[$id]) ? $this->correct[$id] : null; |
|
443 | + } |
|
444 | + |
|
445 | + /** |
|
446 | + * returns answer comment |
|
447 | + * |
|
448 | + * @author Olivier Brouckaert |
|
449 | + * @param - integer $id - answer ID |
|
450 | + * @return string - answer comment |
|
451 | + */ |
|
452 | 452 | public function selectComment($id) |
453 | - { |
|
453 | + { |
|
454 | 454 | return isset($this->comment[$id]) ? $this->comment[$id] : null; |
455 | - } |
|
456 | - |
|
457 | - /** |
|
458 | - * returns answer weighting |
|
459 | - * |
|
460 | - * @author Olivier Brouckaert |
|
461 | - * @param - integer $id - answer ID |
|
462 | - * @return integer - answer weighting |
|
463 | - */ |
|
455 | + } |
|
456 | + |
|
457 | + /** |
|
458 | + * returns answer weighting |
|
459 | + * |
|
460 | + * @author Olivier Brouckaert |
|
461 | + * @param - integer $id - answer ID |
|
462 | + * @return integer - answer weighting |
|
463 | + */ |
|
464 | 464 | public function selectWeighting($id) |
465 | - { |
|
466 | - return isset($this->weighting[$id]) ? $this->weighting[$id] : null; |
|
467 | - } |
|
468 | - |
|
469 | - /** |
|
470 | - * returns answer position |
|
471 | - * |
|
472 | - * @author Olivier Brouckaert |
|
473 | - * @param - integer $id - answer ID |
|
474 | - * @return integer - answer position |
|
475 | - */ |
|
476 | - function selectPosition($id) |
|
477 | - { |
|
478 | - return isset($this->position[$id]) ? $this->position[$id] : null; |
|
479 | - } |
|
480 | - |
|
481 | - /** |
|
482 | - * returns answer hotspot coordinates |
|
483 | - * |
|
484 | - * @author Olivier Brouckaert |
|
485 | - * @param integer Answer ID |
|
486 | - * @return integer Answer position |
|
487 | - */ |
|
465 | + { |
|
466 | + return isset($this->weighting[$id]) ? $this->weighting[$id] : null; |
|
467 | + } |
|
468 | + |
|
469 | + /** |
|
470 | + * returns answer position |
|
471 | + * |
|
472 | + * @author Olivier Brouckaert |
|
473 | + * @param - integer $id - answer ID |
|
474 | + * @return integer - answer position |
|
475 | + */ |
|
476 | + function selectPosition($id) |
|
477 | + { |
|
478 | + return isset($this->position[$id]) ? $this->position[$id] : null; |
|
479 | + } |
|
480 | + |
|
481 | + /** |
|
482 | + * returns answer hotspot coordinates |
|
483 | + * |
|
484 | + * @author Olivier Brouckaert |
|
485 | + * @param integer Answer ID |
|
486 | + * @return integer Answer position |
|
487 | + */ |
|
488 | 488 | public function selectHotspotCoordinates($id) |
489 | - { |
|
490 | - return isset($this->hotspot_coordinates[$id]) ? $this->hotspot_coordinates[$id] : null; |
|
491 | - } |
|
492 | - |
|
493 | - /** |
|
494 | - * returns answer hotspot type |
|
495 | - * |
|
496 | - * @author Toon Keppens |
|
497 | - * @param integer Answer ID |
|
498 | - * @return integer Answer position |
|
499 | - */ |
|
489 | + { |
|
490 | + return isset($this->hotspot_coordinates[$id]) ? $this->hotspot_coordinates[$id] : null; |
|
491 | + } |
|
492 | + |
|
493 | + /** |
|
494 | + * returns answer hotspot type |
|
495 | + * |
|
496 | + * @author Toon Keppens |
|
497 | + * @param integer Answer ID |
|
498 | + * @return integer Answer position |
|
499 | + */ |
|
500 | 500 | public function selectHotspotType($id) |
501 | - { |
|
502 | - return isset($this->hotspot_type[$id]) ? $this->hotspot_type[$id] : null; |
|
503 | - } |
|
504 | - |
|
505 | - /** |
|
506 | - * Creates a new answer |
|
507 | - * |
|
508 | - * @author Olivier Brouckaert |
|
509 | - * @param string $answer answer title |
|
510 | - * @param integer $correct 0 if bad answer, not 0 if good answer |
|
511 | - * @param string $comment answer comment |
|
512 | - * @param integer $weighting answer weighting |
|
513 | - * @param integer $position answer position |
|
514 | - * @param array $new_hotspot_coordinates Coordinates for hotspot exercises (optional) |
|
515 | - * @param integer $new_hotspot_type Type for hotspot exercises (optional) |
|
501 | + { |
|
502 | + return isset($this->hotspot_type[$id]) ? $this->hotspot_type[$id] : null; |
|
503 | + } |
|
504 | + |
|
505 | + /** |
|
506 | + * Creates a new answer |
|
507 | + * |
|
508 | + * @author Olivier Brouckaert |
|
509 | + * @param string $answer answer title |
|
510 | + * @param integer $correct 0 if bad answer, not 0 if good answer |
|
511 | + * @param string $comment answer comment |
|
512 | + * @param integer $weighting answer weighting |
|
513 | + * @param integer $position answer position |
|
514 | + * @param array $new_hotspot_coordinates Coordinates for hotspot exercises (optional) |
|
515 | + * @param integer $new_hotspot_type Type for hotspot exercises (optional) |
|
516 | 516 | * @param string $destination |
517 | - */ |
|
517 | + */ |
|
518 | 518 | public function createAnswer( |
519 | 519 | $answer, |
520 | 520 | $correct, |
@@ -525,7 +525,7 @@ discard block |
||
525 | 525 | $new_hotspot_type = null, |
526 | 526 | $destination = '' |
527 | 527 | ) { |
528 | - $this->new_nbrAnswers++; |
|
528 | + $this->new_nbrAnswers++; |
|
529 | 529 | $id = $this->new_nbrAnswers; |
530 | 530 | $this->new_answer[$id] = $answer; |
531 | 531 | $this->new_correct[$id] = $correct; |
@@ -535,7 +535,7 @@ discard block |
||
535 | 535 | $this->new_hotspot_coordinates[$id] = $new_hotspot_coordinates; |
536 | 536 | $this->new_hotspot_type[$id] = $new_hotspot_type; |
537 | 537 | $this->new_destination[$id] = $destination; |
538 | - } |
|
538 | + } |
|
539 | 539 | |
540 | 540 | /** |
541 | 541 | * Updates an answer |
@@ -577,31 +577,31 @@ discard block |
||
577 | 577 | ]; |
578 | 578 | |
579 | 579 | Database::update($answerTable, $params, ['id_auto = ?' => $autoId]); |
580 | - } |
|
580 | + } |
|
581 | 581 | |
582 | - /** |
|
583 | - * Records answers into the data base |
|
584 | - * |
|
585 | - * @author Olivier Brouckaert |
|
586 | - */ |
|
582 | + /** |
|
583 | + * Records answers into the data base |
|
584 | + * |
|
585 | + * @author Olivier Brouckaert |
|
586 | + */ |
|
587 | 587 | public function save() |
588 | 588 | { |
589 | - $answerTable = Database::get_course_table(TABLE_QUIZ_ANSWER); |
|
590 | - $questionId = intval($this->questionId); |
|
589 | + $answerTable = Database::get_course_table(TABLE_QUIZ_ANSWER); |
|
590 | + $questionId = intval($this->questionId); |
|
591 | 591 | |
592 | - $c_id = $this->course['real_id']; |
|
592 | + $c_id = $this->course['real_id']; |
|
593 | 593 | $correctList = []; |
594 | 594 | $answerList = []; |
595 | 595 | |
596 | - for ($i=1; $i <= $this->new_nbrAnswers; $i++) { |
|
597 | - $answer = $this->new_answer[$i]; |
|
598 | - $correct = $this->new_correct[$i]; |
|
599 | - $comment = $this->new_comment[$i]; |
|
600 | - $weighting = $this->new_weighting[$i]; |
|
601 | - $position = $this->new_position[$i]; |
|
602 | - $hotspot_coordinates = $this->new_hotspot_coordinates[$i]; |
|
603 | - $hotspot_type = $this->new_hotspot_type[$i]; |
|
604 | - $destination = $this->new_destination[$i]; |
|
596 | + for ($i=1; $i <= $this->new_nbrAnswers; $i++) { |
|
597 | + $answer = $this->new_answer[$i]; |
|
598 | + $correct = $this->new_correct[$i]; |
|
599 | + $comment = $this->new_comment[$i]; |
|
600 | + $weighting = $this->new_weighting[$i]; |
|
601 | + $position = $this->new_position[$i]; |
|
602 | + $hotspot_coordinates = $this->new_hotspot_coordinates[$i]; |
|
603 | + $hotspot_type = $this->new_hotspot_type[$i]; |
|
604 | + $destination = $this->new_destination[$i]; |
|
605 | 605 | $autoId = $this->selectAutoId($i); |
606 | 606 | |
607 | 607 | if (!isset($this->position[$i])) { |
@@ -698,36 +698,36 @@ discard block |
||
698 | 698 | } |
699 | 699 | } |
700 | 700 | |
701 | - // moves $new_* arrays |
|
702 | - $this->answer = $this->new_answer; |
|
703 | - $this->correct = $this->new_correct; |
|
704 | - $this->comment = $this->new_comment; |
|
705 | - $this->weighting = $this->new_weighting; |
|
706 | - $this->position = $this->new_position; |
|
707 | - $this->hotspot_coordinates = $this->new_hotspot_coordinates; |
|
708 | - $this->hotspot_type = $this->new_hotspot_type; |
|
709 | - |
|
710 | - $this->nbrAnswers = $this->new_nbrAnswers; |
|
711 | - $this->destination = $this->new_destination; |
|
712 | - // clears $new_* arrays |
|
713 | - |
|
714 | - $this->cancel(); |
|
715 | - } |
|
716 | - |
|
717 | - /** |
|
718 | - * Duplicates answers by copying them into another question |
|
719 | - * |
|
720 | - * @author Olivier Brouckaert |
|
721 | - * @param int question id |
|
701 | + // moves $new_* arrays |
|
702 | + $this->answer = $this->new_answer; |
|
703 | + $this->correct = $this->new_correct; |
|
704 | + $this->comment = $this->new_comment; |
|
705 | + $this->weighting = $this->new_weighting; |
|
706 | + $this->position = $this->new_position; |
|
707 | + $this->hotspot_coordinates = $this->new_hotspot_coordinates; |
|
708 | + $this->hotspot_type = $this->new_hotspot_type; |
|
709 | + |
|
710 | + $this->nbrAnswers = $this->new_nbrAnswers; |
|
711 | + $this->destination = $this->new_destination; |
|
712 | + // clears $new_* arrays |
|
713 | + |
|
714 | + $this->cancel(); |
|
715 | + } |
|
716 | + |
|
717 | + /** |
|
718 | + * Duplicates answers by copying them into another question |
|
719 | + * |
|
720 | + * @author Olivier Brouckaert |
|
721 | + * @param int question id |
|
722 | 722 | * @param array destination course info (result of the function api_get_course_info() ) |
723 | - */ |
|
723 | + */ |
|
724 | 724 | public function duplicate($newQuestionId, $course_info = null) |
725 | 725 | { |
726 | 726 | if (empty($course_info)) { |
727 | 727 | $course_info = $this->course; |
728 | 728 | } |
729 | 729 | |
730 | - $TBL_REPONSES = Database :: get_course_table(TABLE_QUIZ_ANSWER); |
|
730 | + $TBL_REPONSES = Database :: get_course_table(TABLE_QUIZ_ANSWER); |
|
731 | 731 | $fixed_list = array(); |
732 | 732 | |
733 | 733 | if (self::getQuestionType() == MULTIPLE_ANSWER_TRUE_FALSE || |
@@ -741,7 +741,7 @@ discard block |
||
741 | 741 | |
742 | 742 | if (!empty($origin_options)) { |
743 | 743 | foreach ($origin_options as $item) { |
744 | - $new_option_list[] = $item['id']; |
|
744 | + $new_option_list[] = $item['id']; |
|
745 | 745 | } |
746 | 746 | } |
747 | 747 | |
@@ -755,12 +755,12 @@ discard block |
||
755 | 755 | } |
756 | 756 | } |
757 | 757 | |
758 | - // if at least one answer |
|
759 | - if ($this->nbrAnswers) { |
|
760 | - // inserts new answers into data base |
|
761 | - $c_id = $course_info['real_id']; |
|
758 | + // if at least one answer |
|
759 | + if ($this->nbrAnswers) { |
|
760 | + // inserts new answers into data base |
|
761 | + $c_id = $course_info['real_id']; |
|
762 | 762 | |
763 | - for ($i=1;$i <= $this->nbrAnswers;$i++) { |
|
763 | + for ($i=1;$i <= $this->nbrAnswers;$i++) { |
|
764 | 764 | if ($this->course['id'] != $course_info['id']) { |
765 | 765 | $this->answer[$i] = DocumentManager::replace_urls_inside_content_html_from_copy_course( |
766 | 766 | $this->answer[$i], |
@@ -774,8 +774,8 @@ discard block |
||
774 | 774 | ); |
775 | 775 | } |
776 | 776 | |
777 | - $answer = $this->answer[$i]; |
|
778 | - $correct = $this->correct[$i]; |
|
777 | + $answer = $this->answer[$i]; |
|
778 | + $correct = $this->correct[$i]; |
|
779 | 779 | |
780 | 780 | if (self::getQuestionType() == MULTIPLE_ANSWER_TRUE_FALSE || |
781 | 781 | self::getQuestionType() == MULTIPLE_ANSWER_TRUE_FALSE |
@@ -783,12 +783,12 @@ discard block |
||
783 | 783 | $correct = $fixed_list[intval($correct)]; |
784 | 784 | } |
785 | 785 | |
786 | - $comment = $this->comment[$i]; |
|
787 | - $weighting = $this->weighting[$i]; |
|
788 | - $position = $this->position[$i]; |
|
789 | - $hotspot_coordinates = $this->hotspot_coordinates[$i]; |
|
790 | - $hotspot_type = $this->hotspot_type[$i]; |
|
791 | - $destination = $this->destination[$i]; |
|
786 | + $comment = $this->comment[$i]; |
|
787 | + $weighting = $this->weighting[$i]; |
|
788 | + $position = $this->position[$i]; |
|
789 | + $hotspot_coordinates = $this->hotspot_coordinates[$i]; |
|
790 | + $hotspot_type = $this->hotspot_type[$i]; |
|
791 | + $destination = $this->destination[$i]; |
|
792 | 792 | |
793 | 793 | $params = [ |
794 | 794 | 'c_id' => $c_id, |
@@ -808,9 +808,9 @@ discard block |
||
808 | 808 | $sql = "UPDATE $TBL_REPONSES SET id = iid, id_auto = iid WHERE iid = $id"; |
809 | 809 | Database::query($sql); |
810 | 810 | } |
811 | - } |
|
811 | + } |
|
812 | 812 | } |
813 | - } |
|
813 | + } |
|
814 | 814 | |
815 | 815 | /** |
816 | 816 | * Get the necessary JavaScript for some answers |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | $objExercise->read($exerciseId); |
74 | 74 | |
75 | 75 | if ($objExercise->random_answers == '1') { |
76 | - $this->readOrderedBy('rand()', '');// randomize answers |
|
76 | + $this->readOrderedBy('rand()', ''); // randomize answers |
|
77 | 77 | } else { |
78 | 78 | $this->read(); // natural order |
79 | 79 | } |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | ORDER BY position"; |
115 | 115 | |
116 | 116 | $result = Database::query($sql); |
117 | - $i=1; |
|
117 | + $i = 1; |
|
118 | 118 | |
119 | 119 | // while a record is found |
120 | 120 | while ($object = Database::fetch_object($result)) { |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | $this->autoId[$i] = $object->id_auto; |
131 | 131 | $i++; |
132 | 132 | } |
133 | - $this->nbrAnswers = $i-1; |
|
133 | + $this->nbrAnswers = $i - 1; |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | /** |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | { |
143 | 143 | foreach ($this->autoId as $key => $autoId) { |
144 | 144 | if ($autoId == $id) { |
145 | - $result = [ |
|
145 | + $result = [ |
|
146 | 146 | 'answer' => $this->answer[$key], |
147 | 147 | 'correct' => $this->correct[$key], |
148 | 148 | 'comment' => $this->comment[$key], |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | $TBL_ANSWER = Database::get_course_table(TABLE_QUIZ_ANSWER); |
167 | 167 | $questionId = $this->questionId; |
168 | 168 | |
169 | - $sql="SELECT id FROM |
|
169 | + $sql = "SELECT id FROM |
|
170 | 170 | $TBL_ANSWER |
171 | 171 | WHERE c_id = {$this->course_id} AND question_id ='".$questionId."'"; |
172 | 172 | |
@@ -188,14 +188,14 @@ discard block |
||
188 | 188 | * @param string DESC or ASC |
189 | 189 | * @author Frederic Vauthier |
190 | 190 | */ |
191 | - public function readOrderedBy($field, $order='ASC') |
|
191 | + public function readOrderedBy($field, $order = 'ASC') |
|
192 | 192 | { |
193 | 193 | $field = Database::escape_string($field); |
194 | 194 | if (empty($field)) { |
195 | 195 | $field = 'position'; |
196 | 196 | } |
197 | 197 | |
198 | - if ($order != 'ASC' && $order!='DESC') { |
|
198 | + if ($order != 'ASC' && $order != 'DESC') { |
|
199 | 199 | $order = 'ASC'; |
200 | 200 | } |
201 | 201 | |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | c_id = {$this->course_id} AND |
231 | 231 | question_id='".$questionId."' |
232 | 232 | ORDER BY $field $order"; |
233 | - $result=Database::query($sql); |
|
233 | + $result = Database::query($sql); |
|
234 | 234 | |
235 | 235 | $i = 1; |
236 | 236 | // while a record is found |
@@ -260,7 +260,7 @@ discard block |
||
260 | 260 | $this->autoId[$i] = $doubt_data->id_auto; |
261 | 261 | $i++; |
262 | 262 | } |
263 | - $this->nbrAnswers = $i-1; |
|
263 | + $this->nbrAnswers = $i - 1; |
|
264 | 264 | } |
265 | 265 | |
266 | 266 | /** |
@@ -402,8 +402,8 @@ discard block |
||
402 | 402 | public function getGradesList() |
403 | 403 | { |
404 | 404 | $list = array(); |
405 | - for ($i = 0; $i<$this->nbrAnswers;$i++){ |
|
406 | - if(!empty($this->answer[$i])){ |
|
405 | + for ($i = 0; $i < $this->nbrAnswers; $i++) { |
|
406 | + if (!empty($this->answer[$i])) { |
|
407 | 407 | $list[$i] = $this->weighting[$i]; |
408 | 408 | } |
409 | 409 | } |
@@ -421,7 +421,7 @@ discard block |
||
421 | 421 | $sql = "SELECT type FROM $TBL_QUESTIONS |
422 | 422 | WHERE c_id = {$this->course_id} AND id = '".$this->questionId."'"; |
423 | 423 | $res = Database::query($sql); |
424 | - if (Database::num_rows($res)<=0){ |
|
424 | + if (Database::num_rows($res) <= 0) { |
|
425 | 425 | return null; |
426 | 426 | } |
427 | 427 | $row = Database::fetch_array($res); |
@@ -593,7 +593,7 @@ discard block |
||
593 | 593 | $correctList = []; |
594 | 594 | $answerList = []; |
595 | 595 | |
596 | - for ($i=1; $i <= $this->new_nbrAnswers; $i++) { |
|
596 | + for ($i = 1; $i <= $this->new_nbrAnswers; $i++) { |
|
597 | 597 | $answer = $this->new_answer[$i]; |
598 | 598 | $correct = $this->new_correct[$i]; |
599 | 599 | $comment = $this->new_comment[$i]; |
@@ -748,7 +748,7 @@ discard block |
||
748 | 748 | $destination_options = Question::readQuestionOption($newQuestionId, $course_info['real_id']); |
749 | 749 | $i = 0; |
750 | 750 | if (!empty($destination_options)) { |
751 | - foreach($destination_options as $item) { |
|
751 | + foreach ($destination_options as $item) { |
|
752 | 752 | $fixed_list[$new_option_list[$i]] = $item['id']; |
753 | 753 | $i++; |
754 | 754 | } |
@@ -760,7 +760,7 @@ discard block |
||
760 | 760 | // inserts new answers into data base |
761 | 761 | $c_id = $course_info['real_id']; |
762 | 762 | |
763 | - for ($i=1;$i <= $this->nbrAnswers;$i++) { |
|
763 | + for ($i = 1; $i <= $this->nbrAnswers; $i++) { |
|
764 | 764 | if ($this->course['id'] != $course_info['id']) { |
765 | 765 | $this->answer[$i] = DocumentManager::replace_urls_inside_content_html_from_copy_course( |
766 | 766 | $this->answer[$i], |