Пример #1
0
 public function on_generate_feedbacks()
 {
     parent::on_generate_feedbacks();
     // Question combined feedback.
     $responsenodes = $this->questions->nodeList('plugin_qtype_shortanswer_question//answer', $this->question_node);
     $count = 0;
     foreach ($responsenodes as $respnode) {
         $content = $this->questions->nodeValue('feedback', $respnode);
         if (empty($content)) {
             continue;
         }
         $correct = (int) $this->questions->nodeValue('fraction', $respnode) == 1;
         $answerid = (int) $this->questions->nodeValue('@id', $respnode);
         $result = cc_helpers::process_linked_files($content, $this->manifest, $this->rootpath, $this->contextid, $this->outdir);
         $ident = $correct ? 'correct' : 'incorrect';
         $ident .= '_' . $count . '_fb';
         cc_assesment_helper::add_feedback($this->qitem, $result[0], cc_qti_values::htmltype, $ident);
         pkg_resource_dependencies::instance()->add($result[1]);
         if ($correct) {
             $this->correct_feedbacks[$answerid] = $ident;
         } else {
             $this->incorrect_feedbacks[$answerid] = $ident;
         }
         ++$count;
     }
 }
Пример #2
0
 public function convert($outdir)
 {
     $resitem = new cc_item();
     $resitem->title = $this->doc->nodeValue('/activity/folder/name');
     $this->item->add_child_item($resitem);
     $contextid = $this->doc->nodeValue('/activity/@contextid');
     cc_helpers::handle_static_content($this->manifest, $this->rootpath, $contextid, $outdir);
     return true;
 }
Пример #3
0
 public function convert($outdir)
 {
     $rt = new basicltil1_resurce_file();
     $contextid = $this->doc->nodeValue('/activity/@contextid');
     $title = $this->doc->nodeValue('/activity/lti/name');
     $text = $this->doc->nodeValue('/activity/lti/intro');
     $rt->set_title($title);
     $result = cc_helpers::process_linked_files($text, $this->manifest, $this->rootpath, $contextid, $outdir);
     $rt->set_description($result[0]);
     $rt->set_launch_url($this->doc->nodeValue('/activity/lti/toolurl'));
     $rt->set_launch_icon('');
     $this->store($rt, $outdir, $title, $result[1]);
     return true;
 }
Пример #4
0
 protected function on_create(DOMDocument &$doc, $rootmanifestnode = null, $nmanifestID = null)
 {
     $doc->formatOutput = true;
     $doc->preserveWhiteSpace = true;
     $this->manifestID = is_null($nmanifestID) ? cc_helpers::uuidgen('M_') : $nmanifestID;
     $mUUID = $doc->createAttribute('identifier');
     $mUUID->nodeValue = $this->manifestID;
     if (is_null($rootmanifestnode)) {
         if (!empty($this->_generator)) {
             $comment = $doc->createComment($this->_generator);
             $doc->appendChild($comment);
         }
         $rootel = $doc->createElementNS($this->ccnamespaces['imscc'], 'manifest');
         $rootel->appendChild($mUUID);
         $doc->appendChild($rootel);
         //add all namespaces
         foreach ($this->ccnamespaces as $key => $value) {
             if ($key != 'lom') {
                 $dummy_attr = $key . ":dummy";
                 $doc->createAttributeNS($value, $dummy_attr);
             }
         }
         // add location of schemas
         $schemaLocation = '';
         foreach ($this->ccnsnames as $key => $value) {
             $vt = empty($schemaLocation) ? '' : ' ';
             $schemaLocation .= $vt . $this->ccnamespaces[$key] . ' ' . $value;
         }
         $aSchemaLoc = $doc->createAttributeNS($this->ccnamespaces['xsi'], 'xsi:schemaLocation');
         $aSchemaLoc->nodeValue = $schemaLocation;
         $rootel->appendChild($aSchemaLoc);
     } else {
         $rootel = $doc->createElementNS($this->ccnamespaces['imscc'], 'imscc:manifest');
         $rootel->appendChild($mUUID);
     }
     $metadata = $doc->createElementNS($this->ccnamespaces['imscc'], 'metadata');
     $schema = $doc->createElementNS($this->ccnamespaces['imscc'], 'schema', 'IMS Common Cartridge');
     $schemaversion = $doc->createElementNS($this->ccnamespaces['imscc'], 'schemaversion', $this->ccversion);
     $metadata->appendChild($schema);
     $metadata->appendChild($schemaversion);
     $rootel->appendChild($metadata);
     if (!is_null($rootmanifestnode)) {
         $rootmanifestnode->appendChild($rootel);
     }
     $organizations = $doc->createElementNS($this->ccnamespaces['imscc'], 'organizations');
     $rootel->appendChild($organizations);
     $resources = $doc->createElementNS($this->ccnamespaces['imscc'], 'resources');
     $rootel->appendChild($resources);
     return true;
 }
