Exemplo n.º 1
0
 /**
  * Function to get the list of contacts for a profile
  * 
  * @param $form object 
  *
  * @access public
  */
 function getProfileContact($gid)
 {
     $session =& CRM_Core_Session::singleton();
     $params = $session->get('profileParams');
     $details = array();
     $ufGroupParam = array('id' => $gid);
     require_once "CRM/Core/BAO/UFGroup.php";
     CRM_Core_BAO_UFGroup::retrieve($ufGroupParam, $details);
     // make sure this group can be mapped
     if (!$details['is_map']) {
         CRM_Core_Error::statusBounce(ts('This profile does not have the map feature turned on.'));
     }
     $groupId = CRM_Utils_Array::value('limit_listings_group_id', $details);
     // add group id to params if a uf group belong to a any group
     if ($groupId) {
         if (CRM_Utils_Array::value('group', $params)) {
             $params['group'][$groupId] = 1;
         } else {
             $params['group'] = array($groupId => 1);
         }
     }
     $fields = CRM_Core_BAO_UFGroup::getListingFields(CRM_Core_Action::VIEW, CRM_Core_BAO_UFGroup::PUBLIC_VISIBILITY | CRM_Core_BAO_UFGroup::LISTINGS_VISIBILITY, false, $gid);
     $returnProperties =& CRM_Contact_BAO_Contact::makeHierReturnProperties($fields);
     $returnProperties['contact_type'] = 1;
     $returnProperties['sort_name'] = 1;
     $queryParams =& CRM_Contact_BAO_Query::convertFormValues($params, 1);
     $query =& new CRM_Contact_BAO_Query($queryParams, $returnProperties, $fields);
     $ids = $query->searchQuery(0, 0, null, false, false, false, true, false);
     $contactIds = explode(',', $ids);
     return $contactIds;
 }
Exemplo n.º 2
0
 /**
  * Class constructor
  *
  * @param $customSearchClass
  * @param array $formValues array of form values imported
  * @param array $params array of parameters for query
  * @param null $returnProperties
  * @param \const|int $action - action of search basic or advanced.
  *
  * @param bool $includeContactIds
  * @param bool $searchDescendentGroups
  * @param string $searchContext
  * @param null $contextMenu
  *
  * @return CRM_Contact_Selector
  * @access public
  */
 function __construct($customSearchClass, $formValues = NULL, $params = NULL, $returnProperties = NULL, $action = CRM_Core_Action::NONE, $includeContactIds = FALSE, $searchDescendentGroups = TRUE, $searchContext = 'search', $contextMenu = NULL)
 {
     //don't build query constructor, if form is not submitted
     $force = CRM_Utils_Request::retrieve('force', 'Boolean', CRM_Core_DAO::$_nullObject);
     if (empty($formValues) && !$force) {
         return;
     }
     // submitted form values
     $this->_formValues =& $formValues;
     $this->_params =& $params;
     $this->_returnProperties =& $returnProperties;
     $this->_contextMenu =& $contextMenu;
     $this->_context = $searchContext;
     // type of selector
     $this->_action = $action;
     $this->_searchContext = $searchContext;
     $this->_ufGroupID = CRM_Utils_Array::value('uf_group_id', $this->_formValues);
     if ($this->_ufGroupID) {
         $this->_fields = CRM_Core_BAO_UFGroup::getListingFields(CRM_Core_Action::VIEW, CRM_Core_BAO_UFGroup::PUBLIC_VISIBILITY | CRM_Core_BAO_UFGroup::LISTINGS_VISIBILITY, FALSE, $this->_ufGroupID);
         self::$_columnHeaders = NULL;
         $this->_customFields = CRM_Core_BAO_CustomField::getFieldsForImport('Individual');
         $this->_returnProperties = CRM_Contact_BAO_Contact::makeHierReturnProperties($this->_fields);
         $this->_returnProperties['contact_type'] = 1;
         $this->_returnProperties['contact_sub_type'] = 1;
         $this->_returnProperties['sort_name'] = 1;
     }
     $displayRelationshipType = CRM_Utils_Array::value('display_relationship_type', $this->_formValues);
     $operator = CRM_Utils_Array::value('operator', $this->_formValues, 'AND');
     // rectify params to what proximity search expects if there is a value for prox_distance
     // CRM-7021
     if (!empty($this->_params)) {
         CRM_Contact_BAO_ProximityQuery::fixInputParams($this->_params);
     }
     $this->_query = new CRM_Contact_BAO_Query($this->_params, $this->_returnProperties, NULL, $includeContactIds, FALSE, CRM_Contact_BAO_Query::MODE_CONTACTS, FALSE, $searchDescendentGroups, FALSE, $displayRelationshipType, $operator);
     $this->_options =& $this->_query->_options;
 }
Exemplo n.º 3
0
 /**
  * Class constructor
  *
  * @param string params the params for the where clause
  *
  * @return CRM_Contact_Selector_Profile
  * @access public
  */
 function __construct(&$params, &$customFields, $ufGroupIds = NULL, $map = FALSE, $editLink = FALSE, $linkToUF = FALSE)
 {
     $this->_params = $params;
     if (is_array($ufGroupIds)) {
         $this->_profileIds = $ufGroupIds;
         $this->_gid = $ufGroupIds[0];
     } else {
         $this->_profileIds = array($ufGroupIds);
         $this->_gid = $ufGroupIds;
     }
     $this->_map = $map;
     $this->_editLink = $editLink;
     $this->_linkToUF = $linkToUF;
     //get the details of the uf group
     if ($this->_gid) {
         $groupId = CRM_Core_DAO::getFieldValue('CRM_Core_BAO_UFGroup', $this->_gid, 'limit_listings_group_id');
     }
     // add group id to params if a uf group belong to a any group
     if ($groupId) {
         if (!empty($this->_params['group'])) {
             $this->_params['group'][$groupId] = 1;
         } else {
             $this->_params['group'] = array($groupId => 1);
         }
     }
     $this->_fields = CRM_Core_BAO_UFGroup::getListingFields(CRM_Core_Action::VIEW, CRM_Core_BAO_UFGroup::PUBLIC_VISIBILITY | CRM_Core_BAO_UFGroup::LISTINGS_VISIBILITY, FALSE, $this->_profileIds);
     $this->_customFields =& $customFields;
     $returnProperties = CRM_Contact_BAO_Contact::makeHierReturnProperties($this->_fields);
     $returnProperties['contact_type'] = 1;
     $returnProperties['contact_sub_type'] = 1;
     $returnProperties['sort_name'] = 1;
     $queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_params, 1);
     $this->_query = new CRM_Contact_BAO_Query($queryParams, $returnProperties, $this->_fields);
     //the below is done for query building for multirecord custom field listing
     //to show all the custom field multi valued records of a particular contact
     $this->setMultiRecordTableName($this->_fields);
     $this->_options =& $this->_query->_options;
 }
