CRM-18585 - Fix Smart Group operator
[civicrm-core.git] / CRM / Contact / Form / Task / SaveSearch.php
index 62f3ee8a9285d4cfbc84b9b04284f0a71e07e280..e0f56101993a2dfc1687074550d08841cdbc4ba6 100644 (file)
@@ -180,6 +180,11 @@ class CRM_Contact_Form_Task_SaveSearch extends CRM_Contact_Form_Task {
     //save the search
     $savedSearch = new CRM_Contact_BAO_SavedSearch();
     $savedSearch->id = $this->_id;
+    $queryParams = $this->get('queryParams');
+    // CRM-18585 include selected operator in $savedSearch->form_values
+    if (!empty($formValues['operator'])) {
+      $queryParams[] = array('operator', '=', $formValues['operator'], 0, 0);
+    }
     // Use the query parameters rather than the form values - these have already been assessed / converted
     // with the extra knowledge that the form has.
     // Note that we want to move towards a standardised way of saving the query that is not
@@ -187,7 +192,7 @@ class CRM_Contact_Form_Task_SaveSearch extends CRM_Contact_Form_Task {
     // Ideally per CRM-17075 we will use entity reference fields heavily in the form layer & convert to the
     // sql operator syntax at the query layer.
     if (!$isSearchBuilder) {
-      $savedSearch->form_values = serialize($this->get('queryParams'));
+      $savedSearch->form_values = serialize($queryParams);
     }
     else {
       // We want search builder to be able to convert back & forth at the form layer