original_string: function prepare_package() {
          global $CFG;
  
          // set up the leap2a writer if we need it
          $writingleap = false;
          if ($this->exporter->get('formatclass') == PORTFOLIO_FORMAT_LEAP2A) {
              $leapwriter = $this->exporter->get('format')->leap2a_writer();
              $writingleap = true;
          }
          if ($this->attachment) { // simplest case first - single file attachment
              $this->copy_files(array($this->singlefile), $this->attachment);
              if ($writingleap) { // if we're writing leap, make the manifest to go along with the file
                  $entry = new portfolio_format_leap2a_file($this->singlefile->get_filename(), $this->singlefile);
                  $leapwriter->add_entry($entry);
                  return $this->exporter->write_new_file($leapwriter->to_xml(), $this->exporter->get('format')->manifest_name(), true);
              }
  
          } else if (empty($this->post)) {  // exporting whole discussion
              $content = ''; // if we're just writing HTML, start a string to add each post to
              $ids = array(); // if we're writing leap2a, keep track of all entryids so we can add a selection element
              foreach ($this->posts as $post) {
                  $posthtml =  $this->prepare_post($post);
                  if ($writingleap) {
                      $ids[] = $this->prepare_post_leap2a($leapwriter, $post, $posthtml);
                  } else {
                      $content .= $posthtml . '<br /><br />';
                  }
              }
              $this->copy_files($this->multifiles);
              $name = 'discussion.html';
              $manifest = ($this->exporter->get('format') instanceof PORTFOLIO_FORMAT_RICH);
              if ($writingleap) {
                  // add on an extra 'selection' entry
                  $selection = new portfolio_format_leap2a_entry('forumdiscussion' . $this->discussionid,
                      get_string('discussion', 'forum') . ': ' . $this->discussion->name, 'selection');
                  $leapwriter->add_entry($selection);
                  $leapwriter->make_selection($selection, $ids, 'Grouping');
                  $content = $leapwriter->to_xml();
                  $name = $this->get('exporter')->get('format')->manifest_name();
              }
              $this->get('exporter')->write_new_file($content, $name, $manifest);
  
          } else { // exporting a single post
              $posthtml = $this->prepare_post($this->post);
  
              $content = $posthtml;
              $name = 'post.html';
              $manifest = ($this->exporter->get('format') instanceof PORTFOLIO_FORMAT_RICH);
  
              if ($writingleap) {
                  $this->prepare_post_leap2a($leapwriter, $this->post, $posthtml);
                  $content = $leapwriter->to_xml();
                  $name = $this->exporter->get('format')->manifest_name();
              }
              $this->copy_files($this->multifiles);
              $this->get('exporter')->write_new_file($content, $name, $manifest);
          }
      }
code: function prepare_package() {
          global $CFG;
  
          // set up the leap2a writer if we need it
          $writingleap = false;
          if ($this->exporter->get('formatclass') == PORTFOLIO_FORMAT_LEAP2A) {
              $leapwriter = $this->exporter->get('format')->leap2a_writer();
              $writingleap = true;
          }
          if ($this->attachment) { // simplest case first - single file attachment
              $this->copy_files(array($this->singlefile), $this->attachment);
              if ($writingleap) { // if we're writing leap, make the manifest to go along with the file
                  $entry = new portfolio_format_leap2a_file($this->singlefile->get_filename(), $this->singlefile);
                  $leapwriter->add_entry($entry);
                  return $this->exporter->write_new_file($leapwriter->to_xml(), $this->exporter->get('format')->manifest_name(), true);
              }
  
          } else if (empty($this->post)) {  // exporting whole discussion
              $content = ''; // if we're just writing HTML, start a string to add each post to
              $ids = array(); // if we're writing leap2a, keep track of all entryids so we can add a selection element
              foreach ($this->posts as $post) {
                  $posthtml =  $this->prepare_post($post);
                  if ($writingleap) {
                      $ids[] = $this->prepare_post_leap2a($leapwriter, $post, $posthtml);
                  } else {
                      $content .= $posthtml . '<br /><br />';
                  }
              }
              $this->copy_files($this->multifiles);
              $name = 'discussion.html';
              $manifest = ($this->exporter->get('format') instanceof PORTFOLIO_FORMAT_RICH);
              if ($writingleap) {
                  // add on an extra 'selection' entry
                  $selection = new portfolio_format_leap2a_entry('forumdiscussion' . $this->discussionid,
                      get_string('discussion', 'forum') . ': ' . $this->discussion->name, 'selection');
                  $leapwriter->add_entry($selection);
                  $leapwriter->make_selection($selection, $ids, 'Grouping');
                  $content = $leapwriter->to_xml();
                  $name = $this->get('exporter')->get('format')->manifest_name();
              }
              $this->get('exporter')->write_new_file($content, $name, $manifest);
  
          } else { // exporting a single post
              $posthtml = $this->prepare_post($this->post);
  
              $content = $posthtml;
              $name = 'post.html';
              $manifest = ($this->exporter->get('format') instanceof PORTFOLIO_FORMAT_RICH);
  
              if ($writingleap) {
                  $this->prepare_post_leap2a($leapwriter, $this->post, $posthtml);
                  $content = $leapwriter->to_xml();
                  $name = $this->exporter->get('format')->manifest_name();
              }
              $this->copy_files($this->multifiles);
              $this->get('exporter')->write_new_file($content, $name, $manifest);
          }
      }
