function _createDraft($vars) { $field_list = array('response', 'note', 'answer', 'body', 'message', 'issue'); foreach ($field_list as $field) { if (isset($_POST[$field])) { $vars['body'] = urldecode($_POST[$field]); break; } } if (!isset($vars['body'])) { return Http::response(422, "Draft body not found in request"); } $errors = array(); if (!($draft = Draft::create($vars, $errors))) { Http::response(500, print_r($errors, true)); } // If the draft is created from an existing document, ensure inline // attachments from the cloned document are attachned to the draft // XXX: Actually, I think this is just wasting time, because the // other object already has the items attached, so the database // won't clean up the files. They don't have to be attached to // the draft for Draft::getAttachmentIds to return the id of the // attached file //$draft->syncExistingAttachments(); echo JsonDataEncoder::encode(array('draft_id' => $draft->getId())); }
/** * save the proposal as a draft */ public function create_draft() { $draft = new Draft; $draft->proposal = $this->id; $draft->title = $this->title; $draft->content = $this->content; $draft->reason = $this->reason; if (Login::$member) { $draft->author = Login::$member->id; } else { // admin $draft->author = null; } $draft->create(); }