Пример #5
0
 public function convert($outdir)
 {
     $rt = new assesment11_resurce_file();
     $title = $this->doc->nodeValue('/activity/quiz/name');
     $rt->set_title($title);
     // Metadata.
     $metadata = new cc_assesment_metadata();
     $rt->set_metadata($metadata);
     $metadata->enable_feedback();
     $metadata->enable_hints();
     $metadata->enable_solutions();
     // Attempts.
     $max_attempts = (int) $this->doc->nodeValue('/activity/quiz/attempts_number');
     if ($max_attempts > 0) {
         // Qti does not support number of specific attempts bigger than 5 (??)
         if ($max_attempts > 5) {
             $max_attempts = cc_qti_values::unlimited;
         }
         $metadata->set_maxattempts($max_attempts);
     }
     // Time limit must be converted into minutes.
     $timelimit = (int) floor((int) $this->doc->nodeValue('/activity/quiz/timelimit') / 60);
     if ($timelimit > 0) {
         $metadata->set_timelimit($timelimit);
         $metadata->enable_latesubmissions(false);
     }
     $contextid = $this->doc->nodeValue('/activity/@contextid');
     $result = cc_helpers::process_linked_files($this->doc->nodeValue('/activity/quiz/intro'), $this->manifest, $this->rootpath, $contextid, $outdir);
     cc_assesment_helper::add_assesment_description($rt, $result[0], cc_qti_values::htmltype);
     // Section.
     $section = new cc_assesment_section();
     $rt->set_section($section);
     // Process the actual questions.
     $ndeps = cc_assesment_helper::process_questions($this->doc, $this->manifest, $section, $this->rootpath, $contextid, $outdir);
     if ($ndeps === false) {
         // No exportable questions in quiz or quiz has no questions
         // so just skip it.
         return true;
     }
     // Store any additional dependencies.
     $deps = array_merge($result[1], $ndeps);
     // Store everything.
     $this->store($rt, $outdir, $title, $deps);
     return true;
 }
Пример #6
0
 public function convert($outdir)
 {
     $rt = new forum11_resurce_file();
     $title = $this->doc->nodeValue('/activity/forum/name');
     $rt->set_title($title);
     $text = $this->doc->nodeValue('/activity/forum/intro');
     $deps = null;
     if (!empty($text)) {
         $textformat = intval($this->doc->nodeValue('/activity/forum/introformat'));
         $contextid = $this->doc->nodeValue('/activity/@contextid');
         $result = cc_helpers::process_linked_files($text, $this->manifest, $this->rootpath, $contextid, $outdir);
         $textformat = $textformat == 1 ? 'text/html' : 'text/plain';
         $rt->set_text($result[0], $textformat);
         $deps = $result[1];
     }
     $this->store($rt, $outdir, $title, $deps);
     return true;
 }
 public function convert($outdir)
 {
     $title = $this->doc->nodeValue('/activity/resource/name');
     $contextid = $this->doc->nodeValue('/activity/@contextid');
     $files = cc_helpers::handle_resource_content($this->manifest, $this->rootpath, $contextid, $outdir);
     $deps = null;
     $resvalue = null;
     foreach ($files as $vfile => $values) {
         if ($values[2]) {
             $resvalue = $values[0];
             break;
         }
     }
     $resitem = new cc_item();
     $resitem->identifierref = $resvalue;
     $resitem->title = $title;
     $this->item->add_child_item($resitem);
     return true;
 }
