From e6e7e540ca4da5dca618851f0492c0d2dca86fc3 Mon Sep 17 00:00:00 2001 From: eileenmcnaugton Date: Tue, 29 Sep 2015 19:04:59 +1300 Subject: [PATCH] CRM-17225 add button allowing reports to be saved in view mode or criteria mode --- CRM/Report/BAO/ReportInstance.php | 8 ++++- CRM/Report/Form.php | 5 ++- CRM/Report/Form/Instance.php | 35 +++++++++++++++++-- api/v3/ReportInstance.php | 7 ++++ templates/CRM/Report/Form/Tabs/Instance.tpl | 2 +- .../phpunit/api/v3/SyntaxConformanceTest.php | 4 +++ 6 files changed, 56 insertions(+), 5 deletions(-) diff --git a/CRM/Report/BAO/ReportInstance.php b/CRM/Report/BAO/ReportInstance.php index 89dd47a3bb..adb089d2ae 100644 --- a/CRM/Report/BAO/ReportInstance.php +++ b/CRM/Report/BAO/ReportInstance.php @@ -160,6 +160,12 @@ class CRM_Report_BAO_ReportInstance extends CRM_Report_DAO_ReportInstance { unset($params['is_navigation']); } + $viewMode = !empty($params['view_mode']) ? $params['view_mode'] : FALSE; + if ($viewMode) { + // Do not save to the DB - it's saved in the url. + unset($params['view_mode']); + } + // add to dashboard $dashletParams = array(); if (!empty($params['addToDashboard'])) { @@ -185,7 +191,7 @@ class CRM_Report_BAO_ReportInstance extends CRM_Report_DAO_ReportInstance { if (empty($params['id']) && empty($params['instance_id']) && !empty($navigationParams['id'])) { unset($navigationParams['id']); } - $navigationParams['url'] = "civicrm/report/instance/{$instance->id}?reset=1"; + $navigationParams['url'] = "civicrm/report/instance/{$instance->id}" . ($viewMode == 'view' ? '?reset=1&force=1' : '?reset=1&output=criteria'); $navigation = CRM_Core_BAO_Navigation::add($navigationParams); if (!empty($navigationParams['is_active'])) { diff --git a/CRM/Report/Form.php b/CRM/Report/Form.php index 5d5899a934..280392cc3d 100644 --- a/CRM/Report/Form.php +++ b/CRM/Report/Form.php @@ -513,7 +513,10 @@ class CRM_Report_Form extends CRM_Core_Form { } // lets always do a force if reset is found in the url. - if (!empty($_REQUEST['reset'])) { + // 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') { $this->_force = 1; } diff --git a/CRM/Report/Form/Instance.php b/CRM/Report/Form/Instance.php index d09d2d2b37..f96e20b23e 100644 --- a/CRM/Report/Form/Instance.php +++ b/CRM/Report/Form/Instance.php @@ -107,6 +107,11 @@ class CRM_Report_Form_Instance { array('onclick' => "return showHideByValue('is_navigation','','navigation_menu','table-row','radio',false);") ); + $form->addElement('select', 'view_mode', ts('Configure link to...'), array( + 'view' => ts('View Results'), + 'criteria' => ts('Show Criteria'), + )); + $form->addElement('checkbox', 'addToDashboard', ts('Available for Dashboard?'), NULL, array('onclick' => "return showHideByValue('addToDashboard','','limit_result','table-row','radio',false);")); $form->addElement('checkbox', 'is_reserved', ts('Reserved Report?')); @@ -234,6 +239,21 @@ class CRM_Report_Form_Instance { "; + // CRM-17225 view_mode currently supports 'view' or 'criteria'. + // Prior to 4.7 'view' meant reset=1 in the url & if not set + // then show criteria. + // From 4.7 we will pro-actively set 'force=1' but still respect the old behaviour. + // we may look to add pdf, print_view, csv & various charts as these could simply + // be added to the url allowing us to conceptualise 'view right now' vs saved view + // & using a multiselect (option value?) could help here. + // Note that accessing reports without reset=1 in the url turns out to be + // dangerous as it seems to carry actions like 'delete' from one report to another. + $defaults['view_mode'] = 'view'; + $output = CRM_Utils_Request::retrieve('output', 'String'); + if ($output == 'criteria') { + $defaults['view_mode'] = 'criteria'; + } + if ($instanceID) { // this is already retrieved via Form.php $defaults['description'] = CRM_Utils_Array::value('description', $defaults); @@ -246,10 +266,13 @@ class CRM_Report_Form_Instance { CRM_Core_BAO_Navigation::retrieve($params, $navigationDefaults); $defaults['is_navigation'] = 1; $defaults['parent_id'] = CRM_Utils_Array::value('parent_id', $navigationDefaults); - if (!empty($navigationDefaults['is_active'])) { $form->assign('is_navigation', TRUE); } + // A saved view mode will over-ride any url assumptions. + if (strpos($navigationDefaults['url'], 'output=criteria')) { + $defaults['view_mode'] = 'criteria'; + } if (!empty($navigationDefaults['id'])) { $form->_navigation['id'] = $navigationDefaults['id']; @@ -320,6 +343,7 @@ class CRM_Report_Form_Instance { foreach ($unsetFields as $field) { unset($formValues[$field]); } + $view_mode = $formValues['view_mode']; // pass form_values as string $params['form_values'] = serialize($formValues); @@ -339,7 +363,14 @@ class CRM_Report_Form_Instance { CRM_Core_Session::setStatus($statusMsg); if ($redirect) { - CRM_Utils_System::redirect(CRM_Utils_System::url("civicrm/report/instance/{$instance->id}", "reset=1")); + $urlParams = array('reset' => 1); + if ($view_mode == 'view') { + $urlParams['force'] = 1; + } + else { + $urlParams['output'] = 'criteria'; + } + CRM_Utils_System::redirect(CRM_Utils_System::url("civicrm/report/instance/{$instance->id}", $urlParams)); } } diff --git a/api/v3/ReportInstance.php b/api/v3/ReportInstance.php index 7bbcd68eca..677a5fd908 100644 --- a/api/v3/ReportInstance.php +++ b/api/v3/ReportInstance.php @@ -67,6 +67,13 @@ function civicrm_api3_report_instance_create($params) { function _civicrm_api3_report_instance_create_spec(&$params) { $params['report_id']['api.required'] = 1; $params['title']['api.required'] = 1; + $params['view_mode']['api.default'] = 'view'; + $params['view_mode']['title'] = ts('View Mode for Navigation URL'); + $params['view_mode']['type'] = CRM_Utils_Type::T_STRING; + $params['view_mode']['options'] = array( + 'view' => ts('View'), + 'criteria' => ts('Show Criteria'), + ); } /** diff --git a/templates/CRM/Report/Form/Tabs/Instance.tpl b/templates/CRM/Report/Form/Tabs/Instance.tpl index 41cb80feb0..fa310c3fc4 100644 --- a/templates/CRM/Report/Form/Tabs/Instance.tpl +++ b/templates/CRM/Report/Form/Tabs/Instance.tpl @@ -66,7 +66,7 @@ - diff --git a/tests/phpunit/api/v3/SyntaxConformanceTest.php b/tests/phpunit/api/v3/SyntaxConformanceTest.php index 9738a9f896..0b37dcbead 100644 --- a/tests/phpunit/api/v3/SyntaxConformanceTest.php +++ b/tests/phpunit/api/v3/SyntaxConformanceTest.php @@ -630,6 +630,10 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { 'weight', //won't update as there is no 1 in the same price set ), ), + 'ReportInstance' => array( + // View mode is part of the navigation which is not retrieved by the api. + 'cant_return' => array('view_mode'), + ), 'SavedSearch' => array( // I think the fields below are generated based on form_values. 'cant_update' => array( -- 2.25.1
{$form.is_navigation.label}{$form.is_navigation.html}
+
{$form.is_navigation.html} {ts}Link to {/ts} {$form.view_mode.html}
{ts}All report instances are automatically included in the Report Listing page. Check this box to also add this report to the navigation menu.{/ts}