protected function actionGenerate($force)
 {
     /* Why not allow multiple reports to generate at once?
        if (count($this->request_remainder) > 1 ) {
            I2CE::raiseError("Requested generation of invalid report " . implode('/', $this->request_remainder));
            return false;
        }
        */
     if (count($this->request_remainder) == 0) {
         $config = I2CE::getConfig()->modules->CustomReports;
         $config->generate_all->volatile(true);
         $timeConfig = I2CE::getConfig()->traverse('/modules/CustomReports/times', true);
         $timeConfig->volatile(true);
         $fail_time = null;
         $timeConfig->setIfIsSet($fail_time, 'fail');
         if (!is_integer($fail_time)) {
             $fail_time = 600;
         }
         $fail_time = (int) ((int) $fail_time * 60);
         $generation = 0;
         $timeConfig->setIfIsSet($generation, "generate_all/time");
         if (!(is_integer($generation) || ctype_digit($generation)) || (int) $generation < 1) {
             $generation = 0;
         }
         $generation = (int) $generation;
         $config->setIfIsSet($status, 'generate_all/status');
         if ($status === 'in_progress' && (!$force || time() - $generation < $fail_time)) {
             I2CE::raiseError("In progress");
             return true;
         }
         $config->generate_all->status = 'in_progress';
         $config->generate_all->time = time();
         //update the time
         $reports = I2CE::getConfig()->modules->CustomReports->reports->getKeys();
         $all = true;
     } else {
         $reports = $this->request_remainder;
         $all = false;
     }
     //         //generate caches.
     //         $wrangler = new I2CE_Wrangler();
     //         $cachedFormPage = $wrangler->getPage('CachedForms','cacheAll');
     //         if ($cachedFormPage instanceof I2CE_Page) {
     //             $cachedFormPage->cacheAll();
     //         }
     $errors = array();
     foreach ($reports as $report) {
         if (!I2CE_CustomReport::reportExists($report)) {
             I2CE::raiseError("Requested generation of report {$report} which does not exist");
             $errors[] = "Requested generation of report {$report} which does not exist";
             continue;
         }
         try {
             $reportObj = new I2CE_CustomReport($report);
         } catch (Exception $e) {
             $errors[] = "Could not instantiate the report {$report}";
             continue;
         }
         if (!$reportObj->generateCache($force)) {
             $errors[] = "Could not generate report for {$report}";
         }
     }
     foreach ($errors as $error) {
         $this->userMessage($error, 'notice');
     }
     if ($all) {
         if (count($errors) > 0) {
             $config->generate_all->status = 'failed';
         } else {
             $config->generate_all->status = 'done';
         }
         $config->generate_all->time = time();
     }
     return count($errors) == 0;
 }
 /**
  * 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}");
     }
 }