Ejemplo n.º 1
0
 /**
  *Retrieve Name, Type and Id of record contain government value from customvalue table
  */
 static function retreiveContactFieldValue($contactID)
 {
     $govInfo = array();
     $govFieldId = self::retreiveContactFieldId('Identify');
     if (!empty($govFieldId) && $contactID) {
         $govValues = CRM_Core_BAO_CustomValueTable::getEntityValues($contactID, NULL, $govFieldId, TRUE);
         foreach ($govValues as $key => $val) {
             if ($val[$govFieldId['is_government']] == 1) {
                 $govInfo['type'] = $val[$govFieldId['Type']];
                 $govInfo['typeNumber'] = $val[$govFieldId['Number']];
                 $govInfo['key'] = $val[$govFieldId['is_government']];
                 $govInfo['id'] = ":{$key}";
                 break;
             }
         }
     }
     return $govInfo;
 }
Ejemplo n.º 2
0
 /**
  * Test getEntityValues function for stored value.
  */
 public function testGetEntityValues()
 {
     $params = array();
     $contactID = $this->individualCreate();
     $customGroup = $this->customGroupCreate(array('extends' => 'Individual'));
     $fields = array('custom_group_id' => $customGroup['id'], 'html_type' => 'RichTextEditor', 'data_type' => 'Memo');
     $customField = $this->customFieldCreate($fields);
     $params[] = array($customField['id'] => array('value' => '<p><strong>This is a <u>test</u></p>', 'type' => 'Memo', 'custom_field_id' => $customField['id'], 'custom_group_id' => $customGroup['id'], 'table_name' => $customGroup['values'][$customGroup['id']]['table_name'], 'column_name' => $customField['values'][$customField['id']]['column_name'], 'file_id' => ''));
     CRM_Core_BAO_CustomValueTable::store($params, 'civicrm_contact', $contactID);
     $entityValues = CRM_Core_BAO_CustomValueTable::getEntityValues($contactID, 'Individual');
     $this->assertEquals($entityValues[$customField['id']], '<p><strong>This is a <u>test</u></p>', 'Checking same for returned value.');
     $this->customFieldDelete($customField['id']);
     $this->customGroupDelete($customGroup['id']);
     $this->contactDelete($contactID);
 }
Ejemplo n.º 3
0
 /**
  * Copy custom fields and attachments from an existing activity to another.
  *
  * @see CRM_Case_Page_AJAX::_convertToCaseActivity()
  *
  * @param array $params
  */
 public static function copyExtendedActivityData($params)
 {
     // attach custom data to the new activity
     $customParams = $htmlType = array();
     $customValues = CRM_Core_BAO_CustomValueTable::getEntityValues($params['activityID'], 'Activity');
     if (!empty($customValues)) {
         $fieldIds = implode(', ', array_keys($customValues));
         $sql = "SELECT id FROM civicrm_custom_field WHERE html_type = 'File' AND id IN ( {$fieldIds} )";
         $result = CRM_Core_DAO::executeQuery($sql);
         while ($result->fetch()) {
             $htmlType[] = $result->id;
         }
         foreach ($customValues as $key => $value) {
             if ($value !== NULL) {
                 // CRM-10542
                 if (in_array($key, $htmlType)) {
                     $fileValues = CRM_Core_BAO_File::path($value, $params['activityID']);
                     $customParams["custom_{$key}_-1"] = array('name' => $fileValues[0], 'path' => $fileValues[1]);
                 } else {
                     $customParams["custom_{$key}_-1"] = $value;
                 }
             }
         }
         CRM_Core_BAO_CustomValueTable::postProcess($customParams, 'civicrm_activity', $params['mainActivityId'], 'Activity');
     }
     // copy activity attachments ( if any )
     CRM_Core_BAO_File::copyEntityFile('civicrm_activity', $params['activityID'], 'civicrm_activity', $params['mainActivityId']);
 }
Ejemplo n.º 4
0
 /**
  * this function checks whether the values of the custom fields in $params are
  * the same as the values of the custom fields of the relation with given
  * $relationshipId.
  *
  * @param array $params (reference) an assoc array of name/value pairs
  * @param int $relationshipId ID of an existing duplicate relation
  *
  * @return boolean true if custom field values are identical
  * @access private
  * @static
  */
 private static function checkDuplicateCustomFields(&$params, $relationshipId)
 {
     // Get the custom values of the existing relationship.
     $existingValues = CRM_Core_BAO_CustomValueTable::getEntityValues($relationshipId, 'Relationship');
     // Create a similar array for the new relationship.
     $newValues = array();
     if (array_key_exists('custom', $params)) {
         // $params['custom'] seems to be an array. Each value is again an array.
         // This array contains one value (key -1), and this value seems to be
         // an array with the information about the custom value.
         foreach ($params['custom'] as $value) {
             foreach ($value as $customValue) {
                 $newValues[$customValue['custom_field_id']] = $customValue['value'];
             }
         }
     }
     // Calculate difference between arrays. If the only key-value pairs
     // that are in one array but not in the other are empty, the
     // custom fields are considered to be equal.
     // See https://github.com/civicrm/civicrm-core/pull/6515#issuecomment-137985667
     $diff1 = array_diff_assoc($existingValues, $newValues);
     $diff2 = array_diff_assoc($newValues, $existingValues);
     return !array_filter($diff1) && !array_filter($diff2);
 }
Ejemplo n.º 5
0
 /**
  * Find differences between contacts.
  */
 function findDifferences($mainId, $otherId)
 {
     require_once 'api/v2/Contact.php';
     $mainParams = array('contact_id' => (int) $mainId);
     $otherParams = array('contact_id' => (int) $otherId);
     // API 2 has to have the requested fields spelt-out for it
     foreach (self::$validFields as $field) {
         $mainParams["return.{$field}"] = $otherParams["return.{$field}"] = 1;
     }
     $main =& civicrm_contact_get($mainParams);
     $other =& civicrm_contact_get($otherParams);
     //CRM-4524
     $main = reset($main);
     $other = reset($other);
     if ($main['contact_type'] != $other['contact_type']) {
         return false;
     }
     $diffs = array();
     foreach (self::$validFields as $validField) {
         if (CRM_Utils_Array::value($validField, $main) != CRM_Utils_Array::value($validField, $other)) {
             $diffs['contact'][] = $validField;
         }
     }
     require_once 'CRM/Core/BAO/CustomValueTable.php';
     $mainEvs =& CRM_Core_BAO_CustomValueTable::getEntityValues($mainId);
     $otherEvs =& CRM_Core_BAO_CustomValueTable::getEntityValues($otherId);
     $keys = array_keys($mainEvs) + array_keys($otherEvs);
     foreach ($keys as $key) {
         if ($mainEvs[$key] != $otherEvs[$key]) {
             $diffs['custom'][] = $key;
         }
     }
     return $diffs;
 }
