+ /**
+ * 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';
+ }
+ }
+ }
+
+ /**
+ * CRM-17793 - Alter DateTime section header to group by date from the datetime field.
+ * @param $tempTable
+ * @param $columnName
+ */
+ public function alterSectionHeaderForDateTime($tempTable, $columnName) {
+ // add new column with date value for the datetime field
+ $tempQuery = "ALTER TABLE {$tempTable} ADD COLUMN {$columnName}_date VARCHAR(128)";
+ CRM_Core_DAO::executeQuery($tempQuery);
+ $updateQuery = "UPDATE {$tempTable} SET {$columnName}_date = date({$columnName})";
+ CRM_Core_DAO::executeQuery($updateQuery);
+ $this->_select .= ", {$columnName}_date";
+ $this->_sections["{$columnName}_date"] = $this->_sections["{$columnName}"];
+ unset($this->_sections["{$columnName}"]);
+ $this->assign('sections', $this->_sections);
+ }
+
+ /**
+ * Get an array of the columns that have been selected for display.
+ *
+ * @return array
+ */
+ public function getSelectColumns() {
+ $selectColumns = array();
+ foreach ($this->_columns as $tableName => $table) {
+ if (array_key_exists('fields', $table)) {
+ foreach ($table['fields'] as $fieldName => $field) {
+ if (!empty($field['required']) ||
+ !empty($this->_params['fields'][$fieldName])
+ ) {
+
+ $selectColumns["{$tableName}_{$fieldName}"] = 1;
+ }
+ }
+ }
+ }
+ return $selectColumns;
+ }
+
+ /**
+ * Add location tables to the query if they are used for filtering.
+ *
+ * This is for when we are running the query separately for filtering and retrieving display fields.
+ */
+ public function selectivelyAddLocationTablesJoinsToFilterQuery() {
+ if ($this->isTableFiltered('civicrm_email')) {
+ $this->_from .= "
+ LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']}
+ ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_email']}.contact_id
+ AND {$this->_aliases['civicrm_email']}.is_primary = 1";
+ }
+ if ($this->isTableFiltered('civicrm_phone')) {
+ $this->_from .= "
+ LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']}
+ ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id
+ AND {$this->_aliases['civicrm_phone']}.is_primary = 1";
+ }
+ if ($this->isTableFiltered('civicrm_address')) {
+ $this->_from .= "
+ LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']}
+ ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_address']}.contact_id)
+ AND {$this->_aliases['civicrm_address']}.is_primary = 1\n";
+ }
+ }
+