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
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';
}
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 -'),
));
$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);
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;
}
}
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'),
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) {
$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];
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 -'),
+ );
+ }
}
function __construct() {
$this->_columns = array(
- 'civicrm_event' =>
- array(
+ 'civicrm_event' => array(
'dao' => 'CRM_Event_DAO_Event',
- 'filters' =>
- array(
- 'id' =>
- array('title' => ts('Event Title'),
- 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
+ 'filters' => array(
+ 'id' => array(
+ 'title' => ts('Event'),
+ 'operatorType' => CRM_Report_Form::OP_ENTITYREF,
'type' => CRM_Utils_Type::T_INT,
- 'options' => $this->getEventFilterOptions(),
+ 'attributes' => array('select' => array('minimumInputLength' => 0)),
),
),
),
$this->_setVariable = TRUE;
$noSelection = FALSE;
- if (empty($this->_params['id_value'][0])) {
+ if (empty($this->_params['id_value'])) {
$this->_params['id_value'] = array();
$this->_setVariable = FALSE;
}
$noSelection = TRUE;
}
+ else {
+ $this->_params['id_value'] = explode(',', $this->_params['id_value']);
+ }
$this->_rowsFound = count($this->_params['id_value']);
),
'filters' =>
array(
- 'id' => array('title' => ts('Event Title'),
- 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
- 'options' => $this->getEventFilterOptions(),
+ 'id' => array(
+ 'title' => ts('Event'),
+ 'operatorType' => CRM_Report_Form::OP_ENTITYREF,
+ 'type' => CRM_Utils_Type::T_INT,
+ 'attributes' => array('select' => array('minimumInputLength' => 0)),
),
'event_type_id' => array(
'name' => 'event_type_id',
}
}
if (!empty($this->_params['id_value'])) {
- $participant = implode(', ', $this->_params['id_value']);
- $this->_participantWhere = " AND civicrm_participant.event_id IN ( {$participant} ) ";
+ $this->_participantWhere = " AND civicrm_participant.event_id IN ( {$this->_params['id_value']} ) ";
}
if (!empty($clause)) {
),
'filters' =>
array(
- 'id' => array('title' => ts('Event Title'),
- 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
- 'options' => $this->getEventFilterOptions(),
+ 'id' => array(
+ 'title' => ts('Event'),
+ 'operatorType' => CRM_Report_Form::OP_ENTITYREF,
+ 'type' => CRM_Utils_Type::T_INT,
+ 'attributes' => array('select' => array('minimumInputLength' => 0)),
),
'event_type_id' => array(
'name' => 'event_type_id',
}
}
if (!empty($this->_params['id_value'])) {
- $participant = implode(', ', $this->_params['id_value']);
- $this->_participantWhere = " AND civicrm_participant.event_id IN ( {$participant} ) ";
+ $this->_participantWhere = " AND civicrm_participant.event_id IN ( {$this->_params['id_value']} ) ";
}
if (!empty($clause)) {