function getReportOutputAsCsv($reportClass, $inputParams)
 {
     $config = CRM_Core_Config::singleton();
     $config->keyDisable = TRUE;
     $controller = new CRM_Core_Controller_Simple($reportClass, ts('some title'));
     $tmpReportVal = explode('_', $reportClass);
     $reportName = array_pop($tmpReportVal);
     $reportObj =& $controller->_pages[$reportName];
     $tmpGlobals = array();
     $tmpGlobals['_REQUEST']['force'] = 1;
     $tmpGlobals['_GET'][$config->userFrameworkURLVar] = 'civicrm/placeholder';
     $tmpGlobals['_SERVER']['QUERY_STRING'] = '';
     if (!empty($inputParams['fields'])) {
         $fields = implode(',', $inputParams['fields']);
         $tmpGlobals['_GET']['fld'] = $fields;
         $tmpGlobals['_GET']['ufld'] = 1;
     }
     if (!empty($inputParams['filters'])) {
         foreach ($inputParams['filters'] as $key => $val) {
             $tmpGlobals['_GET'][$key] = $val;
         }
     }
     if (!empty($inputParams['group_bys'])) {
         $groupByFields = implode(' ', $inputParams['group_bys']);
         $tmpGlobals['_GET']['gby'] = $groupByFields;
     }
     CRM_Utils_GlobalStack::singleton()->push($tmpGlobals);
     try {
         $reportObj->storeResultSet();
         $reportObj->buildForm();
         $rows = $reportObj->getResultSet();
         $tmpFile = $this->createTempDir() . CRM_Utils_File::makeFileName('CiviReport.csv');
         $csvContent = CRM_Report_Utils_Report::makeCsv($reportObj, $rows);
         file_put_contents($tmpFile, $csvContent);
     } catch (Exception $e) {
         // print_r($e->getCause()->getUserInfo());
         CRM_Utils_GlobalStack::singleton()->pop();
         throw $e;
     }
     CRM_Utils_GlobalStack::singleton()->pop();
     return $tmpFile;
 }
Ejemplo n.º 2
0
 /**
  * Temporarily override global variables and ensure that the variable data.
  * is set as expected (before/during/after the override).
  */
 public function testPushPop()
 {
     global $_FOO, $_EXTRA;
     $_FOO['bar'] = 1;
     $_FOO['whiz'] = 1;
     $_EXTRA = 1;
     $this->assertEquals(1, $_FOO['bar']);
     $this->assertEquals(1, $_FOO['whiz']);
     $this->assertFalse(isset($_FOO['bang']));
     $this->assertEquals(1, $_EXTRA);
     CRM_Utils_GlobalStack::singleton()->push(array('_FOO' => array('bar' => 2, 'bang' => 2), '_EXTRA' => 2));
     $this->assertEquals(2, $_FOO['bar']);
     $this->assertEquals(1, $_FOO['whiz']);
     $this->assertEquals(2, $_FOO['bang']);
     $this->assertEquals(2, $_EXTRA);
     CRM_Utils_GlobalStack::singleton()->pop();
     $this->assertEquals(1, $_FOO['bar']);
     $this->assertEquals(1, $_FOO['whiz']);
     $this->assertEquals(NULL, $_FOO['bang']);
     $this->assertEquals(1, $_EXTRA);
 }