/** * Create a new report * * @param array $data * @param Form $form */ public function createreport($data, $form) { // assume a user's okay if they can edit the reportholder // @TODO have a new create permission here? if ($this->data()->canEdit()) { $type = $data['ReportType']; $classes = ClassInfo::subclassesFor('AdvancedReport'); if (!in_array($type, $classes)) { throw new Exception("Invalid report type"); } $report = new ReportPage(); $report->Title = $data['ReportName']; $report->MetaDescription = isset($data['ReportDescription']) ? $data['ReportDescription'] : ''; $report->ReportType = $type; $report->ParentID = $this->data()->ID; $oldMode = Versioned::get_reading_mode(); Versioned::reading_stage('Stage'); $report->write(); $report->doPublish(); Versioned::reading_stage('Live'); $this->redirect($report->Link()); } else { $form->sessionMessage(_t('ReporHolder.NO_PERMISSION', 'You do not have permission to do that'), 'warning'); $this->redirect($this->data()->Link()); } }
public function doCreate($data, $form) { if (!singleton('AdvancedReport')->canCreate()) { return Security::permissionFailure($this); } $data = $form->getData(); $description = $data['Description']; $class = $data['ClassName']; if (!is_subclass_of($class, 'AdvancedReport')) { $form->addErrorMessage('ClassName', _t('ReportHolder.INVALID_TYPE', 'An invalid report type was selected'), 'required'); return $this->redirectBack(); } $page = new ReportPage(); $page->update(array('Title' => $data['Title'], 'Content' => $description ? "<p>{$description}</p>" : '', 'ReportType' => $class, 'ParentID' => $this->data()->ID)); $page->writeToStage('Stage'); if (Versioned::current_stage() == Versioned::get_live_stage()) { $page->doPublish(); } return $this->redirect($page->Link()); }