if (!in_array($operator, CRM_Core_DAO::acceptedSQLOperators())) {
//Via Contact get api value is not in array(operator => array(values)) format ONLY for IN/NOT IN operators
//so this condition will satisfy the search for now
- if (strstr('IN', $op)) {
+ if (strpos($op, 'IN') !== FALSE) {
$value = array($op => $value);
}
// we don't know when this might happen
$date = "('" . implode("','", $value) . "')";
$format = implode(', ', $format);
}
- elseif ($value) {
+ elseif ($value && (!strstr($op, 'NULL') && !strstr($op, 'EMPTY'))) {
$date = CRM_Utils_Date::processDate($value);
if (!$appendTimeStamp) {
$date = substr($date, 0, 8);
$clause = " (NULLIF($field, '') IS NOT NULL) ";
return $clause;
- case 'IN':
- case 'NOT IN':
- if (isset($dataType)) {
- if (is_array($value)) {
- $values = $value;
- }
- else {
- $value = CRM_Utils_Type::escape($value, "String");
- $values = explode(',', CRM_Utils_Array::value(0, explode(')', CRM_Utils_Array::value(1, explode('(', $value)))));
- }
- // supporting multiple values in IN clause
- $val = array();
- foreach ($values as $v) {
- $v = trim($v);
- $val[] = "'" . CRM_Utils_Type::escape($v, $dataType) . "'";
- }
- $value = "(" . implode($val, ",") . ")";
- }
- return "$clause $value";
-
default:
if (empty($dataType)) {
$dataType = 'String';
case 'membership_status':
case 'member_status_id':
- if (!is_array($value)) {
- $status = $value;
- if (!empty($value)) {
- $value = array_flip(explode(",", str_replace(array('(', ')'), '', $value)));
- }
- else {
- $value = array();
- }
+ case 'membership_type':
+ case 'membership_type_id':
+ case 'member_id':
+ if (strpos($name, 'status') !== FALSE) {
+ $name = 'status_id';
+ $qillName = 'Membership Status(s)';
}
- else {
- $status = implode(',', array_keys($value));
- if (count($value) > 0) {
- $op = 'IN';
- $status = "({$status})";
- }
+ elseif ($name == 'member_id') {
+ $name = 'id';
+ $qillName = 'Membership ID';
}
-
- $names = array();
- $statusTypes = CRM_Member_PseudoConstant::membershipStatus(NULL, NULL, 'label');
- foreach ($value as $id => $dontCare) {
- $names[] = $statusTypes[$id];
+ else {
+ $name = 'membership_type_id';
+ $qillName = 'Memebership Type(s)';
}
- $query->_qill[$grouping][] = ts('Membership Status %1', array(1 => $op)) . ' ' . implode(' ' . ts('or') . ' ', $names);
- $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_membership.status_id",
+ $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_membership.$name",
$op,
- $status,
+ $value,
"Integer"
);
+ list($op, $value) = CRM_Contact_BAO_Query::buildQillForFieldValue('CRM_Member_DAO_Membership', $name, $value, $op);
+ $query->_qill[$grouping][] = ts('%1 %2 %3', array(1 => $qillName, 2 => $op, 3 => $value));
$query->_tables['civicrm_membership'] = $query->_whereTables['civicrm_membership'] = 1;
return;
$query->_tables['civicrm_membership'] = $query->_whereTables['civicrm_membership'] = 1;
return;
- case 'membership_type':
- case 'member_membership_type_id':
- if (!is_array($value)) {
- $mType = $value;
- if (!empty($value)) {
- $value = array_flip(explode(",", str_replace(array('(', ')'), '', $value)));
- }
- else {
- $value = array();
- }
- }
- else {
- $mType = implode(',', array_keys($value));
- if (count($value) > 0) {
- $op = 'IN';
- $mType = "({$mType})";
- }
- }
-
- $names = array();
- $membershipTypes = CRM_Member_PseudoConstant::membershipType();
- foreach ($value as $id => $dontCare) {
- if (!empty($membershipTypes[$id])) {
- $names[] = $membershipTypes[$id];
- }
- }
- $query->_qill[$grouping][] = ts('Membership Type %1', array(1 => $op)) . ' ' . implode(' ' . ts('or') . ' ', $names);
- $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_membership.membership_type_id",
- $op,
- $mType,
- "Integer"
- );
- $query->_tables['civicrm_membership'] = $query->_whereTables['civicrm_membership'] = 1;
- return;
-
- case 'member_id':
- $query->_where[$grouping][] = " civicrm_membership.id $op $value";
- $query->_tables['civicrm_membership'] = $query->_whereTables['civicrm_membership'] = 1;
- return;
-
case 'member_is_primary':
if ($value) {
$query->_where[$grouping][] = " civicrm_membership.owner_membership_id IS NULL";
* @param CRM_Core_Form $form
*/
public static function buildSearchForm(&$form) {
- foreach (CRM_Member_PseudoConstant::membershipType() as $id => $Name) {
- $form->_membershipType = &$form->addElement('checkbox', "member_membership_type_id[$id]", NULL, $Name);
- }
+ $form->addSelect('status_id',
+ array('entity' => 'membership', 'multiple' => 'multiple', 'label' => ts('Memebership Status(s)'), 'option_url' => NULL, 'placeholder' => ts('- any -'))
+ );
- foreach (CRM_Member_PseudoConstant::membershipStatus(NULL, NULL, 'label') as $sId => $sName) {
- $form->_membershipStatus = &$form->addElement('checkbox', "member_status_id[$sId]", NULL, $sName);
- }
+ $form->addSelect('membership_type_id',
+ array('entity' => 'membership', 'multiple' => 'multiple', 'label' => ts('Memebership Type(s)'), 'option_url' => NULL, 'placeholder' => ts('- any -'))
+ );
$form->addElement('text', 'member_source', ts('Source'));
$this->_formValues["member_test"] = 0;
}
+ $specialParams = array(
+ 'status_id',
+ 'membership_type_id',
+ );
+ foreach ($specialParams as $element) {
+ $value = CRM_Utils_Array::value($element, $this->_formValues);
+ if (!empty($value) && is_array($value)) {
+ if ($element == 'status_id') {
+ unset($this->_formValues[$element]);
+ $element = 'member_' . $element;
+ }
+ $this->_formValues[$element] = array('IN' => $value);
+ }
+ }
+
CRM_Core_BAO_CustomValue::fixFieldValueOfTypeMemo($this->_formValues);
$this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues);
);
if ($status) {
$status = explode(',', $status);
- $tempStatus = array();
- foreach ($status as $value) {
- $tempStatus[$value] = 1;
- }
- $this->_formValues['member_status_id'] = $tempStatus;
- $this->_defaults['member_status_id'] = $tempStatus;
+ $this->_formValues['status_id'] = $this->_defaults['status_id'] = (array) $status;
}
$membershipType = CRM_Utils_Request::retrieve('type', 'String',
);
if ($membershipType) {
- $this->_formValues['member_membership_type_id'] = array($membershipType => 1);
- $this->_defaults['member_membership_type_id'] = array($membershipType => 1);
+ $this->_formValues['membership_type_id'] = array($membershipType);
+ $this->_defaults['membership_type_id'] = array($membershipType);
}
$cid = CRM_Utils_Request::retrieve('cid', 'Positive',
+--------------------------------------------------------------------+
*}
<tr>
- <td><label>{ts}Membership Type(s){/ts}</label><br />
- <div class="listing-box">
- {foreach from=$form.member_membership_type_id item="membership_type_val"}
- <div class="{cycle values='odd-row,even-row'}">
- {$membership_type_val.html}
- </div>
- {/foreach}
- </div>
+ <td><label>{$form.membership_type_id.label}</label><br />
+ {$form.membership_type_id.html|crmAddClass:twenty}
</td>
- <td><label>{ts}Membership Status{/ts}</label><br />
- <div class="listing-box">
- {foreach from=$form.member_status_id item="membership_status_val"}
- <div class="{cycle values='odd-row,even-row'}">
- {$membership_status_val.html}
- </div>
- {/foreach}
- </div>
+ <td><label>{$form.status_id.label}</label><br />
+ {$form.status_id.html|crmAddClass:twenty}
</td>
</tr>