code_tokens: function prepare_package ( ) { global $ CFG ; // set up the leap2a writer if we need it $ writingleap = false ; if ( $ this -> exporter -> get ( 'formatclass' ) == PORTFOLIO_FORMAT_LEAP2A ) { $ leapwriter = $ this -> exporter -> get ( 'format' ) -> leap2a_writer ( ) ; $ writingleap = true ; } if ( $ this -> attachment ) { // simplest case first - single file attachment $ this -> copy_files ( array ( $ this -> singlefile ) , $ this -> attachment ) ; if ( $ writingleap ) { // if we're writing leap, make the manifest to go along with the file $ entry = new portfolio_format_leap2a_file ( $ this -> singlefile -> get_filename ( ) , $ this -> singlefile ) ; $ leapwriter -> add_entry ( $ entry ) ; return $ this -> exporter -> write_new_file ( $ leapwriter -> to_xml ( ) , $ this -> exporter -> get ( 'format' ) -> manifest_name ( ) , true ) ; } } else if ( empty ( $ this -> post ) ) { // exporting whole discussion $ content = '' ; // if we're just writing HTML, start a string to add each post to $ ids = array ( ) ; // if we're writing leap2a, keep track of all entryids so we can add a selection element foreach ( $ this -> posts as $ post ) { $ posthtml = $ this -> prepare_post ( $ post ) ; if ( $ writingleap ) { $ ids [ ] = $ this -> prepare_post_leap2a ( $ leapwriter , $ post , $ posthtml ) ; } else { $ content .= $ posthtml . '<br /><br />' ; } } $ this -> copy_files ( $ this -> multifiles ) ; $ name = 'discussion.html' ; $ manifest = ( $ this -> exporter -> get ( 'format' ) instanceof PORTFOLIO_FORMAT_RICH ) ; if ( $ writingleap ) { // add on an extra 'selection' entry $ selection = new portfolio_format_leap2a_entry ( 'forumdiscussion' . $ this -> discussionid , get_string ( 'discussion' , 'forum' ) . ': ' . $ this -> discussion -> name , 'selection' ) ; $ leapwriter -> add_entry ( $ selection ) ; $ leapwriter -> make_selection ( $ selection , $ ids , 'Grouping' ) ; $ content = $ leapwriter -> to_xml ( ) ; $ name = $ this -> get ( 'exporter' ) -> get ( 'format' ) -> manifest_name ( ) ; } $ this -> get ( 'exporter' ) -> write_new_file ( $ content , $ name , $ manifest ) ; } else { // exporting a single post $ posthtml = $ this -> prepare_post ( $ this -> post ) ; $ content = $ posthtml ; $ name = 'post.html' ; $ manifest = ( $ this -> exporter -> get ( 'format' ) instanceof PORTFOLIO_FORMAT_RICH ) ; if ( $ writingleap ) { $ this -> prepare_post_leap2a ( $ leapwriter , $ this -> post , $ posthtml ) ; $ content = $ leapwriter -> to_xml ( ) ; $ name = $ this -> exporter -> get ( 'format' ) -> manifest_name ( ) ; } $ this -> copy_files ( $ this -> multifiles ) ; $ this -> get ( 'exporter' ) -> write_new_file ( $ content , $ name , $ manifest ) ; } }
docstring: either a whole discussion
  a single post, with or without attachment
  or just an attachment with no post
  
  @global object
  @global object
  @uses PORTFOLIO_FORMAT_RICH
  @return mixed
docstring_tokens: either a whole discussion a single post with or without attachment or just an attachment with no post