Exemplo n.º 4
0
 /**
  * Given a contact id and a field set, return the values from the db
  * for this contact
  *
  * @param int $cid
  * @param array $fields
  *   The profile fields of interest.
  * @param array $values
  *   The values for the above fields.
  * @param bool $searchable
  *   Searchable or not.
  * @param array $componentWhere
  *   Component condition.
  * @param bool $absolute
  *   Return urls in absolute form (useful when sending an email).
  * @param null $additionalWhereClause
  */
 public static function getValues($cid, &$fields, &$values, $searchable = TRUE, $componentWhere = NULL, $absolute = FALSE, $additionalWhereClause = NULL)
 {
     if (empty($cid) && empty($componentWhere)) {
         return NULL;
     }
     // get the contact details (hier)
     $returnProperties = CRM_Contact_BAO_Contact::makeHierReturnProperties($fields);
     $params = $cid ? array(array('contact_id', '=', $cid, 0, 0)) : array();
     // add conditions specified by components. eg partcipant_id etc
     if (!empty($componentWhere)) {
         $params = array_merge($params, $componentWhere);
     }
     $query = new CRM_Contact_BAO_Query($params, $returnProperties, $fields);
     $options =& $query->_options;
     $details = $query->searchQuery(0, 0, NULL, FALSE, FALSE, FALSE, FALSE, FALSE, $additionalWhereClause);
     if (!$details->fetch()) {
         return;
     }
     $query->convertToPseudoNames($details);
     $config = CRM_Core_Config::singleton();
     $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id');
     $imProviders = CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id');
     $websiteTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Website', 'website_type_id');
     $multipleFields = array('url');
     //start of code to set the default values
     foreach ($fields as $name => $field) {
         // fix for CRM-3962
         if ($name == 'id') {
             $name = 'contact_id';
         }
         // skip fields that should not be displayed separately
         if (!empty($field['skipDisplay'])) {
             continue;
         }
         // Create a unique, non-empty index for each field.
         $index = $field['title'];
         if ($index === '') {
             $index = ' ';
         }
         while (array_key_exists($index, $values)) {
             $index .= ' ';
         }
         $params[$index] = $values[$index] = '';
         $customFieldName = NULL;
         // hack for CRM-665
         if (isset($details->{$name}) || $name == 'group' || $name == 'tag') {
             // to handle gender / suffix / prefix
             if (in_array(substr($name, 0, -3), array('gender', 'prefix', 'suffix'))) {
                 $params[$index] = $details->{$name};
                 $values[$index] = $details->{$name};
             } elseif (in_array($name, CRM_Contact_BAO_Contact::$_greetingTypes)) {
                 $dname = $name . '_display';
                 $values[$index] = $details->{$dname};
                 $name = $name . '_id';
                 $params[$index] = $details->{$name};
             } elseif (in_array($name, array('state_province', 'country', 'county'))) {
                 $values[$index] = $details->{$name};
                 $idx = $name . '_id';
                 $params[$index] = $details->{$idx};
             } elseif ($name === 'preferred_communication_method') {
                 $communicationFields = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'preferred_communication_method');
                 $compref = array();
                 $pref = explode(CRM_Core_DAO::VALUE_SEPARATOR, $details->{$name});
                 foreach ($pref as $k) {
                     if ($k) {
                         $compref[] = $communicationFields[$k];
                     }
                 }
                 $params[$index] = $details->{$name};
                 $values[$index] = implode(',', $compref);
             } elseif ($name === 'preferred_language') {
                 $params[$index] = $details->{$name};
                 $values[$index] = CRM_Core_PseudoConstant::getLabel('CRM_Contact_DAO_Contact', 'preferred_language', $details->{$name});
             } elseif ($name == 'group') {
                 $groups = CRM_Contact_BAO_GroupContact::getContactGroup($cid, 'Added', NULL, FALSE, TRUE);
                 $title = $ids = array();
                 foreach ($groups as $g) {
                     // CRM-8362: User and User Admin visibility groups should be included in display if user has
                     // VIEW permission on that group
                     $groupPerm = CRM_Contact_BAO_Group::checkPermission($g['group_id'], $g['title']);
                     if ($g['visibility'] != 'User and User Admin Only' || CRM_Utils_Array::key(CRM_Core_Permission::VIEW, $groupPerm)) {
                         $title[] = $g['title'];
                         if ($g['visibility'] == 'Public Pages') {
                             $ids[] = $g['group_id'];
                         }
                     }
                 }
                 $values[$index] = implode(', ', $title);
                 $params[$index] = implode(',', $ids);
             } elseif ($name == 'tag') {
                 $entityTags = CRM_Core_BAO_EntityTag::getTag($cid);
                 $allTags = CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
                 $title = array();
                 foreach ($entityTags as $tagId) {
                     $title[] = $allTags[$tagId];
                 }
                 $values[$index] = implode(', ', $title);
                 $params[$index] = implode(',', $entityTags);
             } elseif ($name == 'activity_status_id') {
                 $activityStatus = CRM_Core_PseudoConstant::activityStatus();
                 $values[$index] = $activityStatus[$details->{$name}];
                 $params[$index] = $details->{$name};
             } elseif ($name == 'activity_date_time') {
                 $values[$index] = CRM_Utils_Date::customFormat($details->{$name});
                 $params[$index] = $details->{$name};
             } elseif ($name == 'contact_sub_type') {
                 $contactSubTypeNames = explode(CRM_Core_DAO::VALUE_SEPARATOR, $details->{$name});
                 if (!empty($contactSubTypeNames)) {
                     $contactSubTypeLabels = array();
                     // get all contact subtypes
                     $allContactSubTypes = CRM_Contact_BAO_ContactType::subTypeInfo();
                     // build contact subtype labels array
                     foreach ($contactSubTypeNames as $cstName) {
                         if ($cstName) {
                             $contactSubTypeLabels[] = $allContactSubTypes[$cstName]['label'];
                         }
                     }
                     $values[$index] = implode(',', $contactSubTypeLabels);
                 }
                 $params[$index] = $details->{$name};
             } else {
                 if (substr($name, 0, 7) === 'do_not_' || substr($name, 0, 3) === 'is_') {
                     if ($details->{$name}) {
                         $values[$index] = '[ x ]';
                     }
                 } else {
                     if ($cfID = CRM_Core_BAO_CustomField::getKeyID($name)) {
                         $htmlType = $field['html_type'];
                         // field_type is only set when we are retrieving profile values
                         // when sending email, we call the same function to get custom field
                         // values etc, i.e. emulating a profile
                         $fieldType = CRM_Utils_Array::value('field_type', $field);
                         if ($htmlType == 'File') {
                             $entityId = $cid;
                             if (!$cid && $fieldType == 'Activity' && !empty($componentWhere[0][2])) {
                                 $entityId = $componentWhere[0][2];
                             }
                             $fileURL = CRM_Core_BAO_CustomField::getFileURL($entityId, $cfID, NULL, $absolute, $additionalWhereClause);
                             $params[$index] = $values[$index] = $fileURL['file_url'];
                         } else {
                             $customVal = NULL;
                             if (isset($dao) && property_exists($dao, 'data_type') && ($dao->data_type == 'Int' || $dao->data_type == 'Boolean')) {
                                 $customVal = (int) $details->{$name};
                             } elseif (isset($dao) && property_exists($dao, 'data_type') && $dao->data_type == 'Float') {
                                 $customVal = (double) $details->{$name};
                             } elseif (!CRM_Utils_System::isNull(explode(CRM_Core_DAO::VALUE_SEPARATOR, $details->{$name}))) {
                                 $customVal = $details->{$name};
                             }
                             //CRM-4582
                             if (CRM_Utils_System::isNull($customVal)) {
                                 continue;
                             }
                             $params[$index] = $customVal;
                             $values[$index] = CRM_Core_BAO_CustomField::getDisplayValue($customVal, $cfID, $options);
                             if ($field['data_type'] == 'ContactReference') {
                                 $params[$index] = $values[$index];
                             }
                             if (CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $cfID, 'is_search_range')) {
                                 $customFieldName = "{$name}_from";
                             }
                         }
                     } elseif ($name == 'image_URL') {
                         list($width, $height) = getimagesize(CRM_Utils_String::unstupifyUrl($details->{$name}));
                         list($thumbWidth, $thumbHeight) = CRM_Contact_BAO_Contact::getThumbSize($width, $height);
                         $image_URL = '<img src="' . $details->{$name} . '" height= ' . $thumbHeight . ' width= ' . $thumbWidth . '  />';
                         $values[$index] = "<a href='#' onclick='contactImagePopUp(\"{$details->{$name}}\", {$width}, {$height});'>{$image_URL}</a>";
                     } elseif (in_array($name, array('birth_date', 'deceased_date', 'membership_start_date', 'membership_end_date', 'join_date'))) {
                         $values[$index] = CRM_Utils_Date::customFormat($details->{$name});
                         $params[$index] = CRM_Utils_Date::isoToMysql($details->{$name});
                     } else {
                         $dao = '';
                         if ($index == 'Campaign') {
                             $dao = 'CRM_Campaign_DAO_Campaign';
                         } elseif ($index == 'Contribution Page') {
                             $dao = 'CRM_Contribute_DAO_ContributionPage';
                         }
                         if ($dao) {
                             $value = CRM_Core_DAO::getFieldValue($dao, $details->{$name}, 'title');
                         } else {
                             $value = $details->{$name};
                         }
                         $values[$index] = $value;
                     }
                 }
             }
         } elseif (strpos($name, '-') !== FALSE) {
             list($fieldName, $id, $type) = CRM_Utils_System::explode('-', $name, 3);
             if (!in_array($fieldName, $multipleFields)) {
                 if ($id == 'Primary') {
                     // fix for CRM-1543
                     // not sure why we'd every use Primary location type id
                     // we need to fix the source if we are using it
                     // $locationTypeName = CRM_Contact_BAO_Contact::getPrimaryLocationType( $cid );
                     $locationTypeName = 1;
                 } else {
                     $locationTypeName = CRM_Utils_Array::value($id, $locationTypes);
                 }
                 if (!$locationTypeName) {
                     continue;
                 }
                 $detailName = "{$locationTypeName}-{$fieldName}";
                 $detailName = str_replace(' ', '_', $detailName);
                 if (in_array($fieldName, array('phone', 'im', 'email', 'openid'))) {
                     if ($type) {
                         $detailName .= "-{$type}";
                     }
                 }
                 if (in_array($fieldName, array('state_province', 'country', 'county'))) {
                     $values[$index] = $details->{$detailName};
                     $idx = $detailName . '_id';
                     $params[$index] = $details->{$idx};
                 } elseif ($fieldName == 'im') {
                     $providerId = $detailName . '-provider_id';
                     if (isset($imProviders[$details->{$providerId}])) {
                         $values[$index] = $details->{$detailName} . " (" . $imProviders[$details->{$providerId}] . ")";
                     } else {
                         $values[$index] = $details->{$detailName};
                     }
                     $params[$index] = $details->{$detailName};
                 } elseif ($fieldName == 'phone') {
                     $phoneExtField = str_replace('phone', 'phone_ext', $detailName);
                     if (isset($details->{$phoneExtField})) {
                         $values[$index] = $details->{$detailName} . " (" . $details->{$phoneExtField} . ")";
                     } else {
                         $values[$index] = $details->{$detailName};
                     }
                     $params[$index] = $details->{$detailName};
                 } else {
                     $values[$index] = $params[$index] = $details->{$detailName};
                 }
             } else {
                 $detailName = "website-{$id}-{$fieldName}";
                 $url = CRM_Utils_System::fixURL($details->{$detailName});
                 if ($details->{$detailName}) {
                     $websiteTypeId = "website-{$id}-website_type_id";
                     $websiteType = $websiteTypes[$details->{$websiteTypeId}];
                     $values[$index] = "<a href=\"{$url}\">{$details->{$detailName}} ( {$websiteType} )</a>";
                 } else {
                     $values[$index] = '';
                 }
             }
         }
         if (CRM_Utils_Array::value('visibility', $field) == 'Public Pages and Listings' && CRM_Core_Permission::check('profile listings and forms')) {
             if (CRM_Utils_System::isNull($params[$index])) {
                 $params[$index] = $values[$index];
             }
             if (!isset($params[$index])) {
                 continue;
             }
             if (!$customFieldName) {
                 $fieldName = $field['name'];
             } else {
                 $fieldName = $customFieldName;
             }
             $url = NULL;
             if (CRM_Core_BAO_CustomField::getKeyID($field['name'])) {
                 $htmlType = $field['html_type'];
                 if ($htmlType == 'Link') {
                     $url = $params[$index];
                 } elseif (in_array($htmlType, array('CheckBox', 'Multi-Select', 'AdvMulti-Select', 'Multi-Select State/Province', 'Multi-Select Country'))) {
                     $valSeperator = CRM_Core_DAO::VALUE_SEPARATOR;
                     $selectedOptions = explode($valSeperator, $params[$index]);
                     foreach ($selectedOptions as $key => $multiOption) {
                         if ($multiOption) {
                             $url[] = CRM_Utils_System::url('civicrm/profile', 'reset=1&force=1&gid=' . $field['group_id'] . '&' . urlencode($fieldName) . '=' . urlencode($multiOption));
                         }
                     }
                 } else {
                     $url = CRM_Utils_System::url('civicrm/profile', 'reset=1&force=1&gid=' . $field['group_id'] . '&' . urlencode($fieldName) . '=' . urlencode($params[$index]));
                 }
             } else {
                 $url = CRM_Utils_System::url('civicrm/profile', 'reset=1&force=1&gid=' . $field['group_id'] . '&' . urlencode($fieldName) . '=' . urlencode($params[$index]));
             }
             if ($url && !empty($values[$index]) && $searchable) {
                 if (is_array($url) && !empty($url)) {
                     $links = array();
                     $eachMultiValue = explode(', ', $values[$index]);
                     foreach ($eachMultiValue as $key => $valueLabel) {
                         $links[] = '<a href="' . $url[$key] . '">' . $valueLabel . '</a>';
                     }
                     $values[$index] = implode(', ', $links);
                 } else {
                     $values[$index] = '<a href="' . $url . '">' . $values[$index] . '</a>';
                 }
             }
         }
     }
 }