Ejemplo n.º 6
0
 /**
  * Set default values for the form. Note that in edit/view mode
  * the default values are retrieved from the database
  *
  *
  * @return void
  */
 public function setDefaultsValues()
 {
     $this->_defaults = array();
     if ($this->_multiRecordProfile && $this->_multiRecord == CRM_Core_Action::DELETE) {
         return;
     }
     if ($this->_mode != self::MODE_SEARCH) {
         // set default values for country / state to start with
         CRM_Core_BAO_UFGroup::setRegisterDefaults($this->_fields, $this->_defaults);
     }
     if ($this->_id && !$this->_multiRecordProfile) {
         if ($this->_isContactActivityProfile) {
             $contactFields = $activityFields = array();
             foreach ($this->_fields as $fieldName => $field) {
                 if (CRM_Utils_Array::value('field_type', $field) == 'Activity') {
                     $activityFields[$fieldName] = $field;
                 } else {
                     $contactFields[$fieldName] = $field;
                 }
             }
             CRM_Core_BAO_UFGroup::setProfileDefaults($this->_id, $contactFields, $this->_defaults, TRUE);
             if ($this->_activityId) {
                 CRM_Core_BAO_UFGroup::setComponentDefaults($activityFields, $this->_activityId, 'Activity', $this->_defaults, TRUE);
             }
         } else {
             CRM_Core_BAO_UFGroup::setProfileDefaults($this->_id, $this->_fields, $this->_defaults, TRUE);
         }
     }
     //set custom field defaults
     if ($this->_multiRecordProfile) {
         foreach ($this->_multiRecordFields as $key => $field) {
             $fieldIds[] = CRM_Core_BAO_CustomField::getKeyID($key);
         }
         $defaultValues = array();
         if ($this->_multiRecord && $this->_multiRecord == CRM_Core_Action::UPDATE) {
             $defaultValues = CRM_Core_BAO_CustomValueTable::getEntityValues($this->_id, NULL, $fieldIds, TRUE);
             if ($this->_recordExists == TRUE) {
                 $defaultValues = $defaultValues[$this->_recordId];
             } else {
                 $defaultValues = NULL;
             }
         }
         if (!empty($defaultValues)) {
             foreach ($defaultValues as $key => $value) {
                 $name = "custom_{$key}";
                 $htmlType = $this->_multiRecordFields[$name]['html_type'];
                 if ($htmlType != 'File') {
                     if (isset($value)) {
                         CRM_Core_BAO_CustomField::setProfileDefaults($key, $name, $this->_defaults, $this->_id, $this->_mode, $value);
                     } else {
                         $this->_defaults[$name] = "";
                     }
                 }
                 if ($htmlType == 'File') {
                     $entityId = $this->_id;
                     if (CRM_Utils_Array::value('field_type', $field) == 'Activity' && $this->_activityId) {
                         $entityId = $this->_activityId;
                     }
                     $url = CRM_Core_BAO_CustomField::getFileURL($entityId, $key);
                     if ($url) {
                         $customFiles[$name]['displayURL'] = ts("Attached File") . ": {$url['file_url']}";
                         $deleteExtra = ts("Are you sure you want to delete attached file?");
                         $fileId = $url['file_id'];
                         $deleteURL = CRM_Utils_System::url('civicrm/file', "reset=1&id={$fileId}&eid={$entityId}&fid={$key}&action=delete");
                         $text = ts("Delete Attached File");
                         $customFiles[$field['name']]['deleteURL'] = "<a href=\"{$deleteURL}\" onclick = \"if (confirm( ' {$deleteExtra} ' )) this.href+='&amp;confirmed=1'; else return false;\">{$text}</a>";
                         // also delete the required rule that we've set on the form element
                         $this->removeFileRequiredRules($name);
                     }
                 }
             }
         }
     } else {
         foreach ($this->_fields as $name => $field) {
             if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
                 $htmlType = $field['html_type'];
                 if ((!isset($this->_defaults[$name]) || $htmlType == 'File') && CRM_Utils_Array::value('field_type', $field) != 'Activity') {
                     CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $this->_defaults, $this->_id, $this->_mode);
                 }
                 if ($htmlType == 'File') {
                     $entityId = $this->_id;
                     if (CRM_Utils_Array::value('field_type', $field) == 'Activity' && $this->_activityId) {
                         $entityId = $this->_activityId;
                     }
                     $url = CRM_Core_BAO_CustomField::getFileURL($entityId, $customFieldID);
                     if ($url) {
                         $customFiles[$field['name']]['displayURL'] = ts("Attached File") . ": {$url['file_url']}";
                         $deleteExtra = ts("Are you sure you want to delete attached file?");
                         $fileId = $url['file_id'];
                         $deleteURL = CRM_Utils_System::url('civicrm/file', "reset=1&id={$fileId}&eid={$entityId}&fid={$customFieldID}&action=delete");
                         $text = ts("Delete Attached File");
                         $customFiles[$field['name']]['deleteURL'] = "<a href=\"{$deleteURL}\" onclick = \"if (confirm( ' {$deleteExtra} ' )) this.href+='&amp;confirmed=1'; else return false;\">{$text}</a>";
                         // also delete the required rule that we've set on the form element
                         $this->removeFileRequiredRules($field['name']);
                     }
                 }
             }
         }
     }
     if (isset($customFiles)) {
         $this->assign('customFiles', $customFiles);
     }
     if ($this->_multiRecordProfile) {
         $this->setDefaults($this->_defaults);
         return;
     }
     if (!empty($this->_defaults['image_URL'])) {
         list($imageWidth, $imageHeight) = getimagesize(CRM_Utils_String::unstupifyUrl($this->_defaults['image_URL']));
         list($imageThumbWidth, $imageThumbHeight) = CRM_Contact_BAO_Contact::getThumbSize($imageWidth, $imageHeight);
         $this->assign("imageWidth", $imageWidth);
         $this->assign("imageHeight", $imageHeight);
         $this->assign("imageThumbWidth", $imageThumbWidth);
         $this->assign("imageThumbHeight", $imageThumbHeight);
         $this->assign("imageURL", $this->_defaults['image_URL']);
         $this->removeFileRequiredRules('image_URL');
     }
     if (array_key_exists('contact_sub_type', $this->_defaults) && !empty($this->_defaults['contact_sub_type'])) {
         $this->_defaults['contact_sub_type'] = explode(CRM_Core_DAO::VALUE_SEPARATOR, trim($this->_defaults['contact_sub_type'], CRM_Core_DAO::VALUE_SEPARATOR));
     }
     $this->setDefaults($this->_defaults);
 }
