Esempio n. 1
0
 /**
  * Delete a saved search.
  *
  * @param int $id
  *   Id of saved search.
  */
 public function delete($id)
 {
     // first delete the group associated with this saved search
     $group = new CRM_Contact_DAO_Group();
     $group->saved_search_id = $id;
     if ($group->find(TRUE)) {
         CRM_Contact_BAO_Group::discard($group->id);
     }
     $savedSearch = new CRM_Contact_DAO_SavedSearch();
     $savedSearch->id = $id;
     $savedSearch->is_active = 0;
     $savedSearch->save();
 }
Esempio n. 2
0
 /**
  * Create a smart group from normalised values.
  *
  * @param array $params
  *
  * @return \CRM_Contact_DAO_SavedSearch
  */
 public static function create(&$params)
 {
     $savedSearch = new CRM_Contact_DAO_SavedSearch();
     if (isset($params['formValues']) && !empty($params['formValues'])) {
         $savedSearch->form_values = serialize($params['formValues']);
     } else {
         $savedSearch->form_values = NULL;
     }
     $savedSearch->is_active = CRM_Utils_Array::value('is_active', $params, 1);
     $savedSearch->mapping_id = CRM_Utils_Array::value('mapping_id', $params, 'null');
     $savedSearch->custom_search_id = CRM_Utils_Array::value('custom_search_id', $params, 'null');
     $savedSearch->id = CRM_Utils_Array::value('id', $params, NULL);
     $savedSearch->save();
     return $savedSearch;
 }
Esempio n. 3
0
 function save()
 {
     // first build the computed fields
     $this->buildClause();
     parent::save();
 }
Esempio n. 4
0
 /**
  * Change saved search.
  *
  * @param \CRM_Queue_TaskContext $ctx
  *
  * @return bool
  */
 public static function changeSavedSearch(CRM_Queue_TaskContext $ctx)
 {
     $membershipStatuses = array_flip(CRM_Member_PseudoConstant::membershipStatus());
     $dao = new CRM_Contact_DAO_SavedSearch();
     $dao->find();
     while ($dao->fetch()) {
         $formValues = NULL;
         if (!empty($dao->form_values)) {
             $formValues = unserialize($dao->form_values);
         }
         if (!empty($formValues['mapper'])) {
             foreach ($formValues['mapper'] as $key => $value) {
                 foreach ($value as $k => $v) {
                     if ($v[0] == 'Membership' && in_array($v[1], array('membership_status', 'membership_status_id'))) {
                         $value = $formValues['value'][$key][$k];
                         $op = $formValues['operator'][$key][$k];
                         if ($op == 'IN') {
                             $value = trim($value);
                             $value = str_replace('(', '', $value);
                             $value = str_replace(')', '', $value);
                             $v = explode(',', $value);
                             $value = array();
                             foreach ($v as $k1 => $v2) {
                                 if (is_numeric($v2)) {
                                     break 2;
                                 }
                                 $value[$k1] = $membershipStatuses[$v2];
                             }
                             $formValues['value'][$key][$k] = "(" . implode(',', $value) . ")";
                         } elseif (in_array($op, array('=', '!='))) {
                             if (is_numeric($value)) {
                                 break;
                             }
                             $formValues['value'][$key][$k] = $membershipStatuses[$value];
                         }
                     }
                 }
             }
             $dao->form_values = serialize($formValues);
             $dao->save();
         }
     }
     return TRUE;
 }
Esempio n. 5
0
 /**
  * Function to deal with groups that may have been mis-saved during a glitch.
  *
  * This deals with groups that may have been saved with differing mapping parameters than
  * the latest supported ones.
  *
  * @param int $id
  * @param array $formValues
  */
 public function tempFixFormValues($id, &$formValues)
 {
     $mappingID = CRM_Core_DAO::singleValueQuery('SELECT mapping_id FROM civicrm_saved_search WHERE id = %1', array(1 => array($id, 'Integer')));
     $addressFields = civicrm_api3('Address', 'getfields');
     $options = self::fieldOptions();
     $entities = array('contact', 'address', 'activity', 'participant', 'pledge', 'membership', 'contribution', 'case', 'grant');
     if (empty($formValues['mapper']) && $mappingID) {
         $mappingFields = CRM_Core_BAO_Mapping::getMappingFields($mappingID);
         foreach ($mappingFields[0][1] as $index => $mappingField) {
             $formValues['mapper'][1][$index] = array($mappingFields[1][1][$index], $mappingFields[0][1][$index]);
             $formValues['operator'][1][$index] = $mappingFields[6][1][$index];
             $formValues['value'][1][$index] = $mappingFields[7][1][$index];
         }
     }
     /*
       foreach ($formValues['mapper'] as $index => $fields) {
         foreach ($fields as $fieldIndex => $field) {
           $entity = $options[$field[1]];
           if ($entity == 'contact' || isset($addressFields['values'][$field[1]])) {
     
             $existing = (CRM_Core_DAO::singleValueQuery("SELECT contact_type FROM civicrm_mapping_field WHERE mapping_id = $mappingID AND grouping = $index AND column_number = $fieldIndex"));
             if ($existing != 'Contact') {
               $formValues['mapper'][$index][$fieldIndex][0] = 'Contact';
               //CRM_Core_DAO::executeQuery("UPDATE civicrm_mapping_field SET contact_type = 'Contact' WHERE mapping_id = $mappingID AND grouping = $index AND column_number = $fieldIndex");
             }
           }
           if (in_array($entity, $entities)) {
             $values = civicrm_api3($entity, 'getoptions', array('field' => $field[1]));
             $currentValue = $formValues['value'][$index][$fieldIndex];
             if (!isset($values['values'][$currentValue]) && in_array($currentValue, $values['values'])) {
               $newValue = array_search($currentValue, $values['values']);
               $formValues['value'][$index][$fieldIndex] = $newValue;
               //CRM_Core_DAO::executeQuery("UPDATE civicrm_mapping_field SET value = $newValue WHERE mapping_id = $mappingID AND grouping = $index AND column_number = $fieldIndex");
     
             }
           }
           /*
           $i = $index;
           while ($i > 0) {
             if ($fields == $formValues['mapper'][$i] && ($formValues['operator'][$i] == $formValues['operator'][$index]) && '=' == $formValues['operator'][$index]) {
             }
             $i--;
           }
     
         }
       }
     */
     $savedSearch = new CRM_Contact_DAO_SavedSearch();
     $savedSearch->id = $id;
     $savedSearch->find(TRUE);
     $tables = $whereTables = array();
     $savedSearch->where_clause = CRM_Contact_BAO_Query::getWhereClause($formValues, NULL, $tables, $whereTables);
     if (!empty($tables)) {
         $savedSearch->select_tables = serialize($tables);
     }
     if (!empty($whereTables)) {
         $savedSearch->where_tables = serialize($whereTables);
     }
     $savedSearch->form_values = serialize($formValues);
     $savedSearch->save();
 }