コード例 #1
0
 /**
  * Prints the content of this draft as a JavaScript variable (including
  * surrounding script tag).
  * @param mod_forumng $forum Forum object
  * @return string HTML (including JS) code to place in page
  */
 public function prepare_edit_js($forum)
 {
     global $USER;
     // Copy fields
     $fields = clone $this->draftfields;
     // Prepare file areas
     $fileoptions = array('subdirs' => false, 'maxbytes' => $forum->get_max_bytes());
     $filecontext = $forum->get_context(true);
     // Prepare draft area for attachments
     $draftitemid = 0;
     file_prepare_draft_area($draftitemid, $filecontext->id, 'mod_forumng', 'draft', $this->get_id(), $fileoptions);
     // Prepare draft area for message files
     $messagedraftitemid = 0;
     $fields->message = file_prepare_draft_area($messagedraftitemid, $filecontext->id, 'mod_forumng', 'draftmessage', $this->get_id(), $fileoptions, $fields->message);
     // Get list of files for main attachment area
     $options = file_get_drafarea_files($draftitemid, '/');
     $usercontext = context_user::instance($USER->id);
     $fs = get_file_storage();
     $files = $fs->get_area_files($usercontext->id, 'user', 'draft', $options->itemid, 'id', false);
     $options->filecount = count($files);
     $fields->attachmentoptions = $options;
     // Get list of files for message area
     $messageoptions = file_get_drafarea_files($messagedraftitemid, '/');
     $files = $fs->get_area_files($usercontext->id, 'user', 'draft', $messageoptions->itemid, 'id', false);
     $messageoptions->filecount = count($files);
     $fields->messageoptions = $messageoptions;
     // Unset things we don't need in JS
     unset($fields->discussionid);
     unset($fields->discussionsubject);
     unset($fields->courseid);
     unset($fields->replytouser);
     unset($fields->options);
     unset($fields->attachments);
     // Add options
     foreach ((array) $this->get_options() as $key => $value) {
         $fields->{$key} = $value;
     }
     return "<script type='text/javascript'>\n" . "var forumng_draft = " . json_encode($fields) . ";\n</script>\n";
 }