17 require_once SQ_SYSTEM_ROOT.
'/core/hipo/hipo_job.inc';
18 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
50 $this->uses_trans = FALSE;
64 return parent::getCodeName().
'-'.$this->_running_vars[
'root_node'];
77 return translate(
'hipo_name_export_online_quiz_to_xml');
93 'name' =>
'Initialising Export',
94 'function_call' => Array(
95 'process_function' =>
'initialiseExport',
97 'running_mode' =>
'server',
100 'allow_cancel' => TRUE,
106 'name' =>
'Generating XML',
107 'function_call' => Array(
108 'process_function' =>
'generateXML',
110 'running_mode' =>
'server',
112 'skip_step' => FALSE,
113 'allow_cancel' => TRUE,
119 'name' =>
'Finalising Export',
120 'function_call' => Array(
121 'process_function' =>
'finaliseExport',
123 'running_mode' =>
'server',
125 'skip_step' => FALSE,
126 'allow_cancel' => TRUE,
144 if (empty($this->_running_vars[
'root_node'])) {
145 trigger_error(
'There is no root node specified', E_USER_WARNING);
149 if (empty($this->_running_vars[
'type_codes'])) {
150 trigger_error (
'There is no type codes specified', E_USER_NOTICE);
154 if (!is_dir($this->_running_vars[
'export_dir'])) {
155 if (!create_directory($this->_running_vars[
'export_dir']))
return FALSE;
158 $this->_running_vars[
'todo_export_assets'] = Array();
159 $this->_running_vars[
'done_export_assets'] = Array();
161 $this->_running_vars[
'opened_tags'] = Array();
163 $this->_running_vars[
'skip_type_codes'] = Array(
'online_quiz_question_multichoice',
'online_quiz_question_group');
166 $children = $GLOBALS[
'SQ_SYSTEM']->am->getAllChildLinks($this->_running_vars[
'root_node'], SQ_SC_LINK_SIGNIFICANT);
168 $root_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($this->_running_vars[
'root_node']);
169 array_unshift($children, Array (
171 "assetid" => $root_asset->id,
172 "type_code" => $root_asset->type(),
174 "is_dependant" =>
"0",
176 $this->_running_vars[
'todo_export_assets'] = $children;
178 return parent::prepare();
195 while (!empty($this->_running_vars[
'todo_export_assets'])) {
196 if (!$this->
generateXML($this->_steps[1], get_class($this))) {
222 echo
"<?xml version=\"1.0\" encoding=\"".SQ_CONF_DEFAULT_CHARACTER_SET.
"\"?>\n";
223 echo
"<data_export>\n";
224 $output = ob_get_clean();
225 file_put_contents($this->_running_vars[
'export_dir'].
'/export.xml', $output, FILE_APPEND | LOCK_EX);
227 $step_data[
'percent_done'] = 100;
228 $step_data[
'complete'] = TRUE;
248 if (!empty($this->_running_vars[
'todo_export_assets'])) {
249 $todo_asset = array_shift($this->_running_vars[
'todo_export_assets']);
252 foreach (array_reverse($this->_running_vars[
'opened_tags'], TRUE) as $level_no => $tag_name){
253 if ($todo_asset[
'lvl'] <= $level_no){
254 echo
"</".$tag_name.
">\n";
255 unset($this->_running_vars[
'opened_tags'][$level_no]);
259 $assetid = $todo_asset[
'assetid'];
260 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
261 if (!is_null($asset)){
264 if (!$todo_asset[
'is_dependant'] && !($todo_asset[
'link_type'] == SQ_LINK_TYPE_3) && !in_array($todo_asset[
'type_code'], $this->_running_vars[
'skip_type_codes'])){
265 $step_data[
'message'] =
"Generating XML for $asset->name (Id: #$asset->id)";
266 echo
"<".$asset->type().
" assetid=\"".$asset->id.
"\">\n";
267 $this->_running_vars[
'opened_tags'][$todo_asset[
'lvl']] = $asset->type();
268 $method_name =
'generate'.str_replace(
'_',
'', get_class($asset)).
'XML';
269 if (in_array($todo_asset[
'type_code'], $this->_running_vars[
'type_codes']) && method_exists($this, $method_name) && $asset->readAccess()){
270 $this->$method_name($asset);
273 echo
"<name><![CDATA[".$asset->name.
"]]></name>\n";
276 $step_data[
'message'] = translate(
'hipo_skipping_asset', $assetid);
279 $step_data[
'message'] = translate(
'hipo_skipping_asset', $assetid);
280 $this->
_addError(
"Could not load Asset (Id: #$assetid)");
282 $this->_running_vars[
'done_export_assets'][] = $assetid;
285 $output = ob_get_clean();
286 file_put_contents($this->_running_vars[
'export_dir'].
'/export.xml', $output, FILE_APPEND | LOCK_EX);
288 if (empty($this->_running_vars[
'todo_export_assets'])) {
289 $step_data[
'percent_done'] = 100;
290 $step_data[
'complete'] = TRUE;
292 $total = count($this->_running_vars[
'todo_export_assets']) + count($this->_running_vars[
'done_export_assets']);
293 $step_data[
'percent_done'] = (count($this->_running_vars[
'done_export_assets']) / $total) * 100;
294 $step_data[
'complete'] = FALSE;
316 foreach (array_reverse($this->_running_vars[
'opened_tags'], TRUE) as $level_no => $tag_name){
317 echo
"</".$tag_name.
">\n";
318 unset($this->_running_vars[
'opened_tags'][$level_no]);
321 echo
"</data_export>\n";
323 $output = ob_get_clean();
324 file_put_contents($this->_running_vars[
'export_dir'].
'/export.xml', $output, FILE_APPEND | LOCK_EX);
327 $content = file_get_contents($this->_running_vars[
'export_dir'].
'/export.xml');
328 $GLOBALS[
'SQ_SYSTEM']->_translateMatrixURL($content);
329 file_put_contents($this->_running_vars[
'export_dir'].
'/export.xml', $content, LOCK_EX);
333 $doc =
new DOMDocument();
334 $doc->formatOutput = TRUE;
335 $doc->load($this->_running_vars[
'export_dir'].
'/export.xml', LIBXML_NOBLANKS);
336 $doc->save($this->_running_vars[
'export_dir'].
'/export.xml', LIBXML_NOEMPTYTAG);
338 $step_data[
'percent_done'] = 100;
339 $step_data[
'complete'] = TRUE;
356 $settings = isset($this->_running_vars[
'export_settings'][$asset->
type()]) ? $this->_running_vars[
'export_settings'][$asset->
type()] : Array();
358 $start_tag = array_get_index($settings,
'start_tag',
'');
359 $end_tag = array_get_index($settings,
'end_tag',
'');
360 $paint_method = array_get_index($settings,
'paint_method',
'raw');
362 echo
"<name><![CDATA[".trim($asset->
attr(
'name')).
"]]></name>";
363 echo
"<short_name><![CDATA[".trim($asset->
attr(
'short_name')).
"]]></short_name>";
366 if ($paint_method ==
'default_layout'){
367 $layout_id = $GLOBALS[
'SQ_SYSTEM']->am->getValueFromURL(strip_url($asset->
getURL(), TRUE),
'paint_layout::system::frontend');
368 if (!empty($layout_id)){
376 $contents = ob_get_clean();
378 if (!empty($start_tag) || !empty($end_tag)) {
379 $start_tag = preg_quote($start_tag,
'/');
380 $end_tag = preg_quote($end_tag,
'/');
381 $pattern =
"/$start_tag(.*)$end_tag/s";
383 $matched = preg_match($pattern, $contents, $matches);
384 if ($matched) $contents = $matches[1];
388 echo
"<contents><![CDATA[".trim($contents).
"]]></contents>";
403 echo
"<name><![CDATA[".trim($asset->
attr(
'name')).
"]]></name>\n";
405 $pool_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($asset->id, SQ_LINK_NOTICE,
'', FALSE,
'major',
'root');
407 $question_group_ids = Array();
408 foreach ($pool_links as $link){
410 $pool_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($link[
'minorid']);
411 if ($pool_asset && $pool_asset->type() ==
'online_quiz_question_group'){
412 $question_group_ids[$link[
'minorid']][] = $link[
'minorid'];
415 $question_groups = $GLOBALS[
'SQ_SYSTEM']->am->getParents($link[
'minorid'],
'online_quiz_question_group', TRUE, NULL, SQ_PERMISSION_READ);
416 foreach (array_keys($question_groups) as $question_group_id) {
417 $question_group_ids[$question_group_id][] = $link[
'minorid'];
421 foreach ($question_group_ids as $question_group_id => $pool_nodes){
422 $question_group = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($question_group_id);
423 if (is_null($question_group))
continue;
425 echo
"<".$question_group->type().
" assetid=\"".$question_group->id.
"\" pool_nodes=\"".implode(
',', $pool_nodes).
"\">\n";
426 echo
"<name><![CDATA[".trim($question_group->attr(
'name')).
"]]></name>\n";
427 $score_categories = $question_group->attr(
'score_categories');
428 foreach ($score_categories as $category){
429 echo
"<score_category>\n";
430 echo
"<name><![CDATA[".trim($category[
'name']).
"]]></name>\n";
431 echo
"<min_score>".$category[
'min_score'].
"</min_score>\n";
432 echo
"<max_score>".$category[
'max_score'].
"</max_score>\n";
433 echo
"<content><![CDATA[".trim($category[
'content']).
"]]></content>\n";
434 echo
"</score_category>\n";
436 echo
"</".$question_group->type().
">\n";
437 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($question_group);
441 $question_pool_setup = $asset->
attr(
'question_pool_setup');
442 foreach ($pool_links as $link){
443 echo
"<pool_node id=\"".$link[
'minorid'].
"\">\n";
445 if ($asset->
attr(
'interactive_mode')){
446 $info = $question_pool_setup[$link[
'minorid']];
447 echo
"<size>".$info[
'size'].
"</size>\n";
448 echo
"<retries>".$info[
'retries'].
"</retries>\n";
449 echo
"<order>$order</order>\n";
452 $questions = $GLOBALS[
'SQ_SYSTEM']->am->getChildren($link[
'minorid'],
'online_quiz_question_multichoice', TRUE, NULL, NULL, SQ_PERMISSION_READ);
453 foreach (array_keys($questions) as $question_id){
454 $question = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($question_id);
455 if (is_null($question))
continue;
457 echo
"<".$question->type().
" assetid=\"".$question->id.
"\">\n";
458 echo
"<name><![CDATA[".trim($question->attr(
'name')).
"]]></name>\n";
459 echo
"<question_text><![CDATA[".trim($question->getQuestionText()).
"]]></question_text>\n";
460 echo
"<question_note><![CDATA[".trim($question->getQuestionNote()).
"]]></question_note>\n";
462 $options = $question->attr(
'response_form');
463 foreach ($options as $option_key => $option_info){
465 echo
"<text><![CDATA[".trim($option_info[
'text']).
"]]></text>\n";
466 echo
"<points>".$option_info[
'points'].
"</points>\n";
467 echo
"<response_supplement><![CDATA[".trim($option_info[
'response_supplement']).
"]]></response_supplement>\n";
470 echo
"</".$question->type().
">\n";
471 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($question);
473 echo
"</pool_node>\n";