From 02d451ab182db97db8d0d93e35e4099072be7df6 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Tue, 15 Sep 2015 12:56:37 +1200 Subject: [PATCH] CRM-17144 add ability for permissioned user to see report sql --- CRM/Core/Permission.php | 1 + CRM/Report/Form.php | 39 ++++++++++++++++++++ CRM/Report/Info.php | 4 ++ templates/CRM/Report/Form/Tabs/Developer.tpl | 3 ++ 4 files changed, 47 insertions(+) create mode 100644 templates/CRM/Report/Form/Tabs/Developer.tpl diff --git a/CRM/Core/Permission.php b/CRM/Core/Permission.php index b9bacb0ce9..19c64e866c 100644 --- a/CRM/Core/Permission.php +++ b/CRM/Core/Permission.php @@ -783,6 +783,7 @@ class CRM_Core_Permission { $prefix . ts('view debug output'), ts('View results of debug and backtrace'), ), + 'view all notes' => array( $prefix . ts('view all notes'), ts("View notes (for visible contacts) even if they're marked admin only"), diff --git a/CRM/Report/Form.php b/CRM/Report/Form.php index e7d71e598c..aeeb6358a9 100644 --- a/CRM/Report/Form.php +++ b/CRM/Report/Form.php @@ -380,6 +380,15 @@ class CRM_Report_Form extends CRM_Core_Form { */ protected $_createNew; + /** + * SQL being run in this report. + * + * The sql in the report is stored in this variable in order to be displayed on the developer tab. + * + * @var string + */ + + protected $sql; /** * Class constructor. */ @@ -1195,6 +1204,35 @@ class CRM_Report_Form extends CRM_Core_Form { $this->assign('tabs', $order); } + /** + * The intent is to add a tab for developers to view the sql. + * + * Currently using dpm. + * + * @param string $sql + */ + protected function addToDeveloperTab($sql) { + if (!CRM_Core_Permission::check('view report sql')) { + return; + } + $this->tabs['Developer'] = array( + 'title' => ts('Developer'), + 'tpl' => 'Developer', + 'div_label' => 'set-developer', + ); + + $this->assignTabs(); + foreach (array('LEFT JOIN') as $term) { + $sql = str_replace($term, '
  ' . $term, $sql); + } + foreach (array('FROM', 'WHERE', 'GROUP BY', 'ORDER BY', 'LIMIT', ';') as $term) { + $sql = str_replace($term, '

' . $term, $sql); + } + $this->sql .= $sql . "
"; + + $this->assign('sql', $this->sql); + } + /** * Add options defined in $this->_options to the report. */ @@ -2673,6 +2711,7 @@ WHERE cg.extends IN ('" . implode("','", $this->_customGroupExtends) . "') AND CRM_Utils_Hook::alterReportVar('sql', $this, $this); $sql = "{$this->_select} {$this->_from} {$this->_where} {$this->_groupBy} {$this->_having} {$this->_orderBy} {$this->_limit}"; + $this->addToDeveloperTab($sql); return $sql; } diff --git a/CRM/Report/Info.php b/CRM/Report/Info.php index c5c80f0bd3..d7ffa9f67a 100644 --- a/CRM/Report/Info.php +++ b/CRM/Report/Info.php @@ -99,6 +99,10 @@ class CRM_Report_Info extends CRM_Core_Component_Info { ts('administer Reports'), ts('Manage report templates'), ), + 'view report sql' => array( + ts('view report sql'), + ts('View sql used in CiviReports'), + ), ); if (!$descriptions) { diff --git a/templates/CRM/Report/Form/Tabs/Developer.tpl b/templates/CRM/Report/Form/Tabs/Developer.tpl new file mode 100644 index 0000000000..47d9cccebe --- /dev/null +++ b/templates/CRM/Report/Form/Tabs/Developer.tpl @@ -0,0 +1,3 @@ +
+
{$sql}
+
-- 2.25.1