Пример #8
0
 public function convert($outdir)
 {
     $rt = new page11_resurce_file();
     $title = $this->doc->nodeValue('/activity/page/name');
     $intro = $this->doc->nodeValue('/activity/page/intro');
     $contextid = $this->doc->nodeValue('/activity/@contextid');
     $pagecontent = $this->doc->nodeValue('/activity/page/content');
     $rt->set_title($title);
     $rawname = str_replace(' ', '_', strtolower(trim(clean_param($title, PARAM_FILE))));
     if (!empty($rawname)) {
         $this->defaultname = $rawname . ".html";
     }
     $result = cc_helpers::process_linked_files($pagecontent, $this->manifest, $this->rootpath, $contextid, $outdir, true);
     $rt->set_content($result[0]);
     $rt->set_intro($intro);
     //store everything
     $this->store($rt, $outdir, $title, $result[1]);
     return true;
 }
 public function on_generate_answers()
 {
     // Add responses holder.
     $qresponse_lid = new cc_response_lidtype();
     $this->qresponse_lid = $qresponse_lid;
     $this->qpresentation->set_response_lid($qresponse_lid);
     $qresponse_choice = new cc_assesment_render_choicetype();
     $qresponse_lid->set_render_choice($qresponse_choice);
     // Mark that question has only one correct answer -
     // which applies for multiple choice and yes/no questions.
     $qresponse_lid->set_rcardinality(cc_qti_values::Single);
     // Are we to shuffle the responses?
     $shuffle_answers = (int) $this->quiz->nodeValue('/activity/quiz/shuffleanswers') > 0;
     $qresponse_choice->enable_shuffle($shuffle_answers);
     $answerlist = array();
     $qa_responses = $this->questions->nodeList('plugin_qtype_truefalse_question/answers/answer', $this->question_node);
     foreach ($qa_responses as $node) {
         $answer_content = $this->questions->nodeValue('answertext', $node);
         $id = (int) $this->questions->nodeValue('@id', $node) == $this->correct_answer_node_id;
         $qresponse_label = cc_assesment_helper::add_answer($qresponse_choice, $answer_content, cc_qti_values::htmltype);
         $answer_ident = strtolower(trim($answer_content));
         $qresponse_label->set_ident($answer_ident);
         $feedback_ident = $id ? 'correct_fb' : 'incorrect_fb';
         if (empty($this->correct_answer_ident) && $id) {
             $this->correct_answer_ident = $answer_ident;
         }
         // Add answer specific feedback if not empty.
         $content = $this->questions->nodeValue('feedback', $node);
         if (!empty($content)) {
             $result = cc_helpers::process_linked_files($content, $this->manifest, $this->rootpath, $this->contextid, $this->outdir);
             cc_assesment_helper::add_feedback($this->qitem, $result[0], cc_qti_values::htmltype, $feedback_ident);
             pkg_resource_dependencies::instance()->add($result[1]);
             $answerlist[$answer_ident] = $feedback_ident;
         }
     }
     $this->answerlist = $answerlist;
 }
Пример #10
0
 /**
  * Add a resource to the manifest
  *
  * @param cc_i_resource $res
  * @param string $identifier
  * @param string $type
  * @return array
  */
 public function add_resource(cc_i_resource $res, $identifier = null, $type = 'webcontent')
 {
     if (!$this->ccobj->valid($type)) {
         throw new Exception("Type invalid...");
     }
     if (is_null($res)) {
         throw new Exception('Invalid Resource or dont give it');
     }
     $rst = null;
     if (is_string($res)) {
         $rst = new cc_resource($this->filePath(), $res);
         if (is_string($identifier)) {
             $rst->identifier = $identifier;
         }
     } else {
         $rst = $res;
     }
     //TODO: This has to be reviewed since it does not handle properly mutiple file
     //      dependencies
     if (is_object($identifier)) {
         $this->activemanifest->create_resource_node($rst, $this->doc, $identifier);
     } else {
         $nresnode = null;
         $rst->type = $type;
         if (!cc_helpers::is_html($rst->filename)) {
             $rst->href = null;
         }
         $this->activemanifest->create_resource_node($rst, $this->doc, $nresnode);
         for ($i = 1; $i < count($rst->files); $i++) {
             $ident = $this->get_identifier_by_filename($rst->files[$i]);
             if (empty($ident)) {
                 $newres = new cc_resource($rst->manifestroot, $rst->files[$i], false);
                 if (!empty($newres)) {
                     if (!cc_helpers::is_html($rst->files[$i])) {
                         $newres->href = null;
                     }
                     $newres->type = 'webcontent';
                     $this->activemanifest->create_resource_node($newres, $this->doc, $nresnode);
                 }
             }
         }
         foreach ($this->activemanifest->resources as $k => $v) {
             $k;
             $depen = $this->check_if_exist_in_other($v->files[0]);
             if (!empty($depen)) {
                 $this->replace_file_x_dependency($depen, $v->files[0]);
                 // coloca aca como type = webcontent porque son archivos dependientes
                 // quizas aqui habria q ver de que type es el que vino y segun eso, ponerlo
                 // en associatedcontent o en webcontent
                 $v->type = 'webcontent';
             }
         }
     }
     $tmparray = array($rst->identifier, $rst->files[0]);
     return $tmparray;
 }