Exemplo n.º 5
0
 /**
  * Given a contact id and a field set, return the values from the db
  * for this contact
  *
  * @param int     $id       the contact id
  * @param array   $fields   the profile fields of interest
  * @param array   $values   the values for the above fields
  * @return void
  * @access public
  * @static
  */
 function getValues($cid, &$fields, &$values)
 {
     $options = array();
     // get the contact details (hier)
     $returnProperties =& CRM_Contact_BAO_Contact::makeHierReturnProperties($fields);
     $params = array('id' => $cid);
     $query =& new CRM_Contact_BAO_Query($params, $returnProperties, $fields);
     $options =& $query->_options;
     $details = $query->searchQuery();
     if (!$details->fetch()) {
         return;
     }
     require_once 'CRM/Core/PseudoConstant.php';
     $locationTypes = CRM_Core_PseudoConstant::locationType();
     //start of code to set the default values
     foreach ($fields as $name => $field) {
         $index = $field['title'];
         $params[$index] = $values[$index] = '';
         if ($details->{$name} || $name == 'group' || $name == 'tag') {
             //hack for CRM-665
             //to handle custom data (checkbox) to be written
             // to handle gender / suffix / prefix
             if (in_array($name, array('gender', 'individual_prefix', 'individual_suffix'))) {
                 $values[$index] = $details->{$name};
                 $name = $name . '_id';
                 $params[$index] = $details->{$name};
             } else {
                 if (in_array($name, array('state_province', 'country'))) {
                     $values[$index] = $details->{$name};
                     $idx = $name . '_id';
                     $params[$index] = $details->{$idx};
                 } else {
                     if (substr($name, 0, 7) === 'do_not_' or substr($name, 0, 3) === 'is_') {
                         if ($details->{$name}) {
                             $values[$index] = '[ x ]';
                         }
                     } else {
                         if ($name == 'group') {
                             $groups = CRM_Contact_BAO_GroupContact::getContactGroup($cid, 'Added', null, false, true);
                             $title = array();
                             $ids = array();
                             foreach ($groups as $g) {
                                 if ($g['visibility'] != 'User and User Admin Only') {
                                     $title[] = $g['title'];
                                     if ($g['visibility'] == 'Public User Pages and Listings') {
                                         $ids[] = $g['group_id'];
                                     }
                                 }
                             }
                             $values[$index] = implode(', ', $title);
                             $params[$index] = implode(',', $ids);
                         } else {
                             if ($name == 'tag') {
                                 require_once 'CRM/Core/BAO/EntityTag.php';
                                 $entityTags =& CRM_Core_BAO_EntityTag::getTag('civicrm_contact', $cid);
                                 $allTags =& CRM_Core_PseudoConstant::tag();
                                 $title = array();
                                 foreach ($entityTags as $tagId) {
                                     $title[] = $allTags[$tagId];
                                 }
                                 $values[$index] = implode(', ', $title);
                                 $params[$index] = implode(',', $entityTags);
                             } else {
                                 require_once 'CRM/Core/BAO/CustomField.php';
                                 if ($cfID = CRM_Core_BAO_CustomField::getKeyID($name)) {
                                     $params[$index] = $details->{$name};
                                     $values[$index] = CRM_Core_BAO_CustomField::getDisplayValue($details->{$name}, $cfID, $options);
                                 } else {
                                     $values[$index] = $details->{$name};
                                 }
                             }
                         }
                     }
                 }
             }
         } else {
             if (strpos($name, '-') !== false) {
                 list($fieldName, $id, $type) = explode('-', $name);
                 $locationTypeName = CRM_Utils_Array::value($id, $locationTypes);
                 if (!$locationTypeName) {
                     continue;
                 }
                 $detailName = "{$locationTypeName}-{$fieldName}";
                 if (in_array($fieldName, array('phone', 'im', 'email'))) {
                     if ($type) {
                         $detailName .= "-{$type}";
                     } else {
                         $detailName .= '-1';
                     }
                 }
                 if (in_array($fieldName, array('state_province', 'country'))) {
                     $values[$index] = $details->{$detailName};
                     $idx = $detailName . '_id';
                     $params[$index] = $details->{$idx};
                 } else {
                     $values[$index] = $params[$index] = $details->{$detailName};
                 }
             }
         }
         if ($field['visibility'] == "Public User Pages and Listings" && CRM_Utils_System::checkPermission('profile listings and forms')) {
             if (CRM_Utils_System::isNull($params[$index])) {
                 $params[$index] = $values[$index];
             }
             if (empty($params[$index])) {
                 continue;
             }
             $fieldName = $field['name'];
             $url = CRM_Utils_System::url('civicrm/profile', 'reset=1&force=1&gid=' . $field['group_id'] . '&' . urlencode($fieldName) . '=' . urlencode($params[$index]));
             if (!empty($values[$index])) {
                 $values[$index] = '<a href="' . $url . '">' . $values[$index] . '</a>';
             }
         }
     }
 }
