Esempio n. 1
0
 public function initialise_form()
 {
     global $CFG, $USER;
     require_once $CFG->dirroot . '/mod/dialogue/formlib.php';
     $cm = $this->dialogue->cm;
     $context = $this->dialogue->context;
     $dialogueid = $this->dialogue->dialogueid;
     $conversationid = $this->conversation->conversationid;
     $form = new \mod_dialogue_reply_form('reply.php');
     // point specifically
     // setup important hiddens
     $form->set_data(array('id' => $cm->id));
     $form->set_data(array('dialogueid' => $dialogueid));
     $form->set_data(array('conversationid' => $conversationid));
     $form->set_data(array('messageid' => $this->_messageid));
     if (is_null($this->_messageid)) {
         $form->set_data(array('action' => 'create'));
     } else {
         $form->set_data(array('action' => 'edit'));
     }
     // setup body, set new $draftitemid directly on _bodydraftid and rewritten
     // html on _body
     $this->_body = file_prepare_draft_area($this->_bodydraftid, $context->id, 'mod_dialogue', 'message', $this->_messageid, \mod_dialogue_reply_form::editor_options(), $this->_body);
     $form->set_data(array('body' => array('text' => $this->_body, 'format' => $this->_bodyformat, 'itemid' => $this->_bodydraftid)));
     // setup attachments, set new $draftitemid directly on _attachmentsdraftid
     file_prepare_draft_area($this->_attachmentsdraftid, $context->id, 'mod_dialogue', 'attachment', $this->_messageid, \mod_dialogue_reply_form::attachment_options());
     // using a post array for attachments
     $form->set_data(array('attachments[itemid]' => $this->_attachmentsdraftid));
     // remove any form buttons the user shouldn't have
     if ($this->conversation->state == dialogue::STATE_CLOSED) {
         $form->remove_from_group('send', 'actionbuttongroup');
     }
     // remove any unecessary buttons
     if ($USER->id != $this->author->id or is_null($this->messageid)) {
         $form->remove_from_group('delete', 'actionbuttongroup');
     }
     // remove any unecessary buttons
     if ($USER->id != $this->author->id or is_null($this->messageid)) {
         $form->remove_from_group('trash', 'actionbuttongroup');
     }
     return $this->_form = $form;
 }