public function approveSubmission(Workflow_SubmissionModel $model, $draft)
{
$settings = craft()->workflow->getSettings();
// Fire an 'onBeforeApproveSubmission' event
$event = new Event($this, array('submission' => $model));
$this->onBeforeApproveSubmission($event);
// Allow event to cancel submission saving
if (!$event->performAction) {
return false;
}
// Check for approving a Draft - need to publish not just save
if ($draft) {
$draft->enabled = true;
craft()->entryRevisions->publishDraft($draft);
// The Draft entry has now been deleted, so we don't need to update the submission record
// because it no also doesn't exist (due to cascade deleting of records)
$result = true;
} else {
$entry = craft()->entries->getEntryById($model->owner->id);
$entry->enabled = true;
craft()->entries->saveEntry($entry);
// Then, update our submission record with the necessary information
$result = $this->save($model);
}
// Fire an 'onSaveSubmission' event
$this->onApproveSubmission(new Event($this, array('submission' => $model)));
// Trigger notification to editor
if ($settings->editorNotifications) {
$this->_sendEditorNotificationEmail($model);
}
return $result;
}