/** * Hooked method to marks a form as dirty (needs to be cached). * @param mixed $args. an array of two elements whose first element is a form object, the second is the user */ public function globalUpdate_hook($args) { if (!is_array($args) || !array_key_exists('form', $args)) { return; } $form = $args['form']; if ($form instanceof I2CE_Form) { $form = $form->getName(); } if (!is_string($form)) { return; } $reports = I2CE_CustomReport::getReports(); foreach ($reports as $report) { try { $rep = new I2CE_CustomReport($report); } catch (Exception $e) { continue; } if (I2CE_CustomReport::getStatus($report) == 'not_generated') { continue; } $forms = $rep->getFormsRequiredByReport(); if (!in_array($form, $forms)) { continue; } I2CE::raiseError("Dropping {$report} as it uses {$form} which has been changed in a global update"); $rep->dropTable(); } }
protected function displayExistingReports($contentNode, $transientOptions, $action) { $categories = $this->getReportsByCategory(); //now display the reports by category $catsNode = $this->template->appendFileById('customReports_reports_categories.html', 'div', 'existing_reports', false, $contentNode); if (!$catsNode instanceof DOMNode) { I2CE::raiseError("Could not add report categories template"); return false; } foreach ($categories as $cat => $reports) { $catNode = $this->template->appendFileById('customReports_reports_category.html', 'div', 'existing_reports_categories', false, $catsNode); if (!$catNode instanceof DOMNode) { I2CE::raiseError("Could not add report category template"); return false; } if (strlen($cat) == 0) { $cat = 'Uncategorized'; } $this->template->setDisplayDataImmediate('report_category', $cat, $catNode); foreach ($reports as $shortname) { $swissReport = $this->getChild($shortname); if (!$swissReport instanceof I2CE_Swiss_CustomReports_Report) { continue; } $name = $swissReport->getDisplayName(); $desc = $swissReport->getDescription(); if (!$name) { $name = $shortname; } $repNode = $this->template->appendFileById('customReports_reports_category_report.html', 'li', 'existing_reports_category', false, $catNode); if (!$repNode instanceof DOMNode) { I2CE::raiseError("Could not add report category template"); return false; } $reportStatus = I2CE_CustomReport::getStatus($shortname); if ($reportStatus == 'generated') { $reportLastGenerated = strftime("%c", I2CE_CustomReport::getLastGenerationTime($shortname)); } else { $reportLastGenerated = ''; } $reportHoomanStatus = I2CE_CustomReport::getStatus($shortname, true); $this->template->setDisplayDataImmediate('report_edit_link', $this->getURLRoot($action) . '/' . $shortname, $repNode); $this->template->setDisplayDataImmediate('report_save_link', $this->getURLRoot('export') . '/../' . $shortname . '?pipe=2', $repNode); $this->template->setDisplayDataImmediate('report_delete_link', $this->getURLRoot('delete') . '/../' . $shortname, $repNode); $this->template->setDisplayDataImmediate('report_generate_link', $this->getURLRoot('generate') . '/../' . $shortname, $repNode); $this->template->setDisplayDataImmediate('report_generate_force_link', $this->getURLRoot('generate_force') . '/../' . $shortname, $repNode); $this->template->setDisplayDataImmediate('report_name', $name, $repNode); $this->template->setDisplayDataImmediate('report_description', $desc, $repNode); $this->template->setDisplayDataImmediate('report_status', $reportHoomanStatus, $repNode); $this->template->setDisplayDataImmediate('report_last_generated', $reportLastGenerated, $repNode); } } return true; }
/** * The constuctor * @param I2CE_Page $page * @param string $view * @throws Excecption on error */ public function __construct($page, $view) { $this->page = $page; $this->template = $this->page->getTemplate(); $this->fieldMaps = array(); $this->formMaps = array(); $this->mappedFields = array(); $this->mappedValues = array(); $this->formObjs = array(); $this->display = 'Default'; if (preg_match('/^I2CE_CustomReport_Display_([a-zA-Z0-9_]+)$/', get_class($this), $matches)) { $this->display = $matches[1]; } $config = I2CE::getConfig()->modules->CustomReports; $this->displayConfig = $config->displays->{$this->display}; if (!isset($config->reportViews->{$view})) { throw new Exception("You specified an invalid report view ({$view})"); } $this->view = $view; $this->config = $config->reportViews->{$view}; if (!I2CE_CustomReport::reportExists($this->config->report)) { throw new Exception("View refers to nonexistent report {$this->config->report}"); } $status = I2CE_CustomReport::getStatus($this->config->report); if (!$status || $status == 'not_generated' || $status == 'failed') { throw new Exception("Report for {$this->config->report} has not been generated"); } $this->reportObj = new I2CE_CustomReport($this->config->report); //may throw an error. don't catch it $this->reportConfig = $config->reports->{$this->config->report}; if (!$this->reportConfig instanceof I2CE_MagicDataNode) { throw new Exception("Report {$this->config->report} is invalid"); } if (!isset($this->reportConfig->relationship) || !$this->reportConfig->relationship) { throw new Exception("View refers to nonexistent relationship {$this->reportConfig->relationship}"); } $this->relationshipConfig = $config->relationships->{$this->reportConfig->relationship}; if (!$this->relationshipConfig instanceof I2CE_MagicDataNode) { throw new Exception("Report relationship {$this->reportConfig->relationship} is invalid"); } $this->defaultOptions = $this->getDefaultOptions($this->page->request(), array()); if (!is_array($this->defaultOptions)) { throw new Exception("Cannot get display options"); } if (!$this->canView()) { throw new Exception("Cannot look at view {$this->view}"); } }