Example #1
0
 /**
  * Prepares the package up before control is passed to the portfolio plugin.
  *
  * @throws portfolio_caller_exception
  * @return mixed
  */
 public function prepare_package()
 {
     if ($this->plugin && $this->editor) {
         $options = portfolio_format_text_options();
         $context = context_module::instance($this->cmid);
         $options->context = $context;
         $plugin = $this->get_submission_plugin();
         $text = $plugin->get_editor_text($this->editor, $this->sid);
         $format = $plugin->get_editor_format($this->editor, $this->sid);
         $html = format_text($text, $format, $options);
         $html = portfolio_rewrite_pluginfile_urls($html, $context->id, 'mod_assign', $this->area, $this->sid, $this->exporter->get('format'));
         $exporterclass = $this->exporter->get('formatclass');
         if (in_array($exporterclass, array(PORTFOLIO_FORMAT_PLAINHTML, PORTFOLIO_FORMAT_RICHHTML))) {
             if ($files = $this->exporter->get('caller')->get('multifiles')) {
                 foreach ($files as $file) {
                     $this->exporter->copy_existing_file($file);
                 }
             }
             return $this->exporter->write_new_file($html, 'assignment.html', !empty($files));
         } else {
             if ($this->exporter->get('formatclass') == PORTFOLIO_FORMAT_LEAP2A) {
                 $leapwriter = $this->exporter->get('format')->leap2a_writer();
                 $entry = new portfolio_format_leap2a_entry($this->area . $this->cmid, $context->get_context_name(), 'resource', $html);
                 $entry->add_category('web', 'resource_type');
                 $entry->author = $this->user;
                 $leapwriter->add_entry($entry);
                 if ($files = $this->exporter->get('caller')->get('multifiles')) {
                     $leapwriter->link_files($entry, $files, $this->area . $this->cmid . 'file');
                     foreach ($files as $file) {
                         $this->exporter->copy_existing_file($file);
                     }
                 }
                 return $this->exporter->write_new_file($leapwriter->to_xml(), $this->exporter->get('format')->manifest_name(), true);
             } else {
                 debugging('invalid format class: ' . $this->exporter->get('formatclass'));
             }
         }
     }
     if ($this->exporter->get('formatclass') == PORTFOLIO_FORMAT_LEAP2A) {
         $leapwriter = $this->exporter->get('format')->leap2a_writer();
         $files = array();
         if ($this->singlefile) {
             $files[] = $this->singlefile;
         } else {
             if ($this->multifiles) {
                 $files = $this->multifiles;
             } else {
                 throw new portfolio_caller_exception('invalidpreparepackagefile', 'portfolio', $this->get_return_url());
             }
         }
         $entryids = array();
         foreach ($files as $file) {
             $entry = new portfolio_format_leap2a_file($file->get_filename(), $file);
             $entry->author = $this->user;
             $leapwriter->add_entry($entry);
             $this->exporter->copy_existing_file($file);
             $entryids[] = $entry->id;
         }
         if (count($files) > 1) {
             $baseid = 'assign' . $this->cmid . $this->area;
             $context = context_module::instance($this->cmid);
             // If we have multiple files, they should be grouped together into a folder.
             $entry = new portfolio_format_leap2a_entry($baseid . 'group', $context->get_context_name(), 'selection');
             $leapwriter->add_entry($entry);
             $leapwriter->make_selection($entry, $entryids, 'Folder');
         }
         return $this->exporter->write_new_file($leapwriter->to_xml(), $this->exporter->get('format')->manifest_name(), true);
     }
     return $this->prepare_package_file();
 }
Example #2
0
 /**
  * helper function to add a leap2a entry element
  * that corresponds to a single certificate,
  *
  * the entry/ies are added directly to the leapwriter, which is passed by ref
  *
  * @global object $certificate the stdclass object representing the database record
  * @param portfolio_format_leap2a_writer $leapwriter writer object to add entries to
  * @param string $content  the content of the certificate (prepared by {@link prepare_certificate}
  *
  * @return int id of new entry
  */
 private function prepare_certificat_leap2a(portfolio_format_leap2a_writer $leapwriter, $content)
 {
     global $USER;
     $order = array(" ", "\r\n", "\n", "\r");
     $replace = ' ';
     $content = str_replace($order, $replace, $content);
     $title = get_string('certificat', 'referentiel') . ' ' . $this->occurrence->code_referentiel;
     $entry = new portfolio_format_leap2a_entry('certificat' . $this->certificat->id, $title, 'leap2', $content);
     // proposer ability ?
     $entry->published = time();
     $entry->updated = time();
     $entry->author->id = $this->certificat->userid;
     $entry->summary = '<p><h3>' . get_string('certificat', 'referentiel') . ' ' . get_string('referentiel', 'referentiel') . $this->occurrence->code_referentiel . '</h3>' . "\n" . '<p>' . $this->occurrence->description_referentiel . '</p>';
     $entry->add_category('web', 'any_type', 'Referentiel');
     // DEBUG
     // echo "<br />266 :: ENTRY<br />\n";
     // print_object($entry);
     $leapwriter->add_entry($entry);
     // echo "<br />272 :: LEAPWRITER<br />\n";
     // print_object($leapwriter);
     return $entry->id;
 }
Example #3
0
 function portfolio_prepare_package($exporter, $user)
 {
     $submission = $this->get_submission($user->id);
     $options = new stdClass();
     $options->para = false;
     $options->filter = false;
     $html = format_text($submission->data1, $submission->data2, $options);
     $html = portfolio_rewrite_pluginfile_urls($html, $this->context->id, 'mod_assignment', $this->filearea, $submission->id, $exporter->get('format'));
     if (in_array($exporter->get('formatclass'), array(PORTFOLIO_FORMAT_PLAINHTML, PORTFOLIO_FORMAT_RICHHTML))) {
         if ($files = $exporter->get('caller')->get('multifiles')) {
             foreach ($files as $f) {
                 $exporter->copy_existing_file($f);
             }
         }
         return $exporter->write_new_file($html, 'assignment.html', !empty($files));
     } else {
         if ($exporter->get('formatclass') == PORTFOLIO_FORMAT_LEAP2A) {
             $leapwriter = $exporter->get('format')->leap2a_writer();
             $entry = new portfolio_format_leap2a_entry('assignmentonline' . $this->assignment->id, $this->assignment->name, 'resource', $html);
             $entry->add_category('web', 'resource_type');
             $entry->published = $submission->timecreated;
             $entry->updated = $submission->timemodified;
             $entry->author = $user;
             $leapwriter->add_entry($entry);
             if ($files = $exporter->get('caller')->get('multifiles')) {
                 $leapwriter->link_files($entry, $files, 'assignmentonline' . $this->assignment->id . 'file');
                 foreach ($files as $f) {
                     $exporter->copy_existing_file($f);
                 }
             }
             $exporter->write_new_file($leapwriter->to_xml(), $exporter->get('format')->manifest_name(), true);
         } else {
             debugging('invalid format class: ' . $exporter->get('formatclass'));
         }
     }
 }
Example #4
0
 /**
  * overridden constructor to set up the file.
  *
  */
 public function __construct($title, stored_file $file)
 {
     $id = portfolio_format_leap2a::file_id_prefix() . $file->get_id();
     parent::__construct($id, $title, 'resource');
     $this->referencedfile = $file;
     $this->published = $this->referencedfile->get_timecreated();
     $this->updated = $this->referencedfile->get_timemodified();
     $this->add_category('offline', 'resource_type');
 }