Пример #11
0
 public function init_empty_new()
 {
     $this->identifier = cc_helpers::uuidgen('I_', '_R');
     $this->type = null;
     $this->href = null;
     $this->persiststate = null;
     $this->filename = null;
     $this->isempty = false;
     $this->identifierref = null;
 }
Пример #12
0
 /**
  *
  * ctor
  * @param string $rootdir - path to the containing directory
  * @throws InvalidArgumentException
  * @throws RuntimeException
  */
 public function __construct($rootdir)
 {
     $rdir = realpath($rootdir);
     if (empty($rdir)) {
         throw new InvalidArgumentException('Invalid path!');
     }
     $dir = cc_helpers::randomdir($rdir, 'i_');
     if ($dir === false) {
         throw new RuntimeException('Unable to create directory!');
     }
     $this->rootdir = $rdir;
     $this->dir = $dir;
     $this->fullpath = $rdir . DIRECTORY_SEPARATOR . $dir;
 }
Пример #13
0
 public function on_generate_feedbacks()
 {
     parent::on_generate_feedbacks();
     //Question combined feedbacks
     $correct_question_fb = $this->questions->nodeValue('plugin_qtype_multichoice_question/multichoice/correctfeedback', $this->question_node);
     $incorrect_question_fb = $this->questions->nodeValue('plugin_qtype_multichoice_question/multichoice/incorrectfeedback', $this->question_node);
     if (empty($correct_question_fb)) {
         //Hardcode some text for now
         $correct_question_fb = 'Well done!';
     }
     if (empty($incorrect_question_fb)) {
         //Hardcode some text for now
         $incorrect_question_fb = 'Better luck next time!';
     }
     $proc = array('correct_fb' => $correct_question_fb, 'incorrect_fb' => $incorrect_question_fb);
     foreach ($proc as $ident => $content) {
         if (empty($content)) {
             continue;
         }
         $result = cc_helpers::process_linked_files($content, $this->manifest, $this->rootpath, $this->contextid, $this->outdir);
         cc_assesment_helper::add_feedback($this->qitem, $result[0], cc_qti_values::htmltype, $ident);
         pkg_resource_dependencies::instance()->add($result[1]);
         if ($ident == 'correct_fb') {
             $this->correct_feedbacks[$ident] = $ident;
         } else {
             $this->incorrect_feedbacks[$ident] = $ident;
         }
     }
 }
Пример #14
0
 public function init_new_item()
 {
     $this->identifier = cc_helpers::uuidgen('I_');
     $this->isvisible = true;
     //default is true
     $this->title = null;
     $this->parameters = null;
     $this->childitems = null;
     $this->parentItem = null;
     $this->isempty = false;
 }
Пример #15
0
 /**
  * Add a resource to the manifest
  *
  * @param cc_i_resource $res
  * @param string $identifier
  * @param string $type
  * @return array
  */
 public function add_resource(cc_i_resource $res, $identifier = null, $type = 'webcontent')
 {
     if (!$this->ccobj->valid($type)) {
         throw new Exception("Type invalid...");
     }
     if ($res == null) {
         throw new Exception('Invalid Resource or dont give it');
     }
     $rst = $res;
     // TODO: This has to be reviewed since it does not handle multiple files properly.
     // Dependencies.
     if (is_object($identifier)) {
         $this->activemanifest->create_resource_node($rst, $this->doc, $identifier);
     } else {
         $nresnode = null;
         $rst->type = $type;
         if (!cc_helpers::is_html($rst->filename)) {
             $rst->href = null;
         }
         $this->activemanifest->create_resource_node($rst, $this->doc, $nresnode);
         foreach ($rst->files as $file) {
             $ident = $this->get_identifier_by_filename($file);
             if ($ident == null) {
                 $newres = new cc_resource($rst->manifestroot, $file);
                 if (!cc_helpers::is_html($file)) {
                     $newres->href = null;
                 }
                 $newres->type = 'webcontent';
                 $this->activemanifest->create_resource_node($newres, $this->doc, $nresnode);
             }
         }
     }
     $tmparray = array($rst->identifier, $rst->files[0]);
     return $tmparray;
 }