Exemplo n.º 6
0
 /**
  * Given a contact id and a field set, return the values from the db
  * for this contact
  *
  * @param int     $id             the contact id
  * @param array   $fields         the profile fields of interest
  * @param array   $values         the values for the above fields
  * @param boolean $searchable     searchable or not
  * @param array   $componentWhere component condition
  *
  * @return void
  * @access public
  * @static
  */
 public static function getValues($cid, &$fields, &$values, $searchable = true, $componentWhere = null)
 {
     if (empty($cid)) {
         return null;
     }
     $options = array();
     $studentFields = array();
     if (CRM_Core_Permission::access('Quest', false)) {
         //student fields ( check box )
         require_once 'CRM/Quest/BAO/Student.php';
         $studentFields = CRM_Quest_BAO_Student::$multipleSelectFields;
     }
     // get the contact details (hier)
     $returnProperties =& CRM_Contact_BAO_Contact::makeHierReturnProperties($fields);
     $params = array(array('contact_id', '=', $cid, 0, 0));
     // add conditions specified by components. eg partcipant_id etc
     if (!empty($componentWhere)) {
         $params = array_merge($params, $componentWhere);
     }
     $query =& new CRM_Contact_BAO_Query($params, $returnProperties, $fields);
     $options =& $query->_options;
     $details = $query->searchQuery();
     if (!$details->fetch()) {
         return;
     }
     $config =& CRM_Core_Config::singleton();
     require_once 'CRM/Core/PseudoConstant.php';
     $locationTypes = $imProviders = array();
     $locationTypes = CRM_Core_PseudoConstant::locationType();
     $imProviders = CRM_Core_PseudoConstant::IMProvider();
     //start of code to set the default values
     foreach ($fields as $name => $field) {
         // fix for CRM-3962
         if ($name == 'id') {
             $name = 'contact_id';
         }
         $index = $field['title'];
         $params[$index] = $values[$index] = '';
         $customFieldName = null;
         $elements = array('email_greeting_custom' => 'email_greeting', 'postal_greeting_custom' => 'postal_greeting', 'addressee_custom' => 'addressee');
         if (isset($details->{$name}) || $name == 'group' || $name == 'tag') {
             //hack for CRM-665
             // to handle gender / suffix / prefix
             if (in_array($name, array('gender', 'individual_prefix', 'individual_suffix'))) {
                 $values[$index] = $details->{$name};
                 $name = $name . '_id';
                 $params[$index] = $details->{$name};
             } else {
                 if (in_array($name, array('email_greeting', 'postal_greeting', 'addressee'))) {
                     $dname = $name . '_display';
                     $values[$index] = $details->{$dname};
                     $name = $name . '_id';
                     $params[$index] = $details->{$name};
                 } else {
                     if (in_array($name, array('state_province', 'country', 'county'))) {
                         $values[$index] = $details->{$name};
                         $idx = $name . '_id';
                         $params[$index] = $details->{$idx};
                     } else {
                         if ($name === 'preferred_communication_method') {
                             $communicationFields = CRM_Core_PseudoConstant::pcm();
                             $pref = array();
                             $compref = array();
                             $pref = explode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, $details->{$name});
                             foreach ($pref as $k) {
                                 if ($k) {
                                     $compref[] = $communicationFields[$k];
                                 }
                             }
                             $params[$index] = $details->{$name};
                             $values[$index] = implode(",", $compref);
                         } else {
                             if ($name == 'group') {
                                 $groups = CRM_Contact_BAO_GroupContact::getContactGroup($cid, 'Added', null, false, true);
                                 $title = array();
                                 $ids = array();
                                 foreach ($groups as $g) {
                                     if ($g['visibility'] != 'User and User Admin Only') {
                                         $title[] = $g['title'];
                                         if ($g['visibility'] == 'Public Pages') {
                                             $ids[] = $g['group_id'];
                                         }
                                     }
                                 }
                                 $values[$index] = implode(', ', $title);
                                 $params[$index] = implode(',', $ids);
                             } else {
                                 if ($name == 'tag') {
                                     require_once 'CRM/Core/BAO/EntityTag.php';
                                     $entityTags =& CRM_Core_BAO_EntityTag::getTag($cid);
                                     $allTags =& CRM_Core_PseudoConstant::tag();
                                     $title = array();
                                     foreach ($entityTags as $tagId) {
                                         $title[] = $allTags[$tagId];
                                     }
                                     $values[$index] = implode(', ', $title);
                                     $params[$index] = implode(',', $entityTags);
                                 } else {
                                     if (array_key_exists($name, $studentFields)) {
                                         require_once 'CRM/Core/OptionGroup.php';
                                         $paramsNew = array($name => $details->{$name});
                                         if ($name == 'test_tutoring') {
                                             $names = array($name => array('newName' => $index, 'groupName' => 'test'));
                                         } else {
                                             if (substr($name, 0, 4) == 'cmr_') {
                                                 //for  readers group
                                                 $names = array($name => array('newName' => $index, 'groupName' => substr($name, 0, -3)));
                                             } else {
                                                 $names = array($name => array('newName' => $index, 'groupName' => $name));
                                             }
                                         }
                                         CRM_Core_OptionGroup::lookupValues($paramsNew, $names, false);
                                         $values[$index] = $paramsNew[$index];
                                         $params[$index] = $paramsNew[$name];
                                     } else {
                                         $processed = false;
                                         if (CRM_Core_Permission::access('Quest', false)) {
                                             require_once 'CRM/Quest/BAO/Student.php';
                                             $processed = CRM_Quest_BAO_Student::buildStudentForm($this, $field);
                                         }
                                         if (!$processed) {
                                             if (substr($name, 0, 7) === 'do_not_' or substr($name, 0, 3) === 'is_') {
                                                 if ($details->{$name}) {
                                                     $values[$index] = '[ x ]';
                                                 }
                                             } else {
                                                 require_once 'CRM/Core/BAO/CustomField.php';
                                                 if ($cfID = CRM_Core_BAO_CustomField::getKeyID($name)) {
                                                     $htmlType = $field['html_type'];
                                                     $dataType = $field['data_type'];
                                                     if ($htmlType == 'File') {
                                                         $fileURL = CRM_Core_BAO_CustomField::getFileURL($cid, $cfID);
                                                         $params[$index] = $values[$index] = $fileURL['file_url'];
                                                     } else {
                                                         $customVal = null;
                                                         if (isset($dao) && ($dao->data_type == 'Int' || $dao->data_type == 'Boolean')) {
                                                             $customVal = (int) $details->{$name};
                                                         } else {
                                                             if (isset($dao) && $dao->data_type == 'Float') {
                                                                 $customVal = (double) $details->{$name};
                                                             } else {
                                                                 if (!CRM_Utils_System::isNull(explode(CRM_Core_DAO::VALUE_SEPARATOR, $details->{$name}))) {
                                                                     $customVal = $details->{$name};
                                                                 }
                                                             }
                                                         }
                                                         //CRM-4582
                                                         if (CRM_Utils_System::isNull($customVal)) {
                                                             continue;
                                                         }
                                                         $params[$index] = $customVal;
                                                         $values[$index] = CRM_Core_BAO_CustomField::getDisplayValue($customVal, $cfID, $options);
                                                         if ($htmlType == 'Autocomplete-Select') {
                                                             $params[$index] = $values[$index];
                                                         }
                                                         if (CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $cfID, 'is_search_range')) {
                                                             $customFieldName = "{$name}_from";
                                                         }
                                                     }
                                                 } else {
                                                     if ($name == 'home_URL' && !empty($details->{$name})) {
                                                         $url = CRM_Utils_System::fixURL($details->{$name});
                                                         $values[$index] = "<a href=\"{$url}\">{$details->{$name}}</a>";
                                                     } else {
                                                         if (in_array($name, array('birth_date', 'deceased_date', 'membership_start_date', 'membership_end_date', 'join_date'))) {
                                                             require_once 'CRM/Utils/Date.php';
                                                             $values[$index] = CRM_Utils_Date::customFormat($details->{$name});
                                                             $params[$index] = CRM_Utils_Date::isoToMysql($details->{$name});
                                                         } else {
                                                             $values[$index] = $details->{$name};
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         } else {
             if (strpos($name, '-') !== false) {
                 list($fieldName, $id, $type) = CRM_Utils_System::explode('-', $name, 3);
                 if ($id == 'Primary') {
                     // fix for CRM-1543
                     // not sure why we'd every use Primary location type id
                     // we need to fix the source if we are using it
                     // $locationTypeName = CRM_Contact_BAO_Contact::getPrimaryLocationType( $cid );
                     $locationTypeName = 1;
                 } else {
                     $locationTypeName = CRM_Utils_Array::value($id, $locationTypes);
                 }
                 if (!$locationTypeName) {
                     continue;
                 }
                 $detailName = "{$locationTypeName}-{$fieldName}";
                 $detailName = str_replace(' ', '_', $detailName);
                 if (in_array($fieldName, array('phone', 'im', 'email', 'openid'))) {
                     if ($type) {
                         $detailName .= "-{$type}";
                     }
                 }
                 if (in_array($fieldName, array('state_province', 'country', 'county'))) {
                     $values[$index] = $details->{$detailName};
                     $idx = $detailName . '_id';
                     $params[$index] = $details->{$idx};
                 } else {
                     if ($fieldName == 'im') {
                         $providerId = $detailName . '-provider_id';
                         $providerName = $imProviders[$details->{$providerId}];
                         if ($providerName) {
                             $values[$index] = $details->{$detailName} . " (" . $providerName . ")";
                         } else {
                             $values[$index] = $details->{$detailName};
                         }
                         $params[$index] = $details->{$detailName};
                     } else {
                         $values[$index] = $params[$index] = $details->{$detailName};
                     }
                 }
             }
         }
         if ($field['visibility'] == "Public Pages and Listings" && CRM_Core_Permission::check('profile listings and forms')) {
             if (CRM_Utils_System::isNull($params[$index])) {
                 $params[$index] = $values[$index];
             }
             if (!isset($params[$index])) {
                 continue;
             }
             $customFieldID = CRM_Core_BAO_CustomField::getKeyID($field['name']);
             if (!$customFieldName) {
                 $fieldName = $field['name'];
             } else {
                 $fieldName = $customFieldName;
             }
             $url = null;
             if (CRM_Core_BAO_CustomField::getKeyID($field['name'])) {
                 $htmlType = $field['html_type'];
                 if ($htmlType == 'Link') {
                     $url = $params[$index];
                 } else {
                     if (in_array($htmlType, array('CheckBox', 'Multi-Select', 'AdvMulti-Select', 'Multi-Select State/Province', 'Multi-Select Country'))) {
                         $valSeperator = CRM_Core_BAO_CustomOption::VALUE_SEPERATOR;
                         $selectedOptions = explode($valSeperator, $params[$index]);
                         foreach ($selectedOptions as $key => $multiOption) {
                             if ($multiOption) {
                                 $eachOption = $valSeperator . $multiOption . $valSeperator;
                                 $url[] = CRM_Utils_System::url('civicrm/profile', 'reset=1&force=1&gid=' . $field['group_id'] . '&' . urlencode($fieldName) . '=' . urlencode($eachOption));
                             }
                         }
                     } else {
                         $url = CRM_Utils_System::url('civicrm/profile', 'reset=1&force=1&gid=' . $field['group_id'] . '&' . urlencode($fieldName) . '=' . urlencode($params[$index]));
                     }
                 }
             } else {
                 $url = CRM_Utils_System::url('civicrm/profile', 'reset=1&force=1&gid=' . $field['group_id'] . '&' . urlencode($fieldName) . '=' . urlencode($params[$index]));
             }
             if ($url && !empty($values[$index]) && $searchable) {
                 if (is_array($url) && !empty($url)) {
                     $links = array();
                     $eachMultiValue = explode(', ', $values[$index]);
                     foreach ($eachMultiValue as $key => $valueLabel) {
                         $links[] = '<a href="' . $url[$key] . '">' . $valueLabel . '</a>';
                     }
                     $values[$index] = implode(', ', $links);
                 } else {
                     $values[$index] = '<a href="' . $url . '">' . $values[$index] . '</a>';
                 }
             }
         }
     }
 }
Exemplo n.º 7
0
 /**
  * Class constructor
  *
  * @param array $formValues array of form values imported
  * @param array $params     array of parameters for query
  * @param int   $action - action of search basic or advanced.
  *
  * @return CRM_Contact_Selector
  * @access public
  */
 function __construct($customSearchClass, $formValues = null, $params = null, $returnProperties = null, $action = CRM_Core_Action::NONE, $includeContactIds = false, $searchDescendentGroups = true, $searchContext = 'search', $contextMenu = null)
 {
     //don't build query constructor, if form is not submitted
     $force = CRM_Utils_Request::retrieve('force', 'Boolean', CRM_Core_DAO::$_nullObject);
     if (empty($formValues) && !$force) {
         return;
     }
     // submitted form values
     $this->_formValues =& $formValues;
     $this->_params =& $params;
     $this->_returnProperties =& $returnProperties;
     $this->_contextMenu =& $contextMenu;
     // type of selector
     $this->_action = $action;
     $this->_searchContext = $searchContext;
     $this->_ufGroupID = CRM_Utils_Array::value('uf_group_id', $this->_formValues);
     if ($this->_ufGroupID) {
         require_once 'CRM/Core/BAO/UFGroup.php';
         $this->_fields = CRM_Core_BAO_UFGroup::getListingFields(CRM_Core_Action::VIEW, CRM_Core_BAO_UFGroup::PUBLIC_VISIBILITY | CRM_Core_BAO_UFGroup::LISTINGS_VISIBILITY, false, $this->_ufGroupID);
         self::$_columnHeaders = null;
         //CRM_Core_Error::debug( 'f', $this->_fields );
         $this->_customFields =& CRM_Core_BAO_CustomField::getFieldsForImport('Individual');
         $this->_returnProperties =& CRM_Contact_BAO_Contact::makeHierReturnProperties($this->_fields);
         $this->_returnProperties['contact_type'] = 1;
         $this->_returnProperties['contact_sub_type'] = 1;
         $this->_returnProperties['sort_name'] = 1;
         //$this->_returnProperties['groups'      ] = 1;
     }
     $this->_query =& new CRM_Contact_BAO_Query($this->_params, $this->_returnProperties, null, $includeContactIds, false, 1, false, $searchDescendentGroups);
     $this->_options =& $this->_query->_options;
 }
Exemplo n.º 8
0
 /**
  * Class constructor
  *
  * @param string params the params for the where clause
  *
  * @return CRM_Contact_Selector_Profile
  * @access public
  */
 function __construct(&$params, &$customFields, $ufGroupId = null, $map = false, $editLink = false, $linkToUF = false)
 {
     $this->_params = $params;
     $this->_gid = $ufGroupId;
     $this->_map = $map;
     $this->_editLink = $editLink;
     $this->_linkToUF = $linkToUF;
     //get the details of the uf group
     if ($ufGroupId) {
         $groupId = CRM_Core_DAO::getFieldValue('CRM_Core_BAO_UFGroup', $ufGroupId, 'limit_listings_group_id');
     }
     // add group id to params if a uf group belong to a any group
     if ($groupId) {
         if (CRM_Utils_Array::value('group', $this->_params)) {
             $this->_params['group'][$groupId] = 1;
         } else {
             $this->_params['group'] = array($groupId => 1);
         }
     }
     $this->_fields = CRM_Core_BAO_UFGroup::getListingFields(CRM_Core_Action::VIEW, CRM_Core_BAO_UFGroup::PUBLIC_VISIBILITY | CRM_Core_BAO_UFGroup::LISTINGS_VISIBILITY, false, $this->_gid);
     $this->_customFields =& $customFields;
     $returnProperties =& CRM_Contact_BAO_Contact::makeHierReturnProperties($this->_fields);
     $returnProperties['contact_type'] = 1;
     $returnProperties['contact_sub_type'] = 1;
     $returnProperties['sort_name'] = 1;
     $queryParams =& CRM_Contact_BAO_Query::convertFormValues($this->_params, 1);
     $this->_query =& new CRM_Contact_BAO_Query($queryParams, $returnProperties, $this->_fields);
     $this->_options =& $this->_query->_options;
 }
Exemplo n.º 9
0
 /**
  * Class constructor
  *
  * @param string params the params for the where clause
  *
  * @return CRM_Contact_Selector_Profile
  * @access public
  */
 function CRM_Profile_Selector_Listings(&$params, &$customFields, $ufGroupId = null)
 {
     $this->_params = $params;
     $this->_gid = $ufGroupId;
     //get the details of the uf group
     $ufGroupParam = array('id' => $ufGroupId);
     CRM_Core_BAO_UFGroup::retrieve($ufGroupParam, $details);
     $groupId = CRM_Utils_Array::value('limit_listings_group_id', $details);
     // add group id to params if a uf group belong to a any group
     if ($groupId) {
         if (CRM_Utils_Array::value('group', $this->_params)) {
             $this->_params['group'][$groupId] = 1;
         } else {
             $this->_params['group'] = array($groupId => 1);
         }
     }
     $this->_fields = CRM_Core_BAO_UFGroup::getListingFields(CRM_CORE_ACTION_VIEW, CRM_CORE_BAO_UFGROUP_PUBLIC_VISIBILITY | CRM_CORE_BAO_UFGROUP_LISTINGS_VISIBILITY, false, $this->_gid);
     // CRM_Core_Error::debug( 'p', $this->_params );
     // CRM_Core_Error::debug( 'f', $this->_fields );
     $this->_customFields =& $customFields;
     $returnProperties =& CRM_Contact_BAO_Contact::makeHierReturnProperties($this->_fields);
     $returnProperties['contact_type'] = 1;
     $returnProperties['sort_name'] = 1;
     $this->_query =& new CRM_Contact_BAO_Query($this->_params, $returnProperties, $this->_fields);
     $this->_options =& $this->_query->_options;
     //CRM_Core_Error::debug( 'q', $this->_query );
 }
Exemplo n.º 10
0
 /**
  * Class constructor
  *
  * @param array $formValues array of form values imported
  * @param array $params     array of parameters for query
  * @param int   $action - action of search basic or advanced.
  *
  * @return CRM_Contact_Selector
  * @access public
  */
 function __construct($customSearchClass, $formValues = null, $params = null, $returnProperties = null, $action = CRM_Core_Action::NONE, $includeContactIds = false, $searchDescendentGroups = true, $searchContext = 'search', $contextMenu = null)
 {
     //don't build query constructor, if form is not submitted
     $force = CRM_Utils_Request::retrieve('force', 'Boolean', CRM_Core_DAO::$_nullObject);
     if (empty($formValues) && !$force) {
         return;
     }
     // submitted form values
     $this->_formValues =& $formValues;
     $this->_params =& $params;
     $this->_returnProperties =& $returnProperties;
     $this->_contextMenu =& $contextMenu;
     $this->_context = $searchContext;
     // type of selector
     $this->_action = $action;
     $this->_searchContext = $searchContext;
     $this->_ufGroupID = CRM_Utils_Array::value('uf_group_id', $this->_formValues);
     if ($this->_ufGroupID) {
         require_once 'CRM/Core/BAO/UFGroup.php';
         $this->_fields = CRM_Core_BAO_UFGroup::getListingFields(CRM_Core_Action::VIEW, CRM_Core_BAO_UFGroup::PUBLIC_VISIBILITY | CRM_Core_BAO_UFGroup::LISTINGS_VISIBILITY, false, $this->_ufGroupID);
         self::$_columnHeaders = null;
         //CRM_Core_Error::debug( 'f', $this->_fields );
         $this->_customFields =& CRM_Core_BAO_CustomField::getFieldsForImport('Individual');
         $this->_returnProperties =& CRM_Contact_BAO_Contact::makeHierReturnProperties($this->_fields);
         $this->_returnProperties['contact_type'] = 1;
         $this->_returnProperties['contact_sub_type'] = 1;
         $this->_returnProperties['sort_name'] = 1;
     }
     // rectify params to what proximity search expects if there is a value for prox_distance
     // CRM-7021
     if (!empty($this->_params)) {
         foreach ($this->_params as $param) {
             if ($param[0] == 'prox_distance') {
                 // add prox_ prefix to these
                 $param_alter = array('street_address', 'city', 'postal_code', 'state_province', 'country');
                 foreach ($this->_params as $key => $_param) {
                     if (in_array($_param[0], $param_alter)) {
                         $this->_params[$key][0] = 'prox_' . $_param[0];
                         // _id suffix where needed
                         if ($_param[0] == 'country' || $_param[0] == 'state_province') {
                             $this->_params[$key][0] .= '_id';
                             // flatten state_province array
                             if (is_array($this->_params[$key][2])) {
                                 $this->_params[$key][2] = $this->_params[$key][2][0];
                             }
                         }
                     }
                 }
                 break;
             }
         }
     }
     $this->_query = new CRM_Contact_BAO_Query($this->_params, $this->_returnProperties, null, $includeContactIds, false, CRM_Contact_BAO_Query::MODE_CONTACTS, false, $searchDescendentGroups);
     $this->_options =& $this->_query->_options;
 }
Exemplo n.º 11
0
 /**
  * Function to get the all contact details(Hierarchical)
  *
  * @param int   $contactId contact id
  * @param array $fields fields array
  *
  * @return $values array contains the contact details
  * @static
  * @access public
  */
 function getHierContactDetails($contactId, &$fields)
 {
     $params = array('id' => $contactId);
     $options = array();
     $returnProperties =& CRM_Contact_BAO_Contact::makeHierReturnProperties($fields);
     return list($query, $options) = CRM_Contact_BAO_Query::apiQuery($params, $returnProperties, $options);
 }