*/
protected $tabs = array();
+ /**
+ * Should we add paging.
+ *
+ * @var bool
+ */
+ protected $addPaging = TRUE;
+
/**
* An attribute for checkbox/radio form field layout
*
* This can be set to specify a limit to the number of rows
* Since it is currently envisaged as part of the api usage it is only being applied
* when $_output mode is not 'html' or 'group' so as not to have to interpret / mess with that part
- * of the code (see limit() fn
+ * of the code (see limit() fn.
+ *
* @var integer
*/
protected $_limitValue = NULL;
protected $_selectedTables;
/**
- * Output mode e.g 'print', 'csv', 'pdf'
+ * Output mode e.g 'print', 'csv', 'pdf'.
+ *
* @var string
*/
protected $_outputMode;
+ /**
+ * Format of any chart in use.
+ *
+ * (it's unclear if this could be merged with outputMode at this stage)
+ *
+ * @var
+ */
+ protected $_format;
+
public $_having = NULL;
public $_select = NULL;
public $_selectClauses = array();
$this->_formValues = NULL;
}
+ $this->setOutputMode();
+
+ if ($this->_outputMode == 'copy') {
+ $this->_createNew = ($this->_outputMode == 'copy');
+ $this->_params = $this->_formValues;
+ $this->_params['view_mode'] = 'criteria';
+ $this->_params['title'] = ts('(copy)') . $this->getTitle();
+ // Do not pass go. Do not collect another chance to re-run the same query.
+ CRM_Report_Form_Instance::postProcess($this);
+ }
+
// lets always do a force if reset is found in the url.
// Hey why not? see CRM-17225 for more about this. The use of reset to be force is historical for reasons stated
// in the comment line above these 2.
- if (!empty($_REQUEST['reset']) && CRM_Utils_Request::retrieve('output', 'String') != 'criteria'
- && CRM_Utils_Request::retrieve('output', 'String') != 'save') {
+ if (!empty($_REQUEST['reset'])
+ && !in_array(CRM_Utils_Request::retrieve('output', 'String'), array('save', 'criteria'))) {
$this->_force = 1;
}
$this->_offsetValue = $_offsetValue;
}
+ /**
+ * Setter for $addPaging.
+ *
+ * @param bool $value
+ */
+ public function setAddPaging($value) {
+ $this->addPaging = $value;
+ }
+
/**
* Getter for $_defaultValues.
*
* Set output mode.
*/
public function processReportMode() {
- $buttonName = $this->controller->getButtonName();
-
- $output = CRM_Utils_Request::retrieve(
- 'output',
- 'String',
- CRM_Core_DAO::$_nullObject
- );
+ $this->setOutputMode();
$this->_sendmail
= CRM_Utils_Request::retrieve(
$printOnly = FALSE;
$this->assign('printOnly', FALSE);
- if ($this->_printButtonName == $buttonName || $output == 'print' ||
- ($this->_sendmail && !$output)
+ if ($this->_outputMode == 'print' ||
+ ($this->_sendmail && !$this->_outputMode)
) {
$this->assign('printOnly', TRUE);
$printOnly = TRUE;
+ $this->addPaging = FALSE;
$this->assign('outputMode', 'print');
$this->_outputMode = 'print';
if ($this->_sendmail) {
$this->_absoluteUrl = TRUE;
}
}
- elseif ($this->_pdfButtonName == $buttonName || $output == 'pdf') {
- $this->assign('printOnly', TRUE);
+ elseif ($this->_outputMode == 'pdf') {
$printOnly = TRUE;
- $this->assign('outputMode', 'pdf');
- $this->_outputMode = 'pdf';
+ $this->addPaging = FALSE;
$this->_absoluteUrl = TRUE;
}
- elseif ($this->_csvButtonName == $buttonName || $output == 'csv') {
- $this->assign('printOnly', TRUE);
+ elseif ($this->_outputMode == 'csv') {
$printOnly = TRUE;
- $this->assign('outputMode', 'csv');
- $this->_outputMode = 'csv';
$this->_absoluteUrl = TRUE;
+ $this->addPaging = FALSE;
}
- elseif ($this->_groupButtonName == $buttonName || $output == 'group') {
+ elseif ($this->_outputMode == 'group') {
$this->assign('outputMode', 'group');
- $this->_outputMode = 'group';
}
- elseif ($output == 'create_report' && $this->_criteriaForm) {
+ elseif ($this->_outputMode == 'create_report' && $this->_criteriaForm) {
$this->assign('outputMode', 'create_report');
- $this->_outputMode = 'create_report';
}
- else {
- $this->assign('outputMode', 'html');
- $this->_outputMode = 'html';
+ elseif ($this->_outputMode == 'copy' && $this->_criteriaForm) {
+ $this->_createNew = TRUE;
}
+ $this->assign('outputMode', $this->_outputMode);
+ $this->assign('printOnly', $printOnly);
// Get today's date to include in printed reports
if ($printOnly) {
$reportDate = CRM_Utils_Date::customFormat(date('Y-m-d H:i'));
* Post Processing function for Form.
*
* postProcessCommon should be used to set other variables from input as the api accesses that function.
+ * This function is not accessed when the api calls the report.
*/
public function beginPostProcess() {
$this->setParams($this->controller->exportValues($this->_name));
-
if (empty($this->_params) &&
$this->_force
) {
) {
$this->assign('updateReportButton', TRUE);
}
+
$this->processReportMode();
+
+ if ($this->_outputMode == 'save' || $this->_outputMode == 'copy') {
+ $this->_createNew = ($this->_outputMode == 'copy');
+ // Do not pass go. Do not collect another chance to re-run the same query.
+ // This will be called from the button - there is an earlier response to the url
+ // perhaps they can still be consolidated more.
+ CRM_Report_Form_Instance::postProcess($this);
+ }
$this->beginPostProcessCommon();
}
$group = $this->_params['groups'];
$this->add2group($group);
}
- elseif ($this->_instanceButtonName == $this->controller->getButtonName()) {
- CRM_Report_Form_Instance::postProcess($this);
- }
- elseif ($this->_createNewButtonName == $this->controller->getButtonName() ||
- $this->_outputMode == 'create_report'
- ) {
- $this->_createNew = TRUE;
- CRM_Report_Form_Instance::postProcess($this);
- }
}
/**
if ($this->_dashBoardRowCount) {
$rowCount = $this->_dashBoardRowCount;
}
- if ($this->_outputMode == 'html' || $this->_outputMode == 'group') {
+ if ($this->addPaging) {
$this->_select = str_ireplace('SELECT ', 'SELECT SQL_CALC_FOUND_ROWS ', $this->_select);
$pageId = CRM_Utils_Request::retrieve('crmPID', 'Integer', CRM_Core_DAO::$_nullObject);
$query->_from .= $from;
}
+ /**
+ * Get label for show results buttons.
+ *
+ * @return string
+ */
+ public function getResultsLabel() {
+ $showResultsLabel = $this->resultsDisplayed() ? ts('Refresh results') : ts('View results');
+ return $showResultsLabel;
+ }
+
+ /**
+ * Determine the output mode from the url or input.
+ *
+ * Output could be
+ * - pdf : Render as pdf
+ * - csv : Render as csv
+ * - print : Render in print format
+ * - save : save the report and display the new report
+ * - copy : save the report as a new instance and display that.
+ * - group : go to the add to group screen.
+ *
+ * Potentially chart variations could also be included but the complexity
+ * is that we might print a bar chart as a pdf.
+ */
+ protected function setOutputMode() {
+ $buttonName = $this->controller->getButtonName();
+ $this->_outputMode = CRM_Utils_Request::retrieve(
+ 'output',
+ 'String',
+ CRM_Core_DAO::$_nullObject,
+ FALSE,
+ CRM_Utils_Array::value('task', $this->_params)
+ );
+
+ if ($buttonName) {
+ if ($buttonName == $this->_instanceButtonName) {
+ $this->_outputMode = 'save';
+ }
+ if ($buttonName == $this->_printButtonName) {
+ $this->_outputMode = 'print';
+ }
+ if ($buttonName == $this->_pdfButtonName) {
+ $this->_outputMode = 'pdf';
+ }
+ if ($this->_csvButtonName == $buttonName) {
+ $this->_outputMode = 'csv';
+ }
+ if ($this->_groupButtonName == $buttonName) {
+ $this->_outputMode = 'group';
+ }
+ if ($buttonName == $this->_createNewButtonName) {
+ $this->_outputMode = 'copy';
+ }
+ }
+ }
+
}
*
* @return array
*/
- public function &info() {
+ public function info() {
$report = '';
if ($this->ovID) {
}
$sql = "
- SELECT inst.id, inst.title, inst.report_id, inst.description, v.label, v.grouping,
+ SELECT inst.id, inst.title, inst.report_id, inst.description, v.label, v.grouping, v.name as class_name,
CASE
WHEN comp.name IS NOT NULL THEN SUBSTRING(comp.name, 5)
WHEN v.grouping IS NOT NULL THEN v.grouping
$rows[$dao->compName][$dao->id]['title'] = $dao->title;
$rows[$dao->compName][$dao->id]['label'] = $dao->label;
$rows[$dao->compName][$dao->id]['description'] = $dao->description;
- $rows[$dao->compName][$dao->id]['url'] = CRM_Utils_System::url("{$url}/{$dao->id}", "reset=1");
- if (CRM_Core_Permission::check('administer Reports')) {
- $rows[$dao->compName][$dao->id]['deleteUrl'] = CRM_Utils_System::url("{$url}/{$dao->id}", 'action=delete&reset=1');
- }
+ $rows[$dao->compName][$dao->id]['url'] = CRM_Utils_System::url("{$url}/{$dao->id}", "reset=1&output=criteria");
+ $rows[$dao->compName][$dao->id]['viewUrl'] = CRM_Utils_System::url("{$url}/{$dao->id}", 'force=1&reset=1');
+ $rows[$dao->compName][$dao->id]['actions'] = $this->getActionLinks($dao->id, $dao->class_name);
}
}
return $rows;
return parent::run();
}
+ /**
+ * Get action links.
+ *
+ * @param int $instanceID
+ * @param string $className
+ *
+ * @return array
+ */
+ protected function getActionLinks($instanceID, $className) {
+ $urlCommon = 'civicrm/report/instance/' . $instanceID;
+ $actions = array(
+ 'copy' => array(
+ 'url' => CRM_Utils_System::url($urlCommon, 'reset=1&output=copy'),
+ 'label' => ts('Save a Copy'),
+ ),
+ 'pdf' => array(
+ 'url' => CRM_Utils_System::url($urlCommon, 'reset=1&force=1&output=pdf'),
+ 'label' => ts('View as pdf'),
+ ),
+ 'print' => array(
+ 'url' => CRM_Utils_System::url($urlCommon, 'reset=1&force=1&output=print'),
+ 'label' => ts('Print report'),
+ ),
+ );
+ // Hackery, Hackera, Hacker ahahahahahaha a super nasty hack.
+ // Almost all report classes support csv & loading each class to call the method seems too
+ // expensive. We also have on our later list 'do they support charts' which is instance specific
+ // e.g use of group by might affect it. So, lets just skip for the few that don't for now.
+ $csvBlackList = array(
+ 'CRM_Report_Form_Contact_Detail',
+ 'CRM_Report_Form_Event_Income',
+ );
+ if (!in_array($className, $csvBlackList)) {
+ $actions['csv'] = array(
+ 'url' => CRM_Utils_System::url($urlCommon, 'reset=1&force=1&output=csv'),
+ 'label' => ts('Export to csv'),
+ );
+ }
+ if (CRM_Core_Permission::check('administer Reports')) {
+ $actions['delete'] = array(
+ 'url' => CRM_Utils_System::url($urlCommon, 'reset=1&action=delete'),
+ 'label' => ts('Delete report'),
+ 'confirm_message' => ts('Are you sure you want delete this report? This action cannot be undone.'),
+ );
+ }
+
+ return $actions;
+ }
+
}