Example #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();
 }
 /**
  * Assign test value.
  *
  * @param string $fieldName
  * @param array $fieldDef
  * @param int $counter
  */
 protected function assignTestValue($fieldName, &$fieldDef, $counter)
 {
     if ($fieldName == 'form_values') {
         // A dummy value for form_values.
         $this->{$fieldName} = serialize(array('sort_name' => "SortName{$counter}"));
     } else {
         parent::assignTestValues($fieldName, $fieldDef, $counter);
     }
 }
 /**
  * class constructor
  *
  * @return object CRM_Contact_BAO_SavedSearch
  */
 function CRM_Contact_BAO_SavedSearch()
 {
     parent::CRM_Contact_DAO_SavedSearch();
 }
 function save()
 {
     // first build the computed fields
     $this->buildClause();
     parent::save();
 }
 /**
  * returns the list of fields that can be exported
  *
  * @access public
  * return array
  */
 function &export($prefix = false)
 {
     if (!self::$_export) {
         self::$_export = array();
         $fields =& self::fields();
         foreach ($fields as $name => $field) {
             if (CRM_Utils_Array::value('export', $field)) {
                 if ($prefix) {
                     self::$_export['saved_search'] =& $fields[$name];
                 } else {
                     self::$_export[$name] =& $fields[$name];
                 }
             }
         }
     }
     return self::$_export;
 }
Example #6
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;
 }
 /**
  * Given a label and a set of normalized POST
  * formValues, create a smart group with that
  */
 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;
 }
Example #8
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();
 }
 /**
  * returns the list of fields that can be exported
  *
  * @access public
  * return array
  */
 function &export($prefix = false)
 {
     if (!$GLOBALS['_CRM_CONTACT_DAO_SAVEDSEARCH']['_export']) {
         $GLOBALS['_CRM_CONTACT_DAO_SAVEDSEARCH']['_export'] = array();
         $fields =& CRM_Contact_DAO_SavedSearch::fields();
         foreach ($fields as $name => $field) {
             if (CRM_Utils_Array::value('export', $field)) {
                 if ($prefix) {
                     $GLOBALS['_CRM_CONTACT_DAO_SAVEDSEARCH']['_export']['saved_search'] =& $fields[$name];
                 } else {
                     $GLOBALS['_CRM_CONTACT_DAO_SAVEDSEARCH']['_export'][$name] =& $fields[$name];
                 }
             }
         }
     }
     return $GLOBALS['_CRM_CONTACT_DAO_SAVEDSEARCH']['_export'];
 }