/** * Pre process function. * * Called prior to build form. * * Backported to provide CRM-12687 which is in 4.4 and to prevent inappropriate * defaults being set for group by in core function. Further wrangling * (not in core) for uniquename matching against core metadata. * * https://github.com/eileenmcnaughton/nz.co.fuzion.extendedreport/issues/12 */ public function preProcess() { $this->setVersion(); $this->assign('civicrm_major_version', $this->majorVersion); $this->preProcessCommon(); if (!$this->_id) { $this->addBreadCrumb(); } foreach ($this->_columns as $tableName => $table) { $this->_aliases[$tableName] = $this->setTableAlias($table, $tableName); $expFields = array(); $daoOrBaoName = NULL; // higher preference to bao object if (array_key_exists('bao', $table)) { $daoOrBaoName = $table['bao']; } elseif (array_key_exists('dao', $table)) { $daoOrBaoName = $table['dao']; } if ($daoOrBaoName) { if (method_exists($daoOrBaoName, 'exportableFields')) { $expFields = $daoOrBaoName::exportableFields(); } else { $expFields = $daoOrBaoName::export(); } } foreach ($expFields as $fieldName => $field) { // Double index any unique fields to ensure we find a match // later on. For example the metadata keys // contribution_campaign_id rather than campaign_id // this is not super predictable so we ensure that they are keyed by // both possibilities if (!empty($field['name']) && $field['name'] != $fieldName) { $expFields[$field['name']] = $field; } } $doNotCopy = array('required'); // Extended reports customisation starts == // We don't want all the schema data copied onto group_bys or order_bys. // Ideally we ONLY want it in metadata & other fields can // 'dip into that' as required. But a lot to untangle before then.... // allowing it on group_bys & order_bys can lead to required fields defaulting // to being a group by. $fieldGroups = array('fields', 'filters', 'metadata', 'join_filters'); // Extended reports customisation ends == foreach ($fieldGroups as $fieldGrp) { if (!empty($table[$fieldGrp]) && is_array($table[$fieldGrp])) { foreach ($table[$fieldGrp] as $fieldName => $field) { // $name is the field name used to reference the BAO/DAO export fields array $name = isset($field['name']) ? $field['name'] : $fieldName; // Sometimes the field name key in the BAO/DAO export fields array is // different from the actual database field name. // Unset $field['name'] so that actual database field name can be obtained // from the BAO/DAO export fields array. unset($field['name']); if (array_key_exists($name, $expFields)) { foreach ($doNotCopy as $dnc) { // unset the values we don't want to be copied. unset($expFields[$name][$dnc]); } if (empty($field)) { $this->_columns[$tableName][$fieldGrp][$fieldName] = $expFields[$name]; } else { foreach ($expFields[$name] as $property => $val) { if (!array_key_exists($property, $field)) { $this->_columns[$tableName][$fieldGrp][$fieldName][$property] = $val; } } } } // fill other vars if (!empty($field['no_repeat'])) { $this->_noRepeats[] = "{$tableName}_{$fieldName}"; } if (!empty($field['no_display'])) { $this->_noDisplay[] = "{$tableName}_{$fieldName}"; } // set alias = table-name, unless already set $alias = isset($field['alias']) ? $field['alias'] : ( isset($this->_columns[$tableName]['alias']) ? $this->_columns[$tableName]['alias'] : $tableName ); $this->_columns[$tableName][$fieldGrp][$fieldName]['alias'] = $alias; // set name = fieldName, unless already set if (!isset($this->_columns[$tableName][$fieldGrp][$fieldName]['name'])) { $this->_columns[$tableName][$fieldGrp][$fieldName]['name'] = $name; } // set dbAlias = alias.name, unless already set if (!isset($this->_columns[$tableName][$fieldGrp][$fieldName]['dbAlias'])) { $this->_columns[$tableName][$fieldGrp][$fieldName]['dbAlias'] = $alias . '.' . $this->_columns[$tableName][$fieldGrp][$fieldName]['name']; } // a few auto fills for filters if ($fieldGrp == 'filters' || $fieldGrp == 'join_filters') { // fill operator types if (!array_key_exists('operatorType', $this->_columns[$tableName][$fieldGrp][$fieldName])) { switch (CRM_Utils_Array::value('type', $this->_columns[$tableName][$fieldGrp][$fieldName])) { case CRM_Utils_Type::T_MONEY: case CRM_Utils_Type::T_FLOAT: $this->_columns[$tableName][$fieldGrp][$fieldName]['operatorType'] = CRM_Report_Form::OP_FLOAT; break; case CRM_Utils_Type::T_INT: $this->_columns[$tableName][$fieldGrp][$fieldName]['operatorType'] = CRM_Report_Form::OP_INT; break; case CRM_Utils_Type::T_DATE: $this->_columns[$tableName][$fieldGrp][$fieldName]['operatorType'] = CRM_Report_Form::OP_DATE; break; case CRM_Utils_Type::T_BOOLEAN: $this->_columns[$tableName][$fieldGrp][$fieldName]['operatorType'] = CRM_Report_Form::OP_SELECT; if (!array_key_exists('options', $this->_columns[$tableName][$fieldGrp][$fieldName])) { $this->_columns[$tableName][$fieldGrp][$fieldName]['options'] = array( '' => ts('Any'), '0' => ts('No'), '1' => ts('Yes'), ); } break; default: if ($daoOrBaoName && (array_key_exists('pseudoconstant', $this->_columns[$tableName][$fieldGrp][$fieldName]) || array_key_exists('enumValues', $this->_columns[$tableName][$fieldGrp][$fieldName])) ) { // with multiple options operator-type is generally multi-select $this->_columns[$tableName][$fieldGrp][$fieldName]['operatorType'] = CRM_Report_Form::OP_MULTISELECT; if (!array_key_exists('options', $this->_columns[$tableName][$fieldGrp][$fieldName])) { // fill options $this->_columns[$tableName][$fieldGrp][$fieldName]['options'] = CRM_Core_PseudoConstant::get($daoOrBaoName, $fieldName); } } break; } } } } } } // Copy filters to a separate handy variable. foreach (array('filters', 'join_filters') as $filterString) { if (array_key_exists($filterString, $table)) { $property = '_' . $filterString; $this->{$property}[$tableName] = $this->_columns[$tableName][$filterString]; } } if (array_key_exists('group_bys', $table)) { $groupBys[$tableName] = $this->_columns[$tableName]['group_bys']; } if (array_key_exists('fields', $table)) { $reportFields[$tableName] = $this->_columns[$tableName]['fields']; } } if ($this->_relationship_tab) { $this->addRelationshipTab(); } if ($this->_force) { $this->setDefaultValues(FALSE); } CRM_Report_Utils_Get::processFilter($this->_filters, $this->_defaults); CRM_Report_Utils_Get::processGroupBy($groupBys, $this->_defaults); CRM_Report_Utils_Get::processFields($reportFields, $this->_defaults); CRM_Report_Utils_Get::processChart($this->_defaults); if ($this->_force) { $this->_formValues = $this->_defaults; $this->postProcess(); } }
/** * Pre process function. * * Called prior to build form. */ public function preProcess() { $this->preProcessCommon(); if (!$this->_id) { $this->addBreadCrumb(); } foreach ($this->_columns as $tableName => $table) { // set alias if (!isset($table['alias'])) { $this->_columns[$tableName]['alias'] = substr($tableName, 8) . '_civireport'; } else { $this->_columns[$tableName]['alias'] = $table['alias'] . '_civireport'; } $this->_aliases[$tableName] = $this->_columns[$tableName]['alias']; $daoOrBaoName = NULL; // higher preference to bao object if (array_key_exists('bao', $table)) { $daoOrBaoName = $table['bao']; $expFields = $daoOrBaoName::exportableFields(); } elseif (array_key_exists('dao', $table)) { $daoOrBaoName = $table['dao']; $expFields = $daoOrBaoName::export(); } else { $expFields = array(); } $doNotCopy = array('required'); $fieldGroups = array('fields', 'filters', 'group_bys', 'order_bys'); foreach ($fieldGroups as $fieldGrp) { if (!empty($table[$fieldGrp]) && is_array($table[$fieldGrp])) { foreach ($table[$fieldGrp] as $fieldName => $field) { // $name is the field name used to reference the BAO/DAO export fields array $name = isset($field['name']) ? $field['name'] : $fieldName; // Sometimes the field name key in the BAO/DAO export fields array is // different from the actual database field name. // Unset $field['name'] so that actual database field name can be obtained // from the BAO/DAO export fields array. unset($field['name']); if (array_key_exists($name, $expFields)) { foreach ($doNotCopy as $dnc) { // unset the values we don't want to be copied. unset($expFields[$name][$dnc]); } if (empty($field)) { $this->_columns[$tableName][$fieldGrp][$fieldName] = $expFields[$name]; } else { foreach ($expFields[$name] as $property => $val) { if (!array_key_exists($property, $field)) { $this->_columns[$tableName][$fieldGrp][$fieldName][$property] = $val; } } } } // fill other vars if (!empty($field['no_repeat'])) { $this->_noRepeats[] = "{$tableName}_{$fieldName}"; } if (!empty($field['no_display'])) { $this->_noDisplay[] = "{$tableName}_{$fieldName}"; } // set alias = table-name, unless already set $alias = isset($field['alias']) ? $field['alias'] : (isset($this->_columns[$tableName]['alias']) ? $this->_columns[$tableName]['alias'] : $tableName); $this->_columns[$tableName][$fieldGrp][$fieldName]['alias'] = $alias; // set name = fieldName, unless already set if (!isset($this->_columns[$tableName][$fieldGrp][$fieldName]['name'])) { $this->_columns[$tableName][$fieldGrp][$fieldName]['name'] = $name; } // set dbAlias = alias.name, unless already set if (!isset($this->_columns[$tableName][$fieldGrp][$fieldName]['dbAlias'])) { $this->_columns[$tableName][$fieldGrp][$fieldName]['dbAlias'] = $alias . '.' . $this->_columns[$tableName][$fieldGrp][$fieldName]['name']; } // a few auto fills for filters if ($fieldGrp == 'filters') { // fill operator types if (!array_key_exists('operatorType', $this->_columns[$tableName][$fieldGrp][$fieldName])) { switch (CRM_Utils_Array::value('type', $this->_columns[$tableName][$fieldGrp][$fieldName])) { case CRM_Utils_Type::T_MONEY: case CRM_Utils_Type::T_FLOAT: $this->_columns[$tableName][$fieldGrp][$fieldName]['operatorType'] = CRM_Report_Form::OP_FLOAT; break; case CRM_Utils_Type::T_INT: $this->_columns[$tableName][$fieldGrp][$fieldName]['operatorType'] = CRM_Report_Form::OP_INT; break; case CRM_Utils_Type::T_DATE: $this->_columns[$tableName][$fieldGrp][$fieldName]['operatorType'] = CRM_Report_Form::OP_DATE; break; case CRM_Utils_Type::T_BOOLEAN: $this->_columns[$tableName][$fieldGrp][$fieldName]['operatorType'] = CRM_Report_Form::OP_SELECT; if (!array_key_exists('options', $this->_columns[$tableName][$fieldGrp][$fieldName])) { $this->_columns[$tableName][$fieldGrp][$fieldName]['options'] = array('' => ts('Any'), '0' => ts('No'), '1' => ts('Yes')); } break; default: if ($daoOrBaoName && array_key_exists('pseudoconstant', $this->_columns[$tableName][$fieldGrp][$fieldName])) { // with multiple options operator-type is generally multi-select $this->_columns[$tableName][$fieldGrp][$fieldName]['operatorType'] = CRM_Report_Form::OP_MULTISELECT; if (!array_key_exists('options', $this->_columns[$tableName][$fieldGrp][$fieldName])) { // fill options $this->_columns[$tableName][$fieldGrp][$fieldName]['options'] = CRM_Core_PseudoConstant::get($daoOrBaoName, $fieldName); } } break; } } } } } } // copy filters to a separate handy variable if (array_key_exists('filters', $table)) { $this->_filters[$tableName] = $this->_columns[$tableName]['filters']; } if (array_key_exists('group_bys', $table)) { $groupBys[$tableName] = $this->_columns[$tableName]['group_bys']; } if (array_key_exists('fields', $table)) { $reportFields[$tableName] = $this->_columns[$tableName]['fields']; } } if ($this->_force) { $this->setDefaultValues(FALSE); } CRM_Report_Utils_Get::processFilter($this->_filters, $this->_defaults); CRM_Report_Utils_Get::processGroupBy($groupBys, $this->_defaults); CRM_Report_Utils_Get::processFields($reportFields, $this->_defaults); CRM_Report_Utils_Get::processChart($this->_defaults); if ($this->_force) { $this->_formValues = $this->_defaults; $this->postProcess(); } }
function preProcess() { self::preProcessCommon(); if (!$this->_id) { self::addBreadCrumb(); } foreach ($this->_columns as $tableName => $table) { // set alias if (!isset($table['alias'])) { $this->_columns[$tableName]['alias'] = substr($tableName, 8) . '_civireport'; } else { $this->_columns[$tableName]['alias'] = $table['alias'] . '_civireport'; } $this->_aliases[$tableName] = $this->_columns[$tableName]['alias']; // higher preference to bao object if (array_key_exists('bao', $table)) { require_once str_replace('_', DIRECTORY_SEPARATOR, $table['bao'] . '.php'); eval("\$expFields = {$table['bao']}::exportableFields( );"); } else { require_once str_replace('_', DIRECTORY_SEPARATOR, $table['dao'] . '.php'); eval("\$expFields = {$table['dao']}::export( );"); } $doNotCopy = array('required'); $fieldGroups = array('fields', 'filters', 'group_bys', 'order_bys'); foreach ($fieldGroups as $fieldGrp) { if (CRM_Utils_Array::value($fieldGrp, $table) && is_array($table[$fieldGrp])) { foreach ($table[$fieldGrp] as $fieldName => $field) { // $name is the field name used to reference the BAO/DAO export fields array $name = isset($field['name']) ? $field['name'] : $fieldName; // Sometimes the field name key in the BAO/DAO export fields array is // different from the actual database field name. // Unset $field['name'] so that actual database field name can be obtained // from the BAO/DAO export fields array. unset($field['name']); if (array_key_exists($name, $expFields)) { foreach ($doNotCopy as $dnc) { // unset the values we don't want to be copied. unset($expFields[$name][$dnc]); } if (empty($field)) { $this->_columns[$tableName][$fieldGrp][$fieldName] = $expFields[$name]; } else { foreach ($expFields[$name] as $property => $val) { if (!array_key_exists($property, $field)) { $this->_columns[$tableName][$fieldGrp][$fieldName][$property] = $val; } } } } // fill other vars if (CRM_Utils_Array::value('no_repeat', $field)) { $this->_noRepeats[] = "{$tableName}_{$fieldName}"; } if (CRM_Utils_Array::value('no_display', $field)) { $this->_noDisplay[] = "{$tableName}_{$fieldName}"; } // set alias = table-name, unless already set $alias = isset($field['alias']) ? $field['alias'] : (isset($this->_columns[$tableName]['alias']) ? $this->_columns[$tableName]['alias'] : $tableName); $this->_columns[$tableName][$fieldGrp][$fieldName]['alias'] = $alias; // set name = fieldName, unless already set if (!isset($this->_columns[$tableName][$fieldGrp][$fieldName]['name'])) { $this->_columns[$tableName][$fieldGrp][$fieldName]['name'] = $name; } // set dbAlias = alias.name, unless already set if (!isset($this->_columns[$tableName][$fieldGrp][$fieldName]['dbAlias'])) { $this->_columns[$tableName][$fieldGrp][$fieldName]['dbAlias'] = $alias . '.' . $this->_columns[$tableName][$fieldGrp][$fieldName]['name']; } if (CRM_Utils_Array::value('type', $this->_columns[$tableName][$fieldGrp][$fieldName]) && !isset($this->_columns[$tableName][$fieldGrp][$fieldName]['operatorType'])) { if (in_array($this->_columns[$tableName][$fieldGrp][$fieldName]['type'], array(CRM_Utils_Type::T_MONEY, CRM_Utils_Type::T_FLOAT))) { $this->_columns[$tableName][$fieldGrp][$fieldName]['operatorType'] = CRM_Report_Form::OP_FLOAT; } elseif (in_array($this->_columns[$tableName][$fieldGrp][$fieldName]['type'], array(CRM_Utils_Type::T_INT))) { $this->_columns[$tableName][$fieldGrp][$fieldName]['operatorType'] = CRM_Report_Form::OP_INT; } } } } } // copy filters to a separate handy variable if (array_key_exists('filters', $table)) { $this->_filters[$tableName] = $this->_columns[$tableName]['filters']; } if (array_key_exists('group_bys', $table)) { $groupBys[$tableName] = $this->_columns[$tableName]['group_bys']; } if (array_key_exists('fields', $table)) { $reportFields[$tableName] = $this->_columns[$tableName]['fields']; } } if ($this->_force) { $this->setDefaultValues(FALSE); } CRM_Report_Utils_Get::processFilter($this->_filters, $this->_defaults); CRM_Report_Utils_Get::processGroupBy($groupBys, $this->_defaults); CRM_Report_Utils_Get::processFields($reportFields, $this->_defaults); CRM_Report_Utils_Get::processChart($this->_defaults); if ($this->_force) { $this->_formValues = $this->_defaults; $this->postProcess(); } }