Ejemplo n.º 7
0
 /**
  * Find differences between contacts.
  *
  * @param array $main
  *   Contact details.
  * @param array $other
  *   Contact details.
  *
  * @return array
  */
 public static function findDifferences($main, $other)
 {
     $result = array('contact' => array(), 'custom' => array());
     foreach (self::getContactFields() as $validField) {
         if (CRM_Utils_Array::value($validField, $main) != CRM_Utils_Array::value($validField, $other)) {
             $result['contact'][] = $validField;
         }
     }
     $mainEvs = CRM_Core_BAO_CustomValueTable::getEntityValues($main['id']);
     $otherEvs = CRM_Core_BAO_CustomValueTable::getEntityValues($other['id']);
     $keys = array_unique(array_merge(array_keys($mainEvs), array_keys($otherEvs)));
     foreach ($keys as $key) {
         // Exclude multi-value fields CRM-13836
         if (strpos($key, '_')) {
             continue;
         }
         $key1 = CRM_Utils_Array::value($key, $mainEvs);
         $key2 = CRM_Utils_Array::value($key, $otherEvs);
         if ($key1 != $key2) {
             $result['custom'][] = $key;
         }
     }
     return $result;
 }
 /**
  * Add valid custom data to a Contact Type : Individual Subtype: Student
  */
 function testCreateValidCustomDataToIndividualStudent()
 {
     $params = array('contact_id' => $this->individualStudent, 'contact_type' => 'Individual', "custom_{$this->IndiStudentField['id']}" => 'Test String');
     $result = $this->callAPISuccess('contact', 'create', $params);
     $this->assertNotNull($result['id'], 'In line ' . __LINE__);
     $entityValues = CRM_Core_BAO_CustomValueTable::getEntityValues($this->individualStudent);
     $elements["custom_{$this->IndiStudentField['id']}"] = $entityValues["{$this->IndiStudentField['id']}"];
     // Check the Value in Database
     $this->assertEquals($elements["custom_{$this->IndiStudentField['id']}"], 'Test String', 'in line ' . __LINE__);
 }
Ejemplo n.º 9
0
 /**
  * Load all non-empty fields for the contacts
  *
  * @param array $main
  *   Contact details.
  * @param array $other
  *   Contact details.
  *
  * @return array
  */
 public static function retrieveFields($main, $other)
 {
     $result = array('contact' => array(), 'custom' => array());
     foreach (self::getContactFields() as $validField) {
         // CRM-17556 Get all non-empty fields, to make comparison easier
         if (!empty($main[$validField]) || !empty($other[$validField])) {
             $result['contact'][] = $validField;
         }
     }
     $mainEvs = CRM_Core_BAO_CustomValueTable::getEntityValues($main['id']);
     $otherEvs = CRM_Core_BAO_CustomValueTable::getEntityValues($other['id']);
     $keys = array_unique(array_merge(array_keys($mainEvs), array_keys($otherEvs)));
     foreach ($keys as $key) {
         // Exclude multi-value fields CRM-13836
         if (strpos($key, '_')) {
             continue;
         }
         $key1 = CRM_Utils_Array::value($key, $mainEvs);
         $key2 = CRM_Utils_Array::value($key, $otherEvs);
         // CRM-17556 Get all non-empty fields, to make comparison easier
         if (!empty($key1) || !empty($key2)) {
             $result['custom'][] = $key;
         }
     }
     return $result;
 }
Ejemplo n.º 10
0
 /**
  * Browse the listing.
  *
  * @return void
  */
 public function browse()
 {
     $dateFields = NULL;
     $cgcount = 0;
     $attributes = array();
     $dateFieldsVals = NULL;
     if ($this->_pageViewType == 'profileDataView' && $this->_profileId) {
         $fields = CRM_Core_BAO_UFGroup::getFields($this->_profileId, FALSE, NULL, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::EDIT);
         $multiRecordFields = array();
         $fieldIDs = NULL;
         $result = NULL;
         $multiRecordFieldsWithSummaryListing = CRM_Core_BAO_UFGroup::shiftMultiRecordFields($fields, $multiRecordFields, TRUE);
         $multiFieldId = CRM_Core_BAO_CustomField::getKeyID(key($multiRecordFields));
         $customGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $multiFieldId, 'custom_group_id');
         $reached = CRM_Core_BAO_CustomGroup::hasReachedMaxLimit($customGroupId, $this->_contactId);
         if (!$reached) {
             $this->assign('contactId', $this->_contactId);
             $this->assign('gid', $this->_profileId);
         }
         $this->assign('reachedMax', $reached);
         if ($multiRecordFieldsWithSummaryListing && !empty($multiRecordFieldsWithSummaryListing)) {
             $fieldIDs = array_keys($multiRecordFieldsWithSummaryListing);
         }
     } elseif ($this->_pageViewType == 'customDataView') {
         // require custom group id for _pageViewType of customDataView
         $customGroupId = $this->_customGroupId;
         $reached = CRM_Core_BAO_CustomGroup::hasReachedMaxLimit($customGroupId, $this->_contactId);
         if (!$reached) {
             $this->assign('contactId', $this->_contactId);
             $this->assign('customGroupId', $customGroupId);
             $this->assign('ctype', $this->_contactType);
         }
         $this->assign('reachedMax', $reached);
         // custom group info : this consists of the field title of group fields
         $groupDetail = CRM_Core_BAO_CustomGroup::getGroupDetail($customGroupId, NULL, CRM_Core_DAO::$_nullObject, TRUE);
         // field ids of fields in_selector for the custom group id provided
         $fieldIDs = array_keys($groupDetail[$customGroupId]['fields']);
         // field labels for headers
         $fieldLabels = $groupDetail[$customGroupId]['fields'];
         // from the above customGroupInfo we can get $this->_customGroupTitle
         $this->_customGroupTitle = $groupDetail[$customGroupId]['title'];
     }
     if ($fieldIDs && !empty($fieldIDs) && $this->_contactId) {
         $options = array();
         $returnProperities = array('html_type', 'data_type', 'date_format', 'time_format', 'default_value', 'is_required');
         foreach ($fieldIDs as $key => $fieldID) {
             $fieldIDs[$key] = !is_numeric($fieldID) ? CRM_Core_BAO_CustomField::getKeyID($fieldID) : $fieldID;
             $param = array('id' => $fieldIDs[$key]);
             $returnValues = array();
             CRM_Core_DAO::commonRetrieve('CRM_Core_DAO_CustomField', $param, $returnValues, $returnProperities);
             if ($returnValues['data_type'] == 'Date') {
                 $dateFields[$fieldIDs[$key]] = 1;
                 $actualPHPFormats = CRM_Core_SelectValues::datePluginToPHPFormats();
                 $dateFormat = (array) CRM_Utils_Array::value($returnValues['date_format'], $actualPHPFormats);
                 $timeFormat = CRM_Utils_Array::value('time_format', $returnValues);
             }
             $optionValuePairs = CRM_Core_BAO_CustomOption::getCustomOption($fieldIDs[$key]);
             if (!empty($optionValuePairs)) {
                 foreach ($optionValuePairs as $optionPairs) {
                     $options[$fieldIDs[$key]][$optionPairs['value']] = $optionPairs['label'];
                 }
             }
             $options[$fieldIDs[$key]]['attributes']['html_type'] = $returnValues['html_type'];
             $options[$fieldIDs[$key]]['attributes']['data_type'] = $returnValues['data_type'];
             $options[$fieldIDs[$key]]['attributes']['is_required'] = !empty($returnValues['is_required']);
             $options[$fieldIDs[$key]]['attributes']['default_value'] = CRM_Utils_Array::value('default_value', $returnValues);
             $options[$fieldIDs[$key]]['attributes']['format'] = $options[$fieldIDs[$key]]['attributes']['date_format'] = CRM_Utils_Array::value('date_format', $returnValues);
             $options[$fieldIDs[$key]]['attributes']['time_format'] = CRM_Utils_Array::value('time_format', $returnValues);
         }
         // commonly used for both views i.e profile listing view (profileDataView) and custom data listing view (customDataView)
         $result = CRM_Core_BAO_CustomValueTable::getEntityValues($this->_contactId, NULL, $fieldIDs, TRUE);
         if ($this->_pageViewType == 'profileDataView') {
             if (!empty($fieldIDs)) {
                 //get the group info of multi rec fields in listing view
                 $fieldInput = $fieldIDs;
                 $fieldIdInput = $fieldIDs[0];
             } else {
                 //if no listing fields exist, take the group title for display
                 $nonListingFieldIds = array_keys($multiRecordFields);
                 $singleField = CRM_Core_BAO_CustomField::getKeyID($nonListingFieldIds[0]);
                 $fieldIdInput = $singleField;
                 $singleField = array($singleField);
                 $fieldInput = $singleField;
             }
             $customGroupInfo = CRM_Core_BAO_CustomGroup::getGroupTitles($fieldInput);
             $this->_customGroupTitle = $customGroupInfo[$fieldIdInput]['groupTitle'];
         }
         // $cgcount is defined before 'if' condition as enitiy may have no record
         // and $cgcount is used to build new record url
         $cgcount = 1;
         if ($result && !empty($result)) {
             $links = self::links();
             if ($this->_pageViewType == 'profileDataView') {
                 $pageCheckSum = $this->get('pageCheckSum');
                 if ($pageCheckSum) {
                     foreach ($links as $key => $link) {
                         $links[$key] = $link['qs'] . "&cs=%%cs%%";
                     }
                 }
             }
             $linkAction = array_sum(array_keys($this->links()));
             if ($reached) {
                 unset($links[CRM_Core_Action::COPY]);
             }
             $newCgCount = !$reached ? count($result) + 1 : NULL;
             foreach ($result as $recId => &$value) {
                 foreach ($value as $fieldId => &$val) {
                     if (is_numeric($fieldId)) {
                         $customValue =& $val;
                         if (!empty($dateFields) && array_key_exists($fieldId, $dateFields)) {
                             // formated date capture value capture
                             $dateFieldsVals[$fieldId][$recId] = CRM_Core_BAO_CustomField::getDisplayValue($customValue, $fieldId, $options);
                             //set date and time format
                             switch ($timeFormat) {
                                 case 1:
                                     $dateFormat[1] = 'g:iA';
                                     break;
                                 case 2:
                                     $dateFormat[1] = 'G:i';
                                     break;
                                 default:
                                     // if time is not selected remove time from value
                                     $result[$recId][$fieldId] = substr($result[$recId][$fieldId], 0, 10);
                             }
                             $result[$recId][$fieldId] = CRM_Utils_Date::processDate($result[$recId][$fieldId], NULL, FALSE, implode(" ", $dateFormat));
                         } else {
                             // assign to $result
                             $customValue = CRM_Core_BAO_CustomField::getDisplayValue($customValue, $fieldId, $options);
                         }
                         // FIXME: getDisplayValue should always return a string so why is this necessary?
                         if (!$customValue && $customValue !== '0') {
                             $customValue = "";
                         }
                         // Set field attributes to support crmEditable
                         // Note that $fieldAttributes[data-type] actually refers to the html type not the sql data type
                         // TODO: Not all widget types and validation rules are supported by crmEditable so some fields will not be in-place editable
                         $fieldAttributes = array('class' => "crmf-custom_{$fieldId}_{$recId}");
                         $editable = FALSE;
                         if ($linkAction & CRM_Core_Action::UPDATE) {
                             $spec = $options[$fieldId]['attributes'];
                             switch ($spec['html_type']) {
                                 case 'Text':
                                     // Other data types like money would require some extra validation
                                     // FIXME: crmEditable currently does not support any validation rules :(
                                     $supportedDataTypes = array('Float', 'String', 'Int');
                                     $editable = in_array($spec['data_type'], $supportedDataTypes);
                                     break;
                                 case 'TextArea':
                                     $editable = TRUE;
                                     $fieldAttributes['data-type'] = 'textarea';
                                     break;
                                 case 'Radio':
                                 case 'Select':
                                 case 'Select Country':
                                 case 'Select State/Province':
                                     $editable = TRUE;
                                     $fieldAttributes['data-type'] = $spec['data_type'] == 'Boolean' ? 'boolean' : 'select';
                                     if (!$spec['is_required']) {
                                         $fieldAttributes['data-empty-option'] = ts('- none -');
                                     }
                                     break;
                             }
                         }
                         if ($editable) {
                             $fieldAttributes['class'] .= ' crm-editable';
                         }
                         $attributes[$fieldId][$recId] = $fieldAttributes;
                         $op = NULL;
                         if ($this->_pageViewType == 'profileDataView') {
                             $actionParams = array('recordId' => $recId, 'gid' => $this->_profileId, 'id' => $this->_contactId);
                             $op = 'profile.multiValue.row';
                         } else {
                             // different set of url params
                             $actionParams['gid'] = $actionParams['groupID'] = $this->_customGroupId;
                             $actionParams['cid'] = $actionParams['entityID'] = $this->_contactId;
                             $actionParams['recId'] = $recId;
                             $actionParams['type'] = $this->_contactType;
                             $actionParams['cgcount'] = $cgcount;
                             $actionParams['newCgCount'] = $newCgCount;
                             // DELETE action links
                             $deleteData = array('valueID' => $recId, 'groupID' => $this->_customGroupId, 'contactId' => $this->_contactId, 'key' => CRM_Core_Key::get('civicrm/ajax/customvalue'));
                             $links[CRM_Core_Action::DELETE]['url'] = '#';
                             $links[CRM_Core_Action::DELETE]['extra'] = ' data-delete_params="' . htmlspecialchars(json_encode($deleteData)) . '"';
                             $links[CRM_Core_Action::DELETE]['class'] = 'delete-custom-row';
                         }
                         if (!empty($pageCheckSum)) {
                             $actionParams['cs'] = $pageCheckSum;
                         }
                         $value['action'] = CRM_Core_Action::formLink($links, $linkAction, $actionParams, ts('more'), FALSE, $op, 'customValue', $fieldId);
                     }
                 }
                 $cgcount++;
             }
         }
     }
     $headers = array();
     if (!empty($fieldIDs)) {
         foreach ($fieldIDs as $fieldID) {
             $headers[$fieldID] = $this->_pageViewType == 'profileDataView' ? $customGroupInfo[$fieldID]['fieldLabel'] : $fieldLabels[$fieldID]['label'];
         }
     }
     $this->assign('dateFields', $dateFields);
     $this->assign('dateFieldsVals', $dateFieldsVals);
     $this->assign('cgcount', $cgcount);
     $this->assign('customGroupTitle', $this->_customGroupTitle);
     $this->assign('headers', $headers);
     $this->assign('records', $result);
     $this->assign('attributes', $attributes);
 }
Ejemplo n.º 11
0
 public static function printCaseReport()
 {
     $caseID = CRM_Utils_Request::retrieve('caseID', 'Positive', CRM_Core_DAO::$_nullObject);
     $clientID = CRM_Utils_Request::retrieve('cid', 'Positive', CRM_Core_DAO::$_nullObject);
     $activitySetName = CRM_Utils_Request::retrieve('asn', 'String', CRM_Core_DAO::$_nullObject);
     $isRedact = CRM_Utils_Request::retrieve('redact', 'Boolean', CRM_Core_DAO::$_nullObject);
     $includeActivities = CRM_Utils_Request::retrieve('all', 'Positive', CRM_Core_DAO::$_nullObject);
     $params = $otherRelationships = $globalGroupInfo = array();
     $report = new CRM_Case_XMLProcessor_Report($isRedact);
     if ($includeActivities) {
         $params['include_activities'] = 1;
     }
     if ($isRedact) {
         $params['is_redact'] = 1;
         $report->_redactionStringRules = array();
     }
     $template = CRM_Core_Smarty::singleton();
     //get case related relationships (Case Role)
     $caseRelationships = CRM_Case_BAO_Case::getCaseRoles($clientID, $caseID);
     $caseType = CRM_Case_BAO_Case::getCaseType($caseID, 'name');
     $xmlProcessor = new CRM_Case_XMLProcessor_Process();
     $caseRoles = $xmlProcessor->get($caseType, 'CaseRoles');
     foreach ($caseRelationships as $key => &$value) {
         if (!empty($caseRoles[$value['relation_type']])) {
             unset($caseRoles[$value['relation_type']]);
         }
         if ($isRedact) {
             if (!array_key_exists($value['name'], $report->_redactionStringRules)) {
                 $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($value['name'] => 'name_' . rand(10000, 100000)));
             }
             $value['name'] = self::redact($value['name'], TRUE, $report->_redactionStringRules);
             if (!empty($value['email']) && !array_key_exists($value['email'], $report->_redactionStringRules)) {
                 $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($value['email'] => 'email_' . rand(10000, 100000)));
             }
             $value['email'] = self::redact($value['email'], TRUE, $report->_redactionStringRules);
             if (!empty($value['phone']) && !array_key_exists($value['phone'], $report->_redactionStringRules)) {
                 $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($value['phone'] => 'phone_' . rand(10000, 100000)));
             }
             $value['phone'] = self::redact($value['phone'], TRUE, $report->_redactionStringRules);
         }
     }
     $caseRoles['client'] = CRM_Case_BAO_Case::getContactNames($caseID);
     if ($isRedact) {
         if (!array_key_exists($caseRoles['client']['sort_name'], $report->_redactionStringRules)) {
             $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($caseRoles['client']['sort_name'] => 'name_' . rand(10000, 100000)));
         }
         if (!array_key_exists($caseRoles['client']['display_name'], $report->_redactionStringRules)) {
             $report->_redactionStringRules[$caseRoles['client']['display_name']] = $report->_redactionStringRules[$caseRoles['client']['sort_name']];
         }
         $caseRoles['client']['sort_name'] = self::redact($caseRoles['client']['sort_name'], TRUE, $report->_redactionStringRules);
         if (!empty($caseRoles['client']['email']) && !array_key_exists($caseRoles['client']['email'], $report->_redactionStringRules)) {
             $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($caseRoles['client']['email'] => 'email_' . rand(10000, 100000)));
         }
         $caseRoles['client']['email'] = self::redact($caseRoles['client']['email'], TRUE, $report->_redactionStringRules);
         if (!empty($caseRoles['client']['phone']) && !array_key_exists($caseRoles['client']['phone'], $report->_redactionStringRules)) {
             $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($caseRoles['client']['phone'] => 'phone_' . rand(10000, 100000)));
         }
         $caseRoles['client']['phone'] = self::redact($caseRoles['client']['phone'], TRUE, $report->_redactionStringRules);
     }
     // Retrieve ALL client relationships
     $relClient = CRM_Contact_BAO_Relationship::getRelationship($clientID, CRM_Contact_BAO_Relationship::CURRENT, 0, 0, 0, NULL, NULL, FALSE);
     foreach ($relClient as $r) {
         if ($isRedact) {
             if (!array_key_exists($r['name'], $report->_redactionStringRules)) {
                 $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($r['name'] => 'name_' . rand(10000, 100000)));
             }
             if (!array_key_exists($r['display_name'], $report->_redactionStringRules)) {
                 $report->_redactionStringRules[$r['display_name']] = $report->_redactionStringRules[$r['name']];
             }
             $r['name'] = self::redact($r['name'], TRUE, $report->_redactionStringRules);
             if (!empty($r['phone']) && !array_key_exists($r['phone'], $report->_redactionStringRules)) {
                 $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($r['phone'] => 'phone_' . rand(10000, 100000)));
             }
             $r['phone'] = self::redact($r['phone'], TRUE, $report->_redactionStringRules);
             if (!empty($r['email']) && !array_key_exists($r['email'], $report->_redactionStringRules)) {
                 $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($r['email'] => 'email_' . rand(10000, 100000)));
             }
             $r['email'] = self::redact($r['email'], TRUE, $report->_redactionStringRules);
         }
         if (!array_key_exists($r['id'], $caseRelationships)) {
             $otherRelationships[] = $r;
         }
     }
     // Now global contact list that appears on all cases.
     $relGlobal = CRM_Case_BAO_Case::getGlobalContacts($globalGroupInfo);
     foreach ($relGlobal as &$r) {
         if ($isRedact) {
             if (!array_key_exists($r['sort_name'], $report->_redactionStringRules)) {
                 $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($r['sort_name'] => 'name_' . rand(10000, 100000)));
             }
             if (!array_key_exists($r['display_name'], $report->_redactionStringRules)) {
                 $report->_redactionStringRules[$r['display_name']] = $report->_redactionStringRules[$r['sort_name']];
             }
             $r['sort_name'] = self::redact($r['sort_name'], TRUE, $report->_redactionStringRules);
             if (!empty($r['phone']) && !array_key_exists($r['phone'], $report->_redactionStringRules)) {
                 $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($r['phone'] => 'phone_' . rand(10000, 100000)));
             }
             $r['phone'] = self::redact($r['phone'], TRUE, $report->_redactionStringRules);
             if (!empty($r['email']) && !array_key_exists($r['email'], $report->_redactionStringRules)) {
                 $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($r['email'] => 'email_' . rand(10000, 100000)));
             }
             $r['email'] = self::redact($r['email'], TRUE, $report->_redactionStringRules);
         }
     }
     // Retrieve custom values for cases.
     $customValues = CRM_Core_BAO_CustomValueTable::getEntityValues($caseID, 'Case');
     $extends = array('case');
     $groupTree = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, NULL, $extends);
     $caseCustomFields = array();
     while (list($gid, $group_values) = each($groupTree)) {
         while (list($id, $field_values) = each($group_values['fields'])) {
             if (array_key_exists($id, $customValues)) {
                 $caseCustomFields[$gid]['title'] = $group_values['title'];
                 $caseCustomFields[$gid]['values'][$id] = array('label' => $field_values['label'], 'value' => $customValues[$id]);
             }
         }
     }
     $template->assign('caseRelationships', $caseRelationships);
     $template->assign('caseRoles', $caseRoles);
     $template->assign('otherRelationships', $otherRelationships);
     $template->assign('globalRelationships', $relGlobal);
     $template->assign('globalGroupInfo', $globalGroupInfo);
     $template->assign('caseCustomFields', $caseCustomFields);
     $contents = self::getCaseReport($clientID, $caseID, $activitySetName, $params, $report);
     $printReport = CRM_Case_Audit_Audit::run($contents, $clientID, $caseID, TRUE);
     echo $printReport;
     CRM_Utils_System::civiExit();
 }
 /**
  * Browse the listing
  *
  * @return void
  * @access public
  */
 function browse()
 {
     if ($this->_profileId) {
         $fields = CRM_Core_BAO_UFGroup::getFields($this->_profileId, FALSE, NULL, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::EDIT);
         $multiRecordFields = array();
         $fieldIDs = NULL;
         $result = NULL;
         $multiRecordFieldsWithSummaryListing = CRM_Core_BAO_UFGroup::shiftMultiRecordFields($fields, $multiRecordFields, TRUE);
         $multiFieldId = CRM_Core_BAO_CustomField::getKeyID(key($multiRecordFields));
         $customGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $multiFieldId, 'custom_group_id');
         $reached = CRM_Core_BAO_CustomGroup::hasReachedMaxLimit($customGroupId, $this->_contactId);
         if (!$reached) {
             $this->assign('contactId', $this->_contactId);
             $this->assign('gid', $this->_profileId);
         }
         $this->assign('reachedMax', $reached);
         if ($multiRecordFieldsWithSummaryListing && !empty($multiRecordFieldsWithSummaryListing)) {
             $fieldIDs = array_keys($multiRecordFieldsWithSummaryListing);
         }
     }
     if ($fieldIDs && !empty($fieldIDs) && $this->_contactId) {
         $options = array();
         $returnProperities = array('html_type', 'data_type', 'date_format', 'time_format');
         foreach ($fieldIDs as $key => $fieldID) {
             $fieldIDs[$key] = CRM_Core_BAO_CustomField::getKeyID($fieldID);
             $param = array('id' => $fieldIDs[$key]);
             $returnValues = array();
             CRM_Core_DAO::commonRetrieve('CRM_Core_DAO_CustomField', $param, $returnValues, $returnProperities);
             $optionValuePairs = CRM_Core_BAO_CustomOption::getCustomOption($fieldIDs[$key]);
             if (!empty($optionValuePairs)) {
                 foreach ($optionValuePairs as $optionPairs) {
                     $options[$fieldIDs[$key]][$optionPairs['value']] = $optionPairs['label'];
                 }
             }
             $options[$fieldIDs[$key]]['attributes']['html_type'] = $returnValues['html_type'];
             $options[$fieldIDs[$key]]['attributes']['data_type'] = $returnValues['data_type'];
             $options[$fieldIDs[$key]]['attributes']['format'] = $options[$fieldIDs[$key]]['attributes']['date_format'] = CRM_Utils_Array::value('date_format', $returnValues);
             $options[$fieldIDs[$key]]['attributes']['time_format'] = CRM_Utils_Array::value('time_format', $returnValues);
         }
         $result = CRM_Core_BAO_CustomValueTable::getEntityValues($this->_contactId, NULL, $fieldIDs, TRUE);
         if (!empty($fieldIDs)) {
             //get the group info of multi rec fields in listing view
             $fieldInput = $fieldIDs;
             $fieldIdInput = $fieldIDs[0];
         } else {
             //if no listing fields exist, take the group title for display
             $nonListingFieldIds = array_keys($multiRecordFields);
             $singleField = CRM_Core_BAO_CustomField::getKeyID($nonListingFieldIds[0]);
             $fieldIdInput = $singleField;
             $singleField = array($singleField);
             $fieldInput = $singleField;
         }
         $customGroupInfo = CRM_Core_BAO_CustomGroup::getGroupTitles($fieldInput);
         $this->_customGroupTitle = $customGroupInfo[$fieldIdInput]['groupTitle'];
         if ($result && !empty($result)) {
             $links = self::links();
             $pageCheckSum = $this->get('pageCheckSum');
             if ($pageCheckSum) {
                 foreach ($links as $key => $link) {
                     $links[$key] = $link['qs'] . "&cs=%%cs%%";
                 }
             }
             $linkAction = array_sum(array_keys($this->links()));
             foreach ($result as $recId => &$value) {
                 foreach ($value as $fieldId => &$val) {
                     if (is_numeric($fieldId)) {
                         $customValue =& $val;
                         $customValue = CRM_Core_BAO_CustomField::getDisplayValue($customValue, $fieldId, $options);
                         if (!$customValue) {
                             $customValue = "";
                         }
                         $actionParams = array('recordId' => $recId, 'gid' => $this->_profileId, 'id' => $this->_contactId, 'onPopupClose' => $this->_onPopupClose);
                         if ($pageCheckSum) {
                             $actionParams['cs'] = $pageCheckSum;
                         }
                         $value['action'] = CRM_Core_Action::formLink($links, $linkAction, $actionParams, ts('more'), FALSE, 'profile.multiValue.row', 'customValue', $fieldId);
                     }
                 }
             }
         }
     }
     $headers = array();
     if (!empty($fieldIDs)) {
         foreach ($fieldIDs as $fieldID) {
             $headers[$fieldID] = $customGroupInfo[$fieldID]['fieldLabel'];
         }
     }
     $this->assign('customGroupTitle', $this->_customGroupTitle);
     $this->assign('headers', $headers);
     $this->assign('records', $result);
 }
 /**
  * Browse the listing
  *
  * @return void
  * @access public
  */
 function browse()
 {
     $dateFields = NULL;
     $cgcount = 0;
     $dateFieldsVals = NULL;
     if ($this->_pageViewType == 'profileDataView' && $this->_profileId) {
         $fields = CRM_Core_BAO_UFGroup::getFields($this->_profileId, FALSE, NULL, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::EDIT);
         $multiRecordFields = array();
         $fieldIDs = NULL;
         $result = NULL;
         $multiRecordFieldsWithSummaryListing = CRM_Core_BAO_UFGroup::shiftMultiRecordFields($fields, $multiRecordFields, TRUE);
         $multiFieldId = CRM_Core_BAO_CustomField::getKeyID(key($multiRecordFields));
         $customGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $multiFieldId, 'custom_group_id');
         $reached = CRM_Core_BAO_CustomGroup::hasReachedMaxLimit($customGroupId, $this->_contactId);
         if (!$reached) {
             $this->assign('contactId', $this->_contactId);
             $this->assign('gid', $this->_profileId);
         }
         $this->assign('reachedMax', $reached);
         if ($multiRecordFieldsWithSummaryListing && !empty($multiRecordFieldsWithSummaryListing)) {
             $fieldIDs = array_keys($multiRecordFieldsWithSummaryListing);
         }
     } elseif ($this->_pageViewType == 'customDataView') {
         // require custom group id for _pageViewType of customDataView
         $customGroupId = $this->_customGroupId;
         $reached = CRM_Core_BAO_CustomGroup::hasReachedMaxLimit($customGroupId, $this->_contactId);
         if (!$reached) {
             $this->assign('contactId', $this->_contactId);
             $this->assign('customGroupId', $customGroupId);
             $this->assign('ctype', $this->_contactType);
         }
         $this->assign('reachedMax', $reached);
         // custom group info : this consists of the field title of group fields
         $groupDetail = CRM_Core_BAO_CustomGroup::getGroupDetail($customGroupId, NULL, CRM_Core_DAO::$_nullObject, TRUE);
         // field ids of fields in_selector for the custom group id provided
         $fieldIDs = array_keys($groupDetail[$customGroupId]['fields']);
         // field labels for headers
         $fieldLabels = $groupDetail[$customGroupId]['fields'];
         // from the above customGroupInfo we can get $this->_customGroupTitle
         $this->_customGroupTitle = $groupDetail[$customGroupId]['title'];
     }
     if ($fieldIDs && !empty($fieldIDs) && $this->_contactId) {
         $options = array();
         $returnProperities = array('html_type', 'data_type', 'date_format', 'time_format');
         foreach ($fieldIDs as $key => $fieldID) {
             $fieldIDs[$key] = !is_numeric($fieldID) ? CRM_Core_BAO_CustomField::getKeyID($fieldID) : $fieldID;
             $param = array('id' => $fieldIDs[$key]);
             $returnValues = array();
             CRM_Core_DAO::commonRetrieve('CRM_Core_DAO_CustomField', $param, $returnValues, $returnProperities);
             if ($returnValues['data_type'] == 'Date') {
                 $dateFields[$fieldIDs[$key]] = 1;
             }
             $optionValuePairs = CRM_Core_BAO_CustomOption::getCustomOption($fieldIDs[$key]);
             if (!empty($optionValuePairs)) {
                 foreach ($optionValuePairs as $optionPairs) {
                     $options[$fieldIDs[$key]][$optionPairs['value']] = $optionPairs['label'];
                 }
             }
             $options[$fieldIDs[$key]]['attributes']['html_type'] = $returnValues['html_type'];
             $options[$fieldIDs[$key]]['attributes']['data_type'] = $returnValues['data_type'];
             $options[$fieldIDs[$key]]['attributes']['format'] = $options[$fieldIDs[$key]]['attributes']['date_format'] = CRM_Utils_Array::value('date_format', $returnValues);
             $options[$fieldIDs[$key]]['attributes']['time_format'] = CRM_Utils_Array::value('time_format', $returnValues);
         }
         // commonly used for both views i.e profile listing view (profileDataView) and custom data listing view (customDataView)
         $result = CRM_Core_BAO_CustomValueTable::getEntityValues($this->_contactId, NULL, $fieldIDs, TRUE);
         if ($this->_pageViewType == 'profileDataView') {
             if (!empty($fieldIDs)) {
                 //get the group info of multi rec fields in listing view
                 $fieldInput = $fieldIDs;
                 $fieldIdInput = $fieldIDs[0];
             } else {
                 //if no listing fields exist, take the group title for display
                 $nonListingFieldIds = array_keys($multiRecordFields);
                 $singleField = CRM_Core_BAO_CustomField::getKeyID($nonListingFieldIds[0]);
                 $fieldIdInput = $singleField;
                 $singleField = array($singleField);
                 $fieldInput = $singleField;
             }
             $customGroupInfo = CRM_Core_BAO_CustomGroup::getGroupTitles($fieldInput);
             $this->_customGroupTitle = $customGroupInfo[$fieldIdInput]['groupTitle'];
         }
         // $cgcount is defined before 'if' condition as enitiy may have no record
         // and $cgcount is used to build new record url
         $cgcount = 1;
         if ($result && !empty($result)) {
             $links = self::links();
             if ($this->_pageViewType == 'profileDataView') {
                 $pageCheckSum = $this->get('pageCheckSum');
                 if ($pageCheckSum) {
                     foreach ($links as $key => $link) {
                         $links[$key] = $link['qs'] . "&cs=%%cs%%";
                     }
                 }
             }
             $linkAction = array_sum(array_keys($this->links()));
             if ($reached) {
                 unset($links[CRM_Core_Action::COPY]);
             }
             $newCgCount = !$reached ? count($result) + 1 : NULL;
             foreach ($result as $recId => &$value) {
                 foreach ($value as $fieldId => &$val) {
                     if (is_numeric($fieldId)) {
                         $customValue =& $val;
                         if (!empty($dateFields) && array_key_exists($fieldId, $dateFields)) {
                             // formated date capture value capture
                             $dateFieldsVals[$fieldId][$recId] = CRM_Core_BAO_CustomField::getDisplayValue($customValue, $fieldId, $options);
                         } else {
                             // assign to $result
                             $customValue = CRM_Core_BAO_CustomField::getDisplayValue($customValue, $fieldId, $options);
                         }
                         if (!$customValue) {
                             $customValue = "";
                         }
                         $op = NULL;
                         if ($this->_pageViewType == 'profileDataView') {
                             $actionParams = array('recordId' => $recId, 'gid' => $this->_profileId, 'id' => $this->_contactId);
                             $op = 'profile.multiValue.row';
                         } else {
                             // different set of url params
                             $actionParams['gid'] = $actionParams['groupID'] = $this->_customGroupId;
                             $actionParams['cid'] = $actionParams['entityID'] = $this->_contactId;
                             $actionParams['recId'] = $recId;
                             $actionParams['type'] = $this->_contactType;
                             $actionParams['cgcount'] = $cgcount;
                             $actionParams['newCgCount'] = $newCgCount;
                             // DELETE action links
                             $deleteData = array('valueID' => $recId, 'groupID' => $this->_customGroupId, 'contactId' => $this->_contactId, 'key' => CRM_Core_Key::get('civicrm/ajax/customvalue'));
                             $links[CRM_Core_Action::DELETE]['url'] = '#';
                             $links[CRM_Core_Action::DELETE]['extra'] = ' data-delete_params="' . htmlspecialchars(json_encode($deleteData)) . '"';
                             $links[CRM_Core_Action::DELETE]['class'] = 'delete-custom-row';
                         }
                         if (!empty($pageCheckSum)) {
                             $actionParams['cs'] = $pageCheckSum;
                         }
                         $value['action'] = CRM_Core_Action::formLink($links, $linkAction, $actionParams, ts('more'), FALSE, $op, 'customValue', $fieldId);
                     }
                 }
                 $cgcount++;
             }
         }
     }
     $headers = array();
     if (!empty($fieldIDs)) {
         foreach ($fieldIDs as $fieldID) {
             $headers[$fieldID] = $this->_pageViewType == 'profileDataView' ? $customGroupInfo[$fieldID]['fieldLabel'] : $fieldLabels[$fieldID]['label'];
         }
     }
     $this->assign('dateFields', $dateFields);
     $this->assign('dateFieldsVals', $dateFieldsVals);
     $this->assign('cgcount', $cgcount);
     $this->assign('customGroupTitle', $this->_customGroupTitle);
     $this->assign('headers', $headers);
     $this->assign('records', $result);
 }
Ejemplo n.º 14
0
 function testgetEntityValues()
 {
     $params = array();
     $contactID = Contact::createIndividual();
     $customGroup = Custom::createGroup($params, 'Individual');
     $fields = array('groupId' => $customGroup->id, 'htmlType' => 'RichTextEditor', 'dataType' => 'Memo');
     $customField = Custom::createField($params, $fields);
     $params[] = array($customField->id => array('value' => '<p><strong>This is a <u>test</u></p>', 'type' => 'Memo', 'custom_field_id' => $customField->id, 'custom_group_id' => $customGroup->id, 'table_name' => 'civicrm_value_test_group_' . $customGroup->id, 'column_name' => 'test_Memo_' . $customField->id, 'file_id' => ''));
     require_once 'CRM/Core/BAO/CustomValueTable.php';
     CRM_Core_BAO_CustomValueTable::store($params, 'civicrm_contact', $contactID);
     //        $this->assertDBCompareValue('CRM_Custom_DAO_CustomValue', )
     require_once 'CRM/Core/BAO/CustomValueTable.php';
     $entityValues = CRM_Core_BAO_CustomValueTable::getEntityValues($contactID, 'Individual');
     $this->assertEquals($entityValues[$customField->id], '<p><strong>This is a <u>test</u></p>', 'Checking same for returned value.');
     Custom::deleteField($customField);
     Custom::deleteGroup($customGroup);
     Contact::delete($contactID);
 }
Ejemplo n.º 15
0
 /**
  * Find differences between contacts.
  */
 function findDifferences($mainId, $otherId)
 {
     $mainParams = array('contact_id' => (int) $mainId, 'version' => 3);
     $otherParams = array('contact_id' => (int) $otherId, 'version' => 3);
     foreach (self::$validFields as $field) {
         $mainParams["return.{$field}"] = $otherParams["return.{$field}"] = 1;
     }
     $main =& civicrm_api('contact', 'get', $mainParams);
     $other =& civicrm_api('contact', 'get', $otherParams);
     //CRM-4524
     $main = reset($main['values']);
     $other = reset($other['values']);
     if ($main['contact_type'] != $other['contact_type']) {
         return FALSE;
     }
     $diffs = array();
     foreach (self::$validFields as $validField) {
         if (CRM_Utils_Array::value($validField, $main) != CRM_Utils_Array::value($validField, $other)) {
             $diffs['contact'][] = $validField;
         }
     }
     $mainEvs = CRM_Core_BAO_CustomValueTable::getEntityValues($mainId);
     $otherEvs = CRM_Core_BAO_CustomValueTable::getEntityValues($otherId);
     $keys = array_unique(array_merge(array_keys($mainEvs), array_keys($otherEvs)));
     foreach ($keys as $key) {
         $key1 = CRM_Utils_Array::value($key, $mainEvs);
         $key2 = CRM_Utils_Array::value($key, $otherEvs);
         if ($key1 != $key2) {
             $diffs['custom'][] = $key;
         }
     }
     unset($main, $other, $mainEvs, $otherEvs);
     return $diffs;
 }