<?php
-// $Id$
-
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.3 |
public $_columnHeaders = array();
public $_orderBy = NULL;
public $_groupBy = NULL;
+ public $_whereClauses = array();
+ public $_havingClauses = array();
+
+ /**
+ * Variable to hold the currency alias
+ */
+ protected $_currencyColumn = NULL;
/**
*
// add / modify display columns, filters ..etc
CRM_Utils_Hook::alterReportVar('columns', $this->_columns, $this);
+
+ //assign currencyColumn variable to tpl
+ $this->assign('currencyColumn', $this->_currencyColumn);
}
function preProcessCommon() {
}
// lets always do a force if reset is found in the url.
- if (CRM_Utils_Array::value('reset', $_GET)) {
+ if (CRM_Utils_Array::value('reset', $_REQUEST)) {
$this->_force = 1;
}
$this->_chartButtonName = $this->getButtonName('submit', 'chart');
}
- static function addBreadCrumb() {
+ function addBreadCrumb() {
$breadCrumbs =
array(
array(
$this->preProcessCommon();
if (!$this->_id) {
- self::addBreadCrumb();
+ $this->addBreadCrumb();
}
foreach ($this->_columns as $tableName => $table) {
require_once str_replace('_', DIRECTORY_SEPARATOR, $table['bao'] . '.php');
eval("\$expFields = {$table['bao']}::exportableFields( );");
}
- else {
+ elseif (array_key_exists('dao', $table)){
require_once str_replace('_', DIRECTORY_SEPARATOR, $table['dao'] . '.php');
eval("\$expFields = {$table['dao']}::export( );");
}
+ else{
+ $expFields = array();
+ }
$doNotCopy = array('required');
foreach ($table['filters'] as $fieldName => $field) {
if (isset($field['default'])) {
if (CRM_Utils_Array::value('type', $field) & CRM_Utils_Type::T_DATE) {
- $this->_defaults["{$fieldName}_relative"] = $field['default'];
+ if(is_array($field['default'])){
+ $this->_defaults["{$fieldName}_from"] = CRM_Utils_Array::value('from', $field['default']);
+ $this->_defaults["{$fieldName}_to"] = CRM_Utils_Array::value('to', $field['default']);
+ $this->_defaults["{$fieldName}_relative"] = 0;
+ }
+ else{
+ $this->_defaults["{$fieldName}_relative"] = $field['default'];
+ }
}
else {
$this->_defaults["{$fieldName}_value"] = $field['default'];
foreach ($this->_filters as $table => $attributes) {
foreach ($attributes as $fieldName => $field) {
// get ready with option value pair
- $operations = self::getOperationPair(
+ // @ todo being able to specific options for a field (e.g a date field) in the field spec as an array rather than an override
+ // would be useful
+ $operations = $this->getOperationPair(
CRM_Utils_Array::value('operatorType', $field),
- $fieldName
- );
+ $fieldName);
$filters[$table][$fieldName] = $field;
case CRM_Report_FORM::OP_DATE:
// build datetime fields
- CRM_Core_Form_Date::buildDateRange($this, $fieldName, $count);
+ CRM_Core_Form_Date::buildDateRange($this, $fieldName, $count, '_from','_to', 'From:', FALSE, $operations);
$count++;
break;
case CRM_Report_FORM::OP_DATETIME:
// build datetime fields
- CRM_Core_Form_Date::buildDateRange($this, $fieldName, $count, '_from', '_to', 'From:', FALSE, TRUE, 'searchDate', true);
+ CRM_Core_Form_Date::buildDateRange($this, $fieldName, $count, '_from', '_to', 'From:', FALSE, $operations, 'searchDate', true);
$count++;
break;
if ($field['type'] == 'select') {
$this->addElement('select', "{$fieldName}", $field['title'], $field['options']);
}
- else {
+ else if ($field['type'] == 'checkbox') {
$options[$field['title']] = $fieldName;
+ $this->addCheckBox($fieldName, NULL,
+ $options, NULL,
+ NULL, NULL, NULL, $this->_fourColumnAttribute
+ );
}
}
-
- $this->addCheckBox("options", $field['title'],
- $options, NULL,
- NULL, NULL, NULL, $this->_fourColumnAttribute
- );
}
+ $this->assign('otherOptions', $this->_options);
}
function addChartOptions() {
// Note: $fieldName param allows inheriting class to build operationPairs
// specific to a field.
- static function getOperationPair($type = "string", $fieldName = NULL) {
+ function getOperationPair($type = "string", $fieldName = NULL) {
// FIXME: At some point we should move these key-val pairs
// to option_group and option_value table.
-
switch ($type) {
case CRM_Report_FORM::OP_INT:
case CRM_Report_FORM::OP_FLOAT:
- return array('lte' => ts('Is less than or equal to'),
+ return array(
+ 'lte' => ts('Is less than or equal to'),
'gte' => ts('Is greater than or equal to'),
'bw' => ts('Is between'),
'eq' => ts('Is equal to'),
break;
case CRM_Report_FORM::OP_SELECT:
- return array('eq' => ts('Is equal to'));
+ return array(
+ 'eq' => ts('Is equal to'),
+ );
case CRM_Report_FORM::OP_MONTH:
case CRM_Report_FORM::OP_MULTISELECT:
- return array('in' => ts('Is one of'),
+ return array(
+ 'in' => ts('Is one of'),
'notin' => ts('Is not one of'),
);
break;
case CRM_Report_FORM::OP_DATE:
- return array('nll' => ts('Is empty (Null)'),
+ return array(
+ 'nll' => ts('Is empty (Null)'),
'nnll' => ts('Is not empty (Null)'),
);
break;
case CRM_Report_FORM::OP_MULTISELECT_SEPARATOR:
// use this operator for the values, concatenated with separator. For e.g if
// multiple options for a column is stored as ^A{val1}^A{val2}^A
- return array('mhas' => ts('Is one of'));
+ return array(
+ 'mhas' => ts('Is one of'),
+ );
default:
// type is string
- return array('has' => ts('Contains'),
+ return array(
+ 'has' => ts('Contains'),
'sw' => ts('Starts with'),
'ew' => ts('Ends with'),
'nhas' => ts('Does not contain'),
}
}
- static function getSQLOperator($operator = "like") {
+ function getSQLOperator($operator = "like") {
switch ($operator) {
case 'eq':
return '=';
else {
$value = "'{$value}'";
}
- $sqlOP = self::getSQLOperator($op);
+ $sqlOP = $this->getSQLOperator($op);
$clause = "( {$field['dbAlias']} $sqlOP $value )";
}
break;
case 'in':
case 'notin':
if ($value !== NULL && is_array($value) && count($value) > 0) {
- $sqlOP = self::getSQLOperator($op);
+ $sqlOP = $this->getSQLOperator($op);
if (CRM_Utils_Array::value('type', $field) == CRM_Utils_Type::T_STRING) {
//cycle through selections and esacape values
foreach ($value as $key => $selection) {
case 'mhas':
// mhas == multiple has
if ($value !== NULL && count($value) > 0) {
- $sqlOP = self::getSQLOperator($op);
+ $sqlOP = $this->getSQLOperator($op);
$clause = "{$field['dbAlias']} REGEXP '[[:<:]]" . implode('|', $value) . "[[:>:]]'";
}
break;
else {
$value = "'{$value}'";
}
- $sqlOP = self::getSQLOperator($op);
+ $sqlOP = $this->getSQLOperator($op);
$clause = "( {$field['dbAlias']} $sqlOP $value )";
}
break;
case 'nll':
case 'nnll':
- $sqlOP = self::getSQLOperator($op);
+ $sqlOP = $this->getSQLOperator($op);
$clause = "( {$field['dbAlias']} $sqlOP )";
break;
}
else {
$value = CRM_Utils_Type::escape($value, $type);
- $sqlOP = self::getSQLOperator($op);
+ $sqlOP = $this->getSQLOperator($op);
if ($field['type'] == CRM_Utils_Type::T_STRING) {
$value = "'{$value}'";
}
$relative, $from, $to, $type = NULL, $fromTime = NULL, $toTime = NULL
) {
$clauses = array();
- if (in_array($relative, array_keys(self::getOperationPair(CRM_Report_FORM::OP_DATE)))) {
- $sqlOP = self::getSQLOperator($relative);
+ if (in_array($relative, array_keys($this->getOperationPair(CRM_Report_FORM::OP_DATE)))) {
+ $sqlOP = $this->getSQLOperator($relative);
return "( {$fieldName} {$sqlOP} )";
}
- list($from, $to) = self::getFromTo($relative, $from, $to, $fromTime, $toTime);
+ list($from, $to) = $this->getFromTo($relative, $from, $to, $fromTime, $toTime);
if ($from) {
$from = ($type == CRM_Utils_Type::T_DATE) ? substr($from, 0, 8) : $from;
return NULL;
}
-
- static function dateDisplay($relative, $from, $to) {
- list($from, $to) = self::getFromTo($relative, $from, $to);
+ /**
+ * @todo - could not find any instances where this is called
+ * @param unknown_type $relative
+ * @param String $from
+ * @param String_type $to
+ * @return string|NULL
+ */
+ function dateDisplay($relative, $from, $to) {
+ list($from, $to) = $this->getFromTo($relative, $from, $to);
if ($from) {
$clauses[] = CRM_Utils_Date::customFormat($from, NULL, array('m', 'M'));
return NULL;
}
- static function getFromTo($relative, $from, $to, $fromtime = NULL, $totime = NULL) {
+ function getFromTo($relative, $from, $to, $fromtime = NULL, $totime = NULL) {
if (empty($totime)) {
$totime = '235959';
}
}
function where() {
- $whereClauses = $havingClauses = array();
+ $this->storeWhereHavingClauseArray();
+
+ if (empty($this->_whereClauses)) {
+ $this->_where = "WHERE ( 1 ) ";
+ $this->_having = "";
+ }
+ else {
+ $this->_where = "WHERE " . implode(' AND ', $this->_whereClauses);
+ }
+
+ if ($this->_aclWhere) {
+ $this->_where .= " AND {$this->_aclWhere} ";
+ }
+
+ if (!empty($this->_havingClauses)) {
+ // use this clause to construct group by clause.
+ $this->_having = "HAVING " . implode(' AND ', $this->_havingClauses);
+ }
+ }
+
+ /**
+ * Store Where clauses into an array - breaking out this step makes
+ * over-riding more flexible as the clauses can be used in constructing a
+ * temp table that may not be part of the final where clause or added
+ * in other functions
+ */
+ function storeWhereHavingClauseArray(){
foreach ($this->_columns as $tableName => $table) {
if (array_key_exists('filters', $table)) {
foreach ($table['filters'] as $fieldName => $field) {
+ // respect pseudofield to filter spec so fields can be marked as
+ // not to be handled here
+ if(!empty($field['pseudofield'])){
+ continue;
+ }
$clause = NULL;
if (CRM_Utils_Array::value('type', $field) & CRM_Utils_Type::T_DATE) {
if (CRM_Utils_Array::value('operatorType', $field) == CRM_Report_Form::OP_MONTH) {
$op = CRM_Utils_Array::value("{$fieldName}_op", $this->_params);
if ($op) {
$clause = $this->whereClause($field,
- $op,
- CRM_Utils_Array::value("{$fieldName}_value", $this->_params),
- CRM_Utils_Array::value("{$fieldName}_min", $this->_params),
- CRM_Utils_Array::value("{$fieldName}_max", $this->_params)
+ $op,
+ CRM_Utils_Array::value("{$fieldName}_value", $this->_params),
+ CRM_Utils_Array::value("{$fieldName}_min", $this->_params),
+ CRM_Utils_Array::value("{$fieldName}_max", $this->_params)
);
}
}
if (!empty($clause)) {
if (CRM_Utils_Array::value('having', $field)) {
- $havingClauses[] = $clause;
+ $this->_havingClauses[] = $clause;
}
else {
- $whereClauses[] = $clause;
+ $this->_whereClauses[] = $clause;
}
}
}
}
}
- if (empty($whereClauses)) {
- $this->_where = "WHERE ( 1 ) ";
- $this->_having = "";
- }
- else {
- $this->_where = "WHERE " . implode(' AND ', $whereClauses);
- }
-
- if ($this->_aclWhere) {
- $this->_where .= " AND {$this->_aclWhere} ";
- }
-
- if (!empty($havingClauses)) {
- // use this clause to construct group by clause.
- $this->_having = "HAVING " . implode(' AND ', $havingClauses);
- }
}
-
function processReportMode() {
$buttonName = $this->controller->getButtonName();
- $output = CRM_Utils_Request::retrieve('output',
- 'String',
- CRM_Core_DAO::$_nullObject
+ $output = CRM_Utils_Request::retrieve(
+ 'output',
+ 'String',
+ CRM_Core_DAO::$_nullObject
);
$this->_sendmail =
- CRM_Utils_Request::retrieve('sendmail',
- 'Boolean',
- CRM_Core_DAO::$_nullObject
- );
+ CRM_Utils_Request::retrieve(
+ 'sendmail',
+ 'Boolean',
+ CRM_Core_DAO::$_nullObject
+ );
$this->_absoluteUrl = FALSE;
$printOnly = FALSE;
if ($from || $to) {
$statistics['filters'][] = array(
'title' => $field['title'],
- 'value' => ts(
- "Between %1 and %2",
- array(
- 1 => $from,
- 2 => $to,
- )
- ),
+ 'value' => ts("Between %1 and %2", array(1 => $from, 2 => $to)),
);
}
elseif (in_array($rel = CRM_Utils_Array::value("{$fieldName}_relative", $this->_params),
- array_keys(self::getOperationPair(CRM_Report_FORM::OP_DATE))
+ array_keys($this->getOperationPair(CRM_Report_FORM::OP_DATE))
)) {
- $pair = self::getOperationPair(CRM_Report_FORM::OP_DATE);
+ $pair = $this->getOperationPair(CRM_Report_FORM::OP_DATE);
$statistics['filters'][] = array(
'title' => $field['title'],
'value' => $pair[$rel],
$op = CRM_Utils_Array::value("{$fieldName}_op", $this->_params);
$value = NULL;
if ($op) {
- $pair = self::getOperationPair(
+ $pair = $this->getOperationPair(
CRM_Utils_Array::value('operatorType', $field),
$fieldName
);
CRM_Core_Session::setStatus(ts("Report mail could not be sent."), ts('Mail Error'), 'error');
}
- CRM_Utils_System::redirect(CRM_Utils_System::url(CRM_Utils_System::currentPath(),
- 'reset=1'
- ));
+ CRM_Utils_System::redirect(CRM_Utils_System::url(CRM_Utils_System::currentPath(), 'reset=1'));
}
elseif ($this->_outputMode == 'print') {
echo $content;
WHERE smartgroup_contact.group_id IN ({$smartGroups}) ";
}
- $sqlOp = self::getSQLOperator($op);
+ $sqlOp = $this->getSQLOperator($op);
if (!is_array($value)) {
$value = array($value);
}
// not using left join in query because if any contact
// belongs to more than one tag, results duplicate
// entries.
- $sqlOp = self::getSQLOperator($op);
+ $sqlOp = $this->getSQLOperator($op);
if (!is_array($value)) {
$value = array($value);
}
}
if (!array_key_exists('type', $curFields[$fieldName])) {
- $curFields[$fieldName]['type'] = $curFilters[$fieldName]['type'];
+ $curFields[$fieldName]['type'] = CRM_Utils_Array::value('type', $curFilters[$fieldName], array());
}
if ($addFields) {
foreach (array(
'value', 'min', 'max', 'relative', 'from', 'to') as $attach) {
if (isset($this->_params[$fieldAlias . '_' . $attach]) &&
- (!empty($this->_params[$fieldAlias . '_' . $attach]) || $this->_params[$fieldAlias . '_' . $attach] == '0')
- ) {
+ (!empty($this->_params[$fieldAlias . '_' . $attach])
+ || ($attach != 'relative' && $this->_params[$fieldAlias . '_' . $attach] == '0')
+ )
+ ){
return TRUE;
}
}
return $this->_selectedTables;
}
- /*
+ /**
+ * @deprecated - use getAddressColumns which is a more accurate description
+ * and also accepts an array of options rather than a long list
+ *
* function for adding address fields to construct function in reports
* @param bool $groupBy Add GroupBy? Not appropriate for detail report
* @param bool $orderBy Add GroupBy? Not appropriate for detail report
}
}
+ /**
+ * Add Phone into From Table if required
+ */
+ function addPhoneFromClause() {
+ // include address field if address column is to be included
+ if ($this->isTableSelected('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\n";
+ }
+ }
+
+ /**
+ * Get phone columns to add to array
+ * @param array $options
+ * - prefix Prefix to add to table (in case of more than one instance of the table)
+ * - prefix_label Label to give columns from this phone table instance
+ * @return array phone columns definition
+ */
+ function getPhoneColumns($options = array()){
+ $defaultOptions = array(
+ 'prefix' => '',
+ 'prefix_label' => '',
+ );
+
+ $options = array_merge($defaultOptions,$options);
+
+ $fields = array(
+ $options['prefix'] . 'civicrm_phone' => array(
+ 'dao' => 'CRM_Core_DAO_Phone',
+ 'fields' => array(
+ $options['prefix'] . 'phone' => array(
+ 'title' => ts($options['prefix_label'] . 'Phone'),
+ 'name' => 'phone'
+ ),
+ ),
+ ),
+ );
+ return $fields;
+ }
+
+ /**
+ * Get address columns to add to array
+ * @param array $options
+ * - prefix Prefix to add to table (in case of more than one instance of the table)
+ * - prefix_label Label to give columns from this address table instance
+ * @return array address columns definition
+ */
+ function getAddressColumns($options = array()){
+ $defaultOptions = array(
+ 'prefix' => '',
+ 'prefix_label' => '',
+ 'group_by' => TRUE,
+ 'order_by' => TRUE,
+ 'filters' => TRUE,
+ 'defaults' => array(
+ ),
+ );
+ $options = array_merge($defaultOptions,$options);
+ return $this->addAddressFields(
+ $options['group_by'],
+ $options['order_by'],
+ $options['filters'],
+ $options['defaults']
+ );
+
+ }
+
function add2group($groupID) {
if (is_numeric($groupID) && isset($this->_aliases['civicrm_contact'])) {
$select = "SELECT DISTINCT {$this->_aliases['civicrm_contact']}.id AS addtogroup_contact_id, ";