Esempio n. 1
0
 /**
  * Browse all saved searches.
  *
  * @return content of the parents run method
  *
  */
 function browse()
 {
     $rows = array();
     $savedSearch = new CRM_Contact_DAO_SavedSearch();
     $savedSearch->is_active = 1;
     $savedSearch->selectAdd();
     $savedSearch->selectAdd('id, form_values');
     $savedSearch->find();
     $properties = array('id', 'name', 'description');
     while ($savedSearch->fetch()) {
         // get name and description from group object
         $group = new CRM_Contact_DAO_Group();
         $group->saved_search_id = $savedSearch->id;
         if ($group->find(TRUE)) {
             $permissions = CRM_Group_Page_Group::checkPermission($group->id, $group->title);
             if (!CRM_Utils_System::isNull($permissions)) {
                 $row = array();
                 $row['name'] = $group->title;
                 $row['description'] = $group->description;
                 $row['id'] = $savedSearch->id;
                 $formValues = unserialize($savedSearch->form_values);
                 $query = new CRM_Contact_BAO_Query($formValues);
                 $row['query_detail'] = $query->qill();
                 $action = array_sum(array_keys(self::links()));
                 $action = $action & CRM_Core_Action::mask($permissions);
                 $row['action'] = CRM_Core_Action::formLink(self::links(), $action, array('id' => $row['id']));
                 $rows[] = $row;
             }
         }
     }
     $this->assign('rows', $rows);
     return parent::run();
 }
Esempio n. 2
0
 /**
  * Retrieve DB object based on input parameters.
  *
  * It also stores all the retrieved values in the default array.
  *
  * @param array $params
  *   (reference ) an assoc array of name/value pairs.
  * @param array $defaults
  *   (reference ) an assoc array to hold the flattened values.
  *
  * @return CRM_Contact_BAO_SavedSearch
  */
 public static function retrieve(&$params, &$defaults)
 {
     $savedSearch = new CRM_Contact_DAO_SavedSearch();
     $savedSearch->copyValues($params);
     if ($savedSearch->find(TRUE)) {
         CRM_Core_DAO::storeValues($savedSearch, $defaults);
         return $savedSearch;
     }
     return NULL;
 }
Esempio n. 3
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. 4
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();
 }