From: Coleman Watts Date: Thu, 28 Aug 2014 20:50:38 +0000 (+0100) Subject: CRM-13966 - Improve event selection in reports X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=2107cde9fe0691eecf190e27d6385febb0c95b50;p=civicrm-core.git CRM-13966 - Improve event selection in reports --- diff --git a/CRM/Report/Form.php b/CRM/Report/Form.php index d5d62e6553..38976d9353 100644 --- a/CRM/Report/Form.php +++ b/CRM/Report/Form.php @@ -47,7 +47,8 @@ class CRM_Report_Form extends CRM_Core_Form { OP_SELECT = 64, OP_MULTISELECT = 65, OP_MULTISELECT_SEPARATOR = 66, - OP_MONTH = 128; + OP_MONTH = 128, + OP_ENTITYREF = 256; /** * The id of the report instance @@ -698,6 +699,9 @@ class CRM_Report_Form extends CRM_Core_Form { if (CRM_Utils_Array::value('operatorType', $field) == CRM_Report_Form::OP_MULTISELECT) { $this->_defaults["{$fieldName}_op"] = 'in'; } + if (CRM_Utils_Array::value('operatorType', $field) == CRM_Report_Form::OP_ENTITYREF) { + $this->_defaults["{$fieldName}_op"] = 'in'; + } elseif (CRM_Utils_Array::value('operatorType', $field) == CRM_Report_Form::OP_MULTISELECT_SEPARATOR) { $this->_defaults["{$fieldName}_op"] = 'mhas'; } @@ -927,7 +931,7 @@ class CRM_Report_Form extends CRM_Core_Form { else { $this->addElement('select', "{$fieldName}_value", NULL, $field['options'], array( 'style' => 'min-width:250px', - 'class' => 'crm-select2', + 'class' => 'crm-select2 huge', 'multiple' => TRUE, 'placeholder' => ts('- select -'), )); @@ -942,6 +946,12 @@ class CRM_Report_Form extends CRM_Core_Form { $this->addElement('select', "{$fieldName}_value", NULL, $field['options']); break; + case CRM_Report_Form::OP_ENTITYREF: + $this->addElement('select', "{$fieldName}_op", ts('Operator:'), $operations); + $this->setEntityRefDefaults($field, $table); + $this->addEntityRef("{$fieldName}_value", NULL, $field['attributes']); + break; + case CRM_Report_Form::OP_DATE: // build datetime fields CRM_Core_Form_Date::buildDateRange($this, $fieldName, $count, '_from','_to', 'From:', FALSE, $operations); @@ -966,7 +976,7 @@ class CRM_Report_Form extends CRM_Core_Form { array('onchange' => "return showHideMaxMinVal( '$fieldName', this.value );") ); // we need text box for value input - $this->add('text', "{$fieldName}_value", NULL); + $this->add('text', "{$fieldName}_value", NULL, array('class' => 'huge')); break; } } @@ -1212,6 +1222,7 @@ class CRM_Report_Form extends CRM_Core_Form { case CRM_Report_Form::OP_MONTH: case CRM_Report_Form::OP_MULTISELECT: + case CRM_Report_Form::OP_ENTITYREF: return array( 'in' => ts('Is one of'), 'notin' => ts('Is not one of'), @@ -1407,6 +1418,9 @@ class CRM_Report_Form extends CRM_Core_Form { case 'in': case 'notin': + if (is_string($value) && strlen($value)) { + $value = explode(',', $value); + } if ($value !== NULL && is_array($value) && count($value) > 0) { $sqlOP = $this->getSQLOperator($op); if (CRM_Utils_Array::value('type', $field) == CRM_Utils_Type::T_STRING) { @@ -2637,9 +2651,17 @@ WHERE cg.extends IN ('" . implode("','", $this->_customGroupExtends) . "') AND $min = CRM_Utils_Array::value("{$fieldName}_min", $this->_params); $max = CRM_Utils_Array::value("{$fieldName}_max", $this->_params); $val = CRM_Utils_Array::value("{$fieldName}_value", $this->_params); - if (in_array($op, array( - 'bw', 'nbw')) && ($min || $max)) { - $value = "{$pair[$op]} " . $min . ' and ' . $max; + if (in_array($op, array('bw', 'nbw')) && ($min || $max)) { + $value = "{$pair[$op]} $min " . ts('and') . " $max"; + } + elseif ($val && CRM_Utils_Array::value('operatorType', $field) & self::OP_ENTITYREF) { + $this->setEntityRefDefaults($field, $tableName); + $result = civicrm_api3($field['attributes']['entity'], 'getlist', array('id' => $val) + CRM_Utils_Array::value('api', $field['attributes'], array())); + $values = array(); + foreach ($result['values'] as $v) { + $values[] = $v['label']; + } + $value = "{$pair[$op]} " . implode(', ', $values); } elseif ($op == 'nll' || $op == 'nnll') { $value = $pair[$op]; @@ -3795,4 +3817,18 @@ LEFT JOIN civicrm_contact {$field['alias']} ON {$field['alias']}.id = {$this->_a CRM_Utils_System::civiExit(); } } + + /** + * Apply common settings to entityRef fields + * @param array $field + * @param string $table + */ + private function setEntityRefDefaults(&$field, $table) { + $field['attributes'] = $field['attributes'] ? $field['attributes'] : array(); + $field['attributes'] += array( + 'entity' => CRM_Core_DAO_AllCoreTables::getBriefName(CRM_Core_DAO_AllCoreTables::getClassForTable($table)), + 'multiple' => TRUE, + 'placeholder' => ts('- select -'), + ); + } } diff --git a/CRM/Report/Form/Event.php b/CRM/Report/Form/Event.php index 76dc448bf6..87ea62873e 100644 --- a/CRM/Report/Form/Event.php +++ b/CRM/Report/Form/Event.php @@ -34,23 +34,7 @@ * */ class CRM_Report_Form_Event extends CRM_Report_Form { - /** - * Get a standardized array of