/** * Build the form object. * * @return void */ public function buildQuickForm() { // get categories for the contact id $entityTag = CRM_Core_BAO_EntityTag::getTag($this->_entityID, $this->_entityTable); $this->assign('tagged', $entityTag); // get the list of all the categories $allTag = CRM_Core_BAO_Tag::getTagsUsedFor($this->_entityTable); // need to append the array with the " checked " if contact is tagged with the tag foreach ($allTag as $tagID => $varValue) { if (in_array($tagID, $entityTag)) { $tagAttribute = array('checked' => 'checked', 'id' => "tag_{$tagID}"); } else { $tagAttribute = array('id' => "tag_{$tagID}"); } $tagChk[$tagID] = $this->createElement('checkbox', $tagID, '', '', $tagAttribute); } $this->addGroup($tagChk, 'tagList', NULL, NULL, TRUE); $tags = new CRM_Core_BAO_Tag(); $tree = $tags->getTree($this->_entityTable, TRUE); // let's not load jstree if there are not children. This also fixes blank // display at the beginning of checkboxes $loadJsTree = CRM_Utils_Array::retrieveValueRecursive($tree, 'children'); $this->assign('loadjsTree', FALSE); if (!empty($loadJsTree)) { CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'packages/jquery/plugins/jstree/jquery.jstree.js', 0, 'html-header', FALSE)->addStyleFile('civicrm', 'packages/jquery/plugins/jstree/themes/default/style.css', 0, 'html-header'); $this->assign('loadjsTree', TRUE); } $this->assign('tree', $tree); $this->assign('tag', $allTag); //build tag widget $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_contact'); CRM_Core_Form_Tag::buildQuickForm($this, $parentNames, $this->_entityTable, $this->_entityID); }
/** * Function to build the form * * @return None * @access public */ public function buildQuickForm() { // get categories for the contact id $entityTag = CRM_Core_BAO_EntityTag::getTag($this->_entityID, $this->_entityTable); $this->assign('tagged', $entityTag); // get the list of all the categories $allTag = CRM_Core_BAO_Tag::getTagsUsedFor($this->_entityTable); // need to append the array with the " checked " if contact is tagged with the tag foreach ($allTag as $tagID => $varValue) { if (in_array($tagID, $entityTag)) { $tagAttribute = array('onclick' => "return changeRowColor(\"rowidtag_{$tagID}\")", 'checked' => 'checked', 'id' => "tag_{$tagID}"); } else { $tagAttribute = array('onclick' => "return changeRowColor(\"rowidtag_{$tagID}\")", 'id' => "tag_{$tagID}"); } $tagChk[$tagID] = $this->createElement('checkbox', $tagID, '', '', $tagAttribute); } $this->addGroup($tagChk, 'tagList', NULL, NULL, TRUE); $tags = new CRM_Core_BAO_Tag(); $tree = $tags->getTree($this->_entityTable, TRUE); $this->assign('tree', $tree); $this->assign('tag', $allTag); //build tag widget $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_contact'); CRM_Core_Form_Tag::buildQuickForm($this, $parentNames, $this->_entityTable, $this->_entityID); if ($this->_action & CRM_Core_Action::BROWSE) { $this->freeze(); } else { $this->addButtons(array(array('type' => 'next', 'name' => ts('Update Tags'), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel')))); } }
/** * Function to build the form * * @return void * @access public */ public function buildQuickForm() { CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'packages/jquery/plugins/jstree/jquery.jstree.js', 0, 'html-header', FALSE)->addStyleFile('civicrm', 'packages/jquery/plugins/jstree/themes/default/style.css', 0, 'html-header'); // get categories for the contact id $entityTag = CRM_Core_BAO_EntityTag::getTag($this->_entityID, $this->_entityTable); $this->assign('tagged', $entityTag); // get the list of all the categories $allTag = CRM_Core_BAO_Tag::getTagsUsedFor($this->_entityTable); // need to append the array with the " checked " if contact is tagged with the tag foreach ($allTag as $tagID => $varValue) { if (in_array($tagID, $entityTag)) { $tagAttribute = array('checked' => 'checked', 'id' => "tag_{$tagID}"); } else { $tagAttribute = array('id' => "tag_{$tagID}"); } $tagChk[$tagID] = $this->createElement('checkbox', $tagID, '', '', $tagAttribute); } $this->addGroup($tagChk, 'tagList', NULL, NULL, TRUE); $tags = new CRM_Core_BAO_Tag(); $tree = $tags->getTree($this->_entityTable, TRUE); $this->assign('tree', $tree); $this->assign('tag', $allTag); //build tag widget $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_contact'); CRM_Core_Form_Tag::buildQuickForm($this, $parentNames, $this->_entityTable, $this->_entityID); if ($this->_action & CRM_Core_Action::BROWSE) { $this->freeze(); } else { $this->addButtons(array(array('type' => 'next', 'name' => ts('Update Tags'), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel')))); } }
protected function contactHasOneOfTags($contact_id, $tag_ids) { $isValid = false; $tags = CRM_Core_BAO_EntityTag::getTag($contact_id); foreach ($tag_ids as $tag_id) { if (in_array($tag_id, $tags)) { $isValid = true; break; } } return $isValid; }
/** * Get entity tags. * * @param array $params * * @return array */ function civicrm_api3_entity_tag_get($params) { if (empty($params['entity_id'])) { return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); } else { //do legacy non-standard behaviour $values = CRM_Core_BAO_EntityTag::getTag($params['entity_id'], $params['entity_table']); $result = array(); foreach ($values as $v) { $result[$v] = array('tag_id' => $v); } return civicrm_api3_create_success($result, $params, 'EntityTag'); } }
/** * * @param <type> $params * @return <type> */ function civicrm_entity_tag_display(&$params) { if (!array_key_exists('contact_id', $params)) { return civicrm_create_error(ts('contact_id is a required field')); } require_once 'CRM/Core/BAO/EntityTag.php'; $values =& CRM_Core_BAO_EntityTag::getTag($params['contact_id']); $result = array(); $tags = CRM_Core_PseudoConstant::tag(); foreach ($values as $v) { $result[] = $tags[$v]; } return implode(',', $result); }
/** * Function to build the form * * @return None * @access public */ function buildQuickForm() { // get categories for the contact id $entityTag =& CRM_Core_BAO_EntityTag::getTag('civicrm_contact', $this->_contactId); // get the list of all the categories $allTag =& CRM_Core_PseudoConstant::tag(); // need to append the array with the " checked " if contact is tagged with the tag foreach ($allTag as $tagID => $varValue) { $strChecked = ''; if (in_array($tagID, $entityTag)) { $strChecked = 'checked'; } $tagChk[$tagID] = $this->createElement('checkbox', $tagID, '', '', array('onclick' => "return changeRowColor('rowid{$tagID}')", $strChecked => 'checked', 'id' => $tagID)); } $this->addGroup($tagChk, 'tagList'); $this->assign('tag', $allTag); if ($this->_action & CRM_CORE_ACTION_BROWSE) { $this->freeze(); } else { $this->addButtons(array(array('type' => 'next', 'name' => ts('Update Tags'), 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel')))); } }
/** * 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>'; } } } }
/** * Function to build the form * * @return void * @access public */ public function buildQuickForm() { //this call is for show related cases. if ($this->_showRelatedCases) { return; } CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js')->addScriptFile('civicrm', 'templates/CRM/Case/Form/CaseView.js'); $xmlProcessor = new CRM_Case_XMLProcessor_Process(); $caseRoles = $xmlProcessor->get($this->_caseType, 'CaseRoles'); $reports = $xmlProcessor->get($this->_caseType, 'ActivitySets'); //adding case manager.CRM-4510. $managerRoleId = $xmlProcessor->getCaseManagerRoleId($this->_caseType); if (!empty($managerRoleId)) { $caseRoles[$managerRoleId] = $caseRoles[$managerRoleId] . '<br />' . '(' . ts('Case Manager') . ')'; } $aTypes = $xmlProcessor->get($this->_caseType, 'ActivityTypes', TRUE); $allActTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'name'); $emailActivityType = array_search('Email', $allActTypes); $pdfActivityType = array_search('Print PDF Letter', $allActTypes); // remove Open Case activity type since we're inside an existing case if ($openActTypeId = array_search('Open Case', $allActTypes)) { unset($aTypes[$openActTypeId]); } //check for link cases. $unclosedCases = CRM_Case_BAO_Case::getUnclosedCases(NULL, array($this->_caseID)); if (empty($unclosedCases) && ($linkActTypeId = array_search('Link Cases', $allActTypes))) { unset($aTypes[$linkActTypeId]); } if (!$xmlProcessor->getNaturalActivityTypeSort()) { asort($aTypes); } $activityLinks = array('' => ts('Add Activity')); foreach ($aTypes as $type => $label) { if ($type == $emailActivityType) { $url = CRM_Utils_System::url('civicrm/activity/email/add', "action=add&context=standalone&reset=1&caseid={$this->_caseID}&atype={$type}", FALSE, NULL, FALSE); } else { if ($type == $pdfActivityType) { $url = CRM_Utils_System::url('civicrm/activity/pdf/add', "action=add&context=standalone&reset=1&cid={$this->_contactID}&caseid={$this->_caseID}&atype={$type}", FALSE, NULL, FALSE); } else { $url = CRM_Utils_System::url('civicrm/case/activity', "action=add&reset=1&cid={$this->_contactID}&caseid={$this->_caseID}&atype={$type}", FALSE, NULL, FALSE); } } $activityLinks[$url] = $label; } $this->add('select', 'add_activity_type_id', '', $activityLinks, FALSE, array('class' => 'crm-select2 crm-action-menu action-icon-plus twenty')); if ($this->_hasAccessToAllCases) { $this->add('select', 'report_id', '', array('' => ts('Activity Audit')) + $reports, FALSE, array('class' => 'crm-select2 crm-action-menu action-icon-clipboard')); $this->add('select', 'timeline_id', '', array('' => ts('Add Timeline')) + $reports, FALSE, array('class' => 'crm-select2 crm-action-menu action-icon-play')); } $this->addElement('submit', $this->getButtonName('next'), ' ', array('class' => 'hiddenElement')); if ($this->_mergeCases) { $allCases = CRM_Case_BAO_Case::getContactCases($this->_contactID); $otherCases = array(); foreach ($allCases as $caseId => $details) { //filter current and own cases. if ($caseId == $this->_caseID || !$this->_hasAccessToAllCases && !array_key_exists($caseId, $this->_userCases)) { continue; } $otherCases[$caseId] = 'Case ID: ' . $caseId . ' Type: ' . $details['case_type'] . ' Start: ' . $details['case_start_date']; } if (empty($otherCases)) { $this->_mergeCases = FALSE; $this->assign('mergeCases', $this->_mergeCases); } else { $this->add('select', 'merge_case_id', ts('Select Case for Merge'), array('' => ts('- select case -')) + $otherCases, FALSE, array('class' => 'crm-select2 huge')); $this->addElement('submit', $this->getButtonName('next', 'merge_case'), ts('Merge'), array('class' => 'crm-form-submit-inline hiddenElement')); } } //call activity form self::activityForm($this); //get case related relationships (Case Role) $caseRelationships = CRM_Case_BAO_Case::getCaseRoles($this->_contactID, $this->_caseID); //save special label because we unset it in the loop $managerLabel = empty($managerRoleId) ? '' : $caseRoles[$managerRoleId]; foreach ($caseRelationships as $key => &$value) { if (!empty($managerRoleId)) { if ($managerRoleId == $value['relation_type']) { $value['relation'] = $managerLabel; } } //calculate roles that don't have relationships if (!empty($caseRoles[$value['relation_type']])) { unset($caseRoles[$value['relation_type']]); } } $this->assign('caseRelationships', $caseRelationships); //also add client as role. CRM-4438 $caseRoles['client'] = CRM_Case_BAO_Case::getContactNames($this->_caseID); $this->assign('caseRoles', $caseRoles); // Retrieve ALL client relationships $relClient = CRM_Contact_BAO_Relationship::getRelationship($this->_contactID, CRM_Contact_BAO_Relationship::CURRENT, 0, 0, 0, NULL, NULL, FALSE); // Now build 'Other Relationships' array by removing relationships that are already listed under Case Roles // so they don't show up twice. $clientRelationships = array(); foreach ($relClient as $r) { if (!array_key_exists($r['id'], $caseRelationships)) { $clientRelationships[] = $r; } } $this->assign('clientRelationships', $clientRelationships); // Now global contact list that appears on all cases. $globalGroupInfo = array(); CRM_Case_BAO_Case::getGlobalContacts($globalGroupInfo); $this->assign('globalGroupInfo', $globalGroupInfo); // List of relationship types $baoRel = new CRM_Contact_BAO_Relationship(); $relType = $baoRel->getRelationType('Individual'); $roleTypes = array(); foreach ($relType as $k => $v) { $roleTypes[substr($k, 0, strpos($k, '_'))] = $v; } $this->add('select', 'role_type', ts('Relationship Type'), array('' => ts('- select type -')) + $roleTypes, FALSE, array('class' => 'crm-select2 twenty')); $hookCaseSummary = CRM_Utils_Hook::caseSummary($this->_caseID); if (is_array($hookCaseSummary)) { $this->assign('hookCaseSummary', $hookCaseSummary); } $allTags = CRM_Core_BAO_Tag::getTags('civicrm_case'); if (!empty($allTags)) { $this->add('select', 'case_tag', ts('Tags'), $allTags, FALSE, array('id' => 'tags', 'multiple' => 'multiple', 'class' => 'crm-select2')); $tags = CRM_Core_BAO_EntityTag::getTag($this->_caseID, 'civicrm_case'); $this->setDefaults(array('case_tag' => $tags)); foreach ($tags as $tid) { if (isset($allTags[$tid])) { $tags[$tid] = $allTags[$tid]; } else { unset($tags[$tid]); } } $this->assign('tags', implode(', ', array_filter($tags))); $this->assign('showTags', TRUE); } else { $this->assign('showTags', FALSE); } // build tagset widget // see if we have any tagsets which can be assigned to cases $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_case'); if ($parentNames) { $this->assign('showTagsets', TRUE); } else { $this->assign('showTagsets', FALSE); } CRM_Core_Form_Tag::buildQuickForm($this, $parentNames, 'civicrm_case', $this->_caseID, FALSE, TRUE); $this->addButtons(array(array('type' => 'cancel', 'name' => ts('Done'), 'spacing' => ' ', 'isDefault' => TRUE))); }
/** * Given the component name and returns * the count of participation of contact * * @param string $component input component name * @param integer $contactId input contact id * * @return total number of count of occurence in database * @access public * @static */ static function getCountComponent($component, $contactId) { $object = null; switch ($component) { case 'tag': require_once 'CRM/Core/BAO/EntityTag.php'; return count(CRM_Core_BAO_EntityTag::getTag($contactId)); case 'rel': require_once 'CRM/Contact/BAO/Relationship.php'; return count(CRM_Contact_BAO_Relationship::getRelationship($contactId)); case 'group': require_once 'CRM/Contact/BAO/GroupContact.php'; return CRM_Contact_BAO_GroupContact::getContactGroup($contactId, null, null, true); case 'log': case 'note': eval('$object =& new CRM_Core_DAO_' . $component . '( );'); $object->entity_table = 'civicrm_contact'; $object->entity_id = $contactId; $object->orderBy('modified_date desc'); break; case 'contribution': require_once 'CRM/Contribute/BAO/Contribution.php'; return CRM_Contribute_BAO_Contribution::contributionCount($contactId); break; case 'membership': require_once 'CRM/Member/DAO/Membership.php'; eval('$object =& new CRM_Member_DAO_Membership( );'); $object->contact_id = $contactId; $object->is_test = 0; break; case 'participant': require_once 'CRM/Event/DAO/Participant.php'; eval('$object =& new CRM_Event_DAO_Participant( );'); $object->contact_id = $contactId; $object->is_test = 0; break; case 'pledge': require_once 'CRM/Pledge/DAO/Pledge.php'; eval('$object =& new CRM_Pledge_DAO_Pledge( );'); $object->contact_id = $contactId; $object->is_test = 0; break; case 'case': require_once 'CRM/Case/BAO/Case.php'; return CRM_Case_BAO_Case::caseCount($contactId); case 'grant': require_once 'CRM/Grant/DAO/Grant.php'; eval('$object =& new CRM_Grant_DAO_Grant( );'); $object->contact_id = $contactId; break; case 'activity': require_once 'CRM/Activity/BAO/Activity.php'; return CRM_Activity_BAO_Activity::getActivitiesCount($contactId, false, null, null); default: $custom = explode('_', $component); if ($custom['0'] = 'custom') { require_once 'CRM/Core/DAO/CustomGroup.php'; $tableName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $custom['1'], 'table_name'); $queryString = "SELECT count(id) FROM {$tableName} WHERE entity_id = {$contactId}"; return CRM_Core_DAO::singleValueQuery($queryString); } } $object->find(); return $object->N; }
/** * Test case for createProfileContact. */ public function testCreateProfileContact() { $fields = CRM_Contact_BAO_Contact::exportableFields('Individual'); //current employer field for individual $fields['organization_name'] = array('name' => 'organization_name', 'where' => 'civicrm_organization.organization_name', 'title' => 'Current Employer'); //get the common params $contactParams = $this->contactParams(); $unsetParams = array('location', 'privacy'); foreach ($unsetParams as $param) { unset($contactParams[$param]); } $profileParams = array('organization_name' => 'Yahoo', 'gender_id' => '2', 'prefix_id' => '3', 'suffix_id' => '2', 'city-Primary' => 'Newark', 'contact_type' => 'Individual', 'country-Primary' => '1228', 'do_not_email' => '1', 'do_not_mail' => '1', 'do_not_phone' => '1', 'do_not_trade' => '1', 'do_not_sms' => '1', 'email-Primary' => '*****@*****.**', 'geo_code_1-Primary' => '18.219023', 'geo_code_2-Primary' => '-105.00973', 'im-Primary-provider_id' => '1', 'im-Primary' => 'john.smith', 'on_hold' => '1', 'openid' => '*****@*****.**', 'phone-Primary-1' => '303443689', 'phone-Primary-2' => '9833910234', 'postal_code-Primary' => '01903', 'postal_code_suffix-Primary' => '12345', 'state_province-Primary' => '1029', 'street_address-Primary' => 'Saint Helier St', 'supplemental_address_1-Primary' => 'Hallmark Ct', 'supplemental_address_2-Primary' => 'Jersey Village', 'user_unique_id' => '123456789', 'is_bulkmail' => '1', 'world_region' => 'India', 'tag' => array('3' => '1', '4' => '1', '1' => '1')); $createParams = array_merge($contactParams, $profileParams); //create the contact using create profile contact. $contactId = CRM_Contact_BAO_Contact::createProfileContact($createParams, $fields, NULL, NULL, NULL, NULL, TRUE); //get the parameters to compare. $params = $this->contactParams(); //check the values in DB. foreach ($params as $key => $val) { if (!is_array($params[$key])) { if ($key == 'contact_source') { $this->assertDBCompareValue('CRM_Contact_DAO_Contact', $contactId, 'source', 'id', $params[$key], "Check for {$key} creation."); } else { $this->assertDBCompareValue('CRM_Contact_DAO_Contact', $contactId, $key, 'id', $params[$key], "Check for {$key} creation."); } } } //check privacy options. foreach ($params['privacy'] as $key => $value) { $this->assertDBCompareValue('CRM_Contact_DAO_Contact', $contactId, $key, 'id', $params['privacy'][$key], 'Check for do_not_email creation.'); } $this->assertDBCompareValue('CRM_Contact_DAO_Contact', $contactId, 'contact_type', 'id', $profileParams['contact_type'], 'Check for contact type creation.'); $this->assertDBCompareValue('CRM_Contact_DAO_Contact', $contactId, 'user_unique_id', 'id', $profileParams['user_unique_id'], 'Check for user_unique_id creation.'); $this->assertDBCompareValue('CRM_Contact_DAO_Contact', $contactId, 'birth_date', 'id', $params['birth_date'], 'Check for birth_date creation.'); $this->assertDBCompareValue('CRM_Contact_DAO_Contact', $contactId, 'deceased_date', 'id', $params['deceased_date'], 'Check for deceased_date creation.'); $dbPrefComm = explode(CRM_Core_DAO::VALUE_SEPARATOR, CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contactId, 'preferred_communication_method', 'id', TRUE)); $checkPrefComm = array(); foreach ($dbPrefComm as $key => $value) { if ($value) { $checkPrefComm[$value] = 1; } } $this->assertAttributesEquals($checkPrefComm, $params['preferred_communication_method']); //Now check DB for Address $searchParams = array('contact_id' => $contactId, 'location_type_id' => 1, 'is_primary' => 1); $compareParams = array('street_address' => CRM_Utils_Array::value('street_address-Primary', $profileParams), 'supplemental_address_1' => CRM_Utils_Array::value('supplemental_address_1-Primary', $profileParams), 'supplemental_address_2' => CRM_Utils_Array::value('supplemental_address_2-Primary', $profileParams), 'city' => CRM_Utils_Array::value('city-Primary', $profileParams), 'postal_code' => CRM_Utils_Array::value('postal_code-Primary', $profileParams), 'country_id' => CRM_Utils_Array::value('country-Primary', $profileParams), 'state_province_id' => CRM_Utils_Array::value('state_province-Primary', $profileParams), 'geo_code_1' => CRM_Utils_Array::value('geo_code_1-Primary', $profileParams), 'geo_code_2' => CRM_Utils_Array::value('geo_code_2-Primary', $profileParams)); $this->assertDBCompareValues('CRM_Core_DAO_Address', $searchParams, $compareParams); //Now check DB for Email $compareParams = array('email' => CRM_Utils_Array::value('email-Primary', $profileParams)); $this->assertDBCompareValues('CRM_Core_DAO_Email', $searchParams, $compareParams); //Now check DB for IM $compareParams = array('name' => CRM_Utils_Array::value('im-Primary', $profileParams), 'provider_id' => CRM_Utils_Array::value('im-Primary-provider_id', $profileParams)); $this->assertDBCompareValues('CRM_Core_DAO_IM', $searchParams, $compareParams); //Now check DB for Phone $searchParams = array('contact_id' => $contactId, 'location_type_id' => 1, 'is_primary' => 1); $compareParams = array('phone' => CRM_Utils_Array::value('phone-Primary-1', $profileParams)); $this->assertDBCompareValues('CRM_Core_DAO_Phone', $searchParams, $compareParams); //Now check DB for Mobile $searchParams = array('contact_id' => $contactId, 'location_type_id' => 1, 'phone_type_id' => CRM_Utils_Array::value('phone_type_id', $params['phone'][2])); $compareParams = array('phone' => CRM_Utils_Array::value('phone-Primary-2', $profileParams)); $this->assertDBCompareValues('CRM_Core_DAO_Phone', $searchParams, $compareParams); //get the value of relationship $values = array(); $searchParams = array('contact_id' => $contactId); $relationship = CRM_Contact_BAO_Relationship::getValues($searchParams, $values); //Now check values of Relationship Count. $this->assertEquals(0, $values['relationship']['totalCount'], 'Check for total relationship count'); foreach ($values['relationship']['data'] as $key => $val) { //Now check values of Relationship organization. $this->assertEquals($profileParams['organization_name'], $val['name'], 'Check for organization'); //Now check values of Relationship type. $this->assertEquals('Employee of', $val['relation'], 'Check for relationship type'); //delete the organization. $this->contactDelete(CRM_Utils_Array::value('cid', $val)); } //Now check values of tag ids. $tags = CRM_Core_BAO_EntityTag::getTag($contactId); foreach ($tags as $key => $val) { $tagIds[$key] = 1; } $this->assertAttributesEquals($profileParams['tag'], $tagIds); //update Contact mode $updateCParams = array('first_name' => 'john', 'last_name' => 'doe', 'contact_type' => 'Individual', 'middle_name' => 'abc', 'prefix_id' => 2, 'suffix_id' => 3, 'nick_name' => 'Nick Name Updated', 'job_title' => 'software Developer', 'gender_id' => 1, 'is_deceased' => 1, 'website' => array(1 => array('website_type_id' => 1, 'url' => 'http://civicrmUpdate.org')), 'contact_source' => 'test contact', 'external_identifier' => 111222333, 'preferred_mail_format' => 'Both', 'is_opt_out' => 0, 'legal_identifier' => '123123123123', 'image_URL' => 'http://imageupdate.com', 'deceased_date' => '1981-10-10', 'birth_date' => '1951-11-11', 'privacy' => array('do_not_phone' => 1, 'do_not_email' => 1), 'preferred_communication_method' => array('1' => 0, '2' => 1, '3' => 0, '4' => 1, '5' => 0)); $updatePfParams = array('organization_name' => 'Google', 'city-Primary' => 'Mumbai', 'contact_type' => 'Individual', 'country-Primary' => '1228', 'do_not_email' => '1', 'do_not_mail' => '1', 'do_not_phone' => '1', 'do_not_trade' => '1', 'do_not_sms' => '1', 'email-Primary' => '*****@*****.**', 'geo_code_1-Primary' => '31.694842', 'geo_code_2-Primary' => '-106.29998', 'im-Primary-provider_id' => '1', 'im-Primary' => 'john.doe', 'on_hold' => '1', 'openid' => '*****@*****.**', 'phone-Primary-1' => '02115245336', 'phone-Primary-2' => '9766323895', 'postal_code-Primary' => '12345', 'postal_code_suffix-Primary' => '123', 'state_province-Primary' => '1004', 'street_address-Primary' => 'Oberoi Garden', 'supplemental_address_1-Primary' => 'A-wing:3037', 'supplemental_address_2-Primary' => 'Andhery', 'user_unique_id' => '1122334455', 'is_bulkmail' => '1', 'world_region' => 'India', 'tag' => array('2' => '1', '5' => '1')); $createParams = array_merge($updateCParams, $updatePfParams); //create the contact using create profile contact. $contactID = CRM_Contact_BAO_Contact::createProfileContact($createParams, $fields, $contactId, NULL, NULL, NULL, TRUE); //check the contact ids $this->assertEquals($contactId, $contactID, 'check for Contact ids'); //check the values in DB. foreach ($updateCParams as $key => $val) { if (!is_array($updateCParams[$key])) { if ($key == 'contact_source') { $this->assertDBCompareValue('CRM_Contact_DAO_Contact', $contactId, 'source', 'id', $updateCParams[$key], "Check for {$key} creation."); } else { $this->assertDBCompareValue('CRM_Contact_DAO_Contact', $contactId, $key, 'id', $updateCParams[$key], "Check for {$key} creation."); } } } //check privacy options. foreach ($updateCParams['privacy'] as $key => $value) { $this->assertDBCompareValue('CRM_Contact_DAO_Contact', $contactId, $key, 'id', $updateCParams['privacy'][$key], 'Check for do_not_email creation.'); } $this->assertDBCompareValue('CRM_Contact_DAO_Contact', $contactId, 'contact_type', 'id', $updatePfParams['contact_type'], 'Check for contact type creation.'); $this->assertDBCompareValue('CRM_Contact_DAO_Contact', $contactId, 'user_unique_id', 'id', $updatePfParams['user_unique_id'], 'Check for user_unique_id creation.'); $this->assertDBCompareValue('CRM_Contact_DAO_Contact', $contactId, 'birth_date', 'id', $updateCParams['birth_date'], 'Check for birth_date creation.'); $this->assertDBCompareValue('CRM_Contact_DAO_Contact', $contactId, 'deceased_date', 'id', $updateCParams['deceased_date'], 'Check for deceased_date creation.'); $dbPrefComm = explode(CRM_Core_DAO::VALUE_SEPARATOR, CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contactId, 'preferred_communication_method', 'id', TRUE)); $checkPrefComm = array(); foreach ($dbPrefComm as $key => $value) { if ($value) { $checkPrefComm[$value] = 1; } } $this->assertAttributesEquals($checkPrefComm, $updateCParams['preferred_communication_method']); //Now check DB for Address $searchParams = array('contact_id' => $contactId, 'location_type_id' => 1, 'is_primary' => 1); $compareParams = array('street_address' => CRM_Utils_Array::value('street_address-Primary', $updatePfParams), 'supplemental_address_1' => CRM_Utils_Array::value('supplemental_address_1-Primary', $updatePfParams), 'supplemental_address_2' => CRM_Utils_Array::value('supplemental_address_2-Primary', $updatePfParams), 'city' => CRM_Utils_Array::value('city-Primary', $updatePfParams), 'postal_code' => CRM_Utils_Array::value('postal_code-Primary', $updatePfParams), 'country_id' => CRM_Utils_Array::value('country-Primary', $updatePfParams), 'state_province_id' => CRM_Utils_Array::value('state_province-Primary', $updatePfParams), 'geo_code_1' => CRM_Utils_Array::value('geo_code_1-Primary', $updatePfParams), 'geo_code_2' => CRM_Utils_Array::value('geo_code_2-Primary', $updatePfParams)); $this->assertDBCompareValues('CRM_Core_DAO_Address', $searchParams, $compareParams); //Now check DB for Email $compareParams = array('email' => CRM_Utils_Array::value('email-Primary', $updatePfParams)); $this->assertDBCompareValues('CRM_Core_DAO_Email', $searchParams, $compareParams); //Now check DB for IM $compareParams = array('name' => CRM_Utils_Array::value('im-Primary', $updatePfParams), 'provider_id' => CRM_Utils_Array::value('im-Primary-provider_id', $updatePfParams)); $this->assertDBCompareValues('CRM_Core_DAO_IM', $searchParams, $compareParams); //Now check DB for Phone $searchParams = array('contact_id' => $contactId, 'location_type_id' => 1, 'is_primary' => 1); $compareParams = array('phone' => CRM_Utils_Array::value('phone-Primary-1', $updatePfParams)); $this->assertDBCompareValues('CRM_Core_DAO_Phone', $searchParams, $compareParams); //Now check DB for Mobile $searchParams = array('contact_id' => $contactId, 'location_type_id' => 1, 'phone_type_id' => CRM_Utils_Array::value('phone_type_id', $params['phone'][2])); $compareParams = array('phone' => CRM_Utils_Array::value('phone-Primary-2', $updatePfParams)); $this->assertDBCompareValues('CRM_Core_DAO_Phone', $searchParams, $compareParams); //get the value of relationship $values = array(); $searchParams = array('contact_id' => $contactId); $relationship = CRM_Contact_BAO_Relationship::getValues($searchParams, $values); //Now check values of Relationship Count. $this->assertEquals(0, $values['relationship']['totalCount'], 'Check for total relationship count'); foreach ($values['relationship']['data'] as $key => $val) { //Now check values of Relationship organization. $this->assertEquals($updatePfParams['organization_name'], $val['name'], 'Check for organization'); //Now check values of Relationship type. $this->assertEquals('Employee of', $val['relation'], 'Check for relationship type'); //delete the organization. $this->contactDelete(CRM_Utils_Array::value('cid', $val)); } //Now check values of tag ids. $tags = CRM_Core_BAO_EntityTag::getTag($contactId); foreach ($tags as $key => $val) { $tagIds[$key] = 1; } $this->assertAttributesEquals($updatePfParams['tag'], $tagIds); //cleanup DB by deleting the contact $this->contactDelete($contactId); }
/** * Set default values for the form. * * For edit/view mode the default values are retrieved from the database. * * @return array */ public function setDefaultValues() { $defaults = $this->_values + CRM_Core_Form_RecurringEntity::setDefaultValues(); // if we're editing... if (isset($this->_activityId)) { if (empty($defaults['activity_date_time'])) { list($defaults['activity_date_time'], $defaults['activity_date_time_time']) = CRM_Utils_Date::setDateDefaults(NULL, 'activityDateTime'); } elseif ($this->_action & CRM_Core_Action::UPDATE) { $this->assign('current_activity_date_time', $defaults['activity_date_time']); list($defaults['activity_date_time'], $defaults['activity_date_time_time']) = CRM_Utils_Date::setDateDefaults($defaults['activity_date_time'], 'activityDateTime'); list($defaults['repetition_start_date'], $defaults['repetition_start_date_time']) = CRM_Utils_Date::setDateDefaults($defaults['activity_date_time'], 'activityDateTime'); } if ($this->_context != 'standalone') { $this->assign('target_contact_value', CRM_Utils_Array::value('target_contact_value', $defaults)); $this->assign('assignee_contact_value', CRM_Utils_Array::value('assignee_contact_value', $defaults)); } // Fixme: why are we getting the wrong keys from upstream? $defaults['target_contact_id'] = CRM_Utils_Array::value('target_contact', $defaults); $defaults['assignee_contact_id'] = CRM_Utils_Array::value('assignee_contact', $defaults); // set default tags if exists $defaults['tag'] = CRM_Core_BAO_EntityTag::getTag($this->_activityId, 'civicrm_activity'); } else { // if it's a new activity, we need to set default values for associated contact fields $this->_sourceContactId = $this->_currentUserId; $this->_targetContactId = $this->_currentlyViewedContactId; $defaults['source_contact_id'] = $this->_sourceContactId; $defaults['target_contact_id'] = $this->_targetContactId; list($defaults['activity_date_time'], $defaults['activity_date_time_time']) = CRM_Utils_Date::setDateDefaults(NULL, 'activityDateTime'); } if ($this->_activityTypeId) { $defaults['activity_type_id'] = $this->_activityTypeId; } if (!$this->_single && !empty($this->_contactIds)) { $defaults['target_contact_id'] = $this->_contactIds; } // CRM-15472 - 50 is around the practical limit of how many items a select2 entityRef can handle if (!empty($defaults['target_contact_id'])) { $count = count(is_array($defaults['target_contact_id']) ? $defaults['target_contact_id'] : explode(',', $defaults['target_contact_id'])); if ($count > 50) { $this->freeze(array('target_contact_id')); } } if ($this->_action & (CRM_Core_Action::DELETE | CRM_Core_Action::RENEW)) { $this->assign('delName', CRM_Utils_Array::value('subject', $defaults)); } if ($this->_activityTypeFile) { $className = "CRM_{$this->_crmDir}_Form_Activity_{$this->_activityTypeFile}"; $defaults += $className::setDefaultValues($this); } if (empty($defaults['priority_id'])) { $priority = CRM_Core_PseudoConstant::get('CRM_Activity_DAO_Activity', 'priority_id'); $defaults['priority_id'] = array_search('Normal', $priority); } if (empty($defaults['status_id'])) { $defaults['status_id'] = CRM_Core_OptionGroup::getDefaultValue('activity_status'); } return $defaults; }
/** * 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>'; } } } } }
/** * set defaults for relevant form elements * * @param int $id the contact id * @param array $defaults the defaults array to store the values in * @param int $type what components are we interested in * * @return void * @access public * @static */ function setDefaults($id, &$defaults, $type = CRM_CONTACT_FORM_GROUPTAG_ALL) { $type = (int) $type; if ($type & CRM_CONTACT_FORM_GROUPTAG_GROUP) { require_once 'CRM/Contact/BAO/GroupContact.php'; $contactGroup =& CRM_Contact_BAO_GroupContact::getContactGroup($id, 'Added', null, false, true); if ($contactGroup) { foreach ($contactGroup as $group) { $defaults['group'][$group['group_id']] = 1; } } } if ($type & CRM_CONTACT_FORM_GROUPTAG_TAG) { require_once 'CRM/Core/BAO/EntityTag.php'; $contactTag =& CRM_Core_BAO_EntityTag::getTag('civicrm_contact', $id); if ($contactTag) { foreach ($contactTag as $tag) { $defaults['tag'][$tag] = 1; } } } }
/** * This function sets the default values for the form. For edit/view mode * the default values are retrieved from the database * * @access public * * @return void */ function setDefaultValues() { if ($this->_cdType) { return CRM_Custom_Form_CustomData::setDefaultValues($this); } $defaults = $this->_values; // if we're editing... if (isset($this->_activityId)) { if (!CRM_Utils_Array::crmIsEmptyArray($defaults['target_contact'])) { $target_contact_value = explode(';', trim($defaults['target_contact_value'])); $target_contact = array_combine(array_unique($defaults['target_contact']), $target_contact_value); if ($this->_action & CRM_Core_Action::VIEW) { $this->assign('target_contact', $target_contact); } else { //this assigned variable is used by newcontact creation widget to set defaults $this->assign('prePopulateData', $this->formatContactValues($target_contact)); } } if (!CRM_Utils_Array::crmIsEmptyArray($defaults['assignee_contact'])) { $assignee_contact_value = explode(';', trim($defaults['assignee_contact_value'])); $assignee_contact = array_combine($defaults['assignee_contact'], $assignee_contact_value); if ($this->_action & CRM_Core_Action::VIEW) { $this->assign('assignee_contact', $assignee_contact); } else { $this->assign('assignee_contact', $this->formatContactValues($assignee_contact)); } } if (empty($defaults['activity_date_time'])) { list($defaults['activity_date_time'], $defaults['activity_date_time_time']) = CRM_Utils_Date::setDateDefaults(NULL, 'activityDateTime'); } elseif ($this->_action & CRM_Core_Action::UPDATE) { $this->assign('current_activity_date_time', $defaults['activity_date_time']); list($defaults['activity_date_time'], $defaults['activity_date_time_time']) = CRM_Utils_Date::setDateDefaults($defaults['activity_date_time'], 'activityDateTime'); } //set the assignee contact count to template if (!empty($defaults['assignee_contact'])) { $this->assign('assigneeContactCount', count($defaults['assignee_contact'])); } else { $this->assign('assigneeContactCount', 1); } //set the target contact count to template if (!empty($defaults['target_contact'])) { $this->assign('targetContactCount', count($defaults['target_contact'])); } else { $this->assign('targetContactCount', 1); } if ($this->_context != 'standalone') { $this->assign('target_contact_value', CRM_Utils_Array::value('target_contact_value', $defaults)); $this->assign('assignee_contact_value', CRM_Utils_Array::value('assignee_contact_value', $defaults)); } // set default tags if exists $defaults['tag'] = CRM_Core_BAO_EntityTag::getTag($this->_activityId, 'civicrm_activity'); } else { // if it's a new activity, we need to set default values for associated contact fields // since those are jQuery fields, unfortunately we cannot use defaults directly $this->_sourceContactId = $this->_currentUserId; $this->_targetContactId = $this->_currentlyViewedContactId; $target_contact = array(); $defaults['source_contact_id'] = $this->_sourceContactId; if ($this->_context != 'standalone' && isset($this->_targetContactId)) { $target_contact[$this->_targetContactId] = self::_getDisplayNameById($this->_targetContactId); } //this assigned variable is used by newcontact creation widget to set defaults $this->assign('prePopulateData', $this->formatContactValues($target_contact)); list($defaults['activity_date_time'], $defaults['activity_date_time_time']) = CRM_Utils_Date::setDateDefaults(NULL, 'activityDateTime'); } if ($this->_activityTypeId) { $defaults['activity_type_id'] = $this->_activityTypeId; } if ($this->_action & (CRM_Core_Action::DELETE | CRM_Core_Action::RENEW)) { $this->assign('delName', CRM_Utils_Array::value('subject', $defaults)); } if ($this->_activityTypeFile) { $className = "CRM_{$this->_crmDir}_Form_Activity_{$this->_activityTypeFile}"; $defaults += $className::setDefaultValues($this); } if (empty($defaults['priority_id'])) { $priority = CRM_Core_PseudoConstant::get('CRM_Activity_DAO_Activity', 'priority_id'); $defaults['priority_id'] = array_search('Normal', $priority); } if (empty($defaults['status_id'])) { $defaults['status_id'] = CRM_Core_OptionGroup::getDefaultValue('activity_status'); } return $defaults; }
function wordmailmerge_civicrm_buildForm($formName, &$form) { require_once 'CRM/Core/DAO/MessageTemplate.php'; require_once 'CRM/Core/BAO/File.php'; require_once 'CRM/Core/DAO.php'; if ($formName == 'CRM_Admin_Form_MessageTemplates') { $action = $form->getVar('_action'); $template = CRM_Core_Smarty::singleton(); $form->assign('action', $action); $templatePath = realpath(dirname(__FILE__) . "/templates"); $config = CRM_Core_Config::singleton(); if ($action == CRM_Core_Action::UPDATE) { $msgTemplateId = $form->getVar('_defaultValues')['id']; $sql = "SELECT * FROM veda_civicrm_wordmailmerge WHERE msg_template_id = %1"; $params = array(1 => array($msgTemplateId, 'Integer')); $dao = CRM_Core_DAO::executeQuery($sql, $params); while ($dao->fetch()) { $fileId = $dao->file_id; } if (!empty($fileId)) { $mysql = "SELECT * FROM civicrm_file WHERE id = %1"; $params = array(1 => array($fileId, 'Integer')); $dao = CRM_Core_DAO::executeQuery($mysql, $params); while ($dao->fetch()) { $default['fileID'] = $dao->id; $default['mime_type'] = $dao->mime_type; $default['fileName'] = $dao->uri; $default['cleanName'] = CRM_Utils_File::cleanFileName($dao->uri); $default['fullPath'] = $config->customFileUploadDir . DIRECTORY_SEPARATOR . $dao->uri; $default['url'] = CRM_Utils_System::url('civicrm/file', "reset=1&id={$dao->id}&eid={$msgTemplateId}"); $default['href'] = "<a href=\"{$default['url']}\">{$default['cleanName']}</a>"; $default['tag'] = CRM_Core_BAO_EntityTag::getTag($dao->id, 'civicrm_file'); $default['deleteURLArgs'] = CRM_Core_BAO_File::deleteURLArgs('civicrm_msg_template', $msgTemplateId, $dao->id); } $defaults[$dao->id] = $default; $form->assign('defaults', $defaults); } } CRM_Core_BAO_File::buildAttachment($form, 'civicrm_msg_template', '', 1); $session = CRM_Core_Session::singleton(); $session->pushUserContext(CRM_Utils_System::url('civicrm/admin/messageTemplates', 'reset=1')); CRM_Core_Region::instance('page-body')->add(array('template' => "{$templatePath}/CRM/Wordmailmerge/testfield.tpl")); } }
/** * Function to build the form * * @return None * @access public */ public function buildQuickForm() { //this call is for show related cases. if ($this->_showRelatedCases) { return; } $xmlProcessor = new CRM_Case_XMLProcessor_Process(); $caseRoles = $xmlProcessor->get($this->_caseType, 'CaseRoles'); $reports = $xmlProcessor->get($this->_caseType, 'ActivitySets'); //adding case manager.CRM-4510. $managerRoleId = $xmlProcessor->getCaseManagerRoleId($this->_caseType); if (!empty($managerRoleId)) { $caseRoles[$managerRoleId] = $caseRoles[$managerRoleId] . '<br />' . '(' . ts('Case Manager') . ')'; } $aTypes = $xmlProcessor->get($this->_caseType, 'ActivityTypes', true); require_once 'CRM/Core/PseudoConstant.php'; $allActTypes = CRM_Core_PseudoConstant::activityType(true, true, false, 'name'); // remove Open Case activity type since we're inside an existing case if (($openActTypeId = array_search('Open Case', $allActTypes)) && array_key_exists($openActTypeId, $aTypes)) { unset($aTypes[$openActTypeId]); } //check for link cases. $unclosedCases = CRM_Case_BAO_Case::getUnclosedCases(null, array($this->_caseID)); if (empty($unclosedCases) && ($linkActTypeId = array_search('Link Cases', $allActTypes)) && array_key_exists($linkActTypeId, $aTypes)) { unset($aTypes[$linkActTypeId]); } asort($aTypes); $this->add('select', 'activity_type_id', ts('New Activity'), array('' => ts('- select activity type -')) + $aTypes); if ($this->_hasAccessToAllCases) { $this->add('select', 'report_id', ts('Run QA Audit / Redact'), array('' => ts('- select activity set -')) + $reports); $this->add('select', 'timeline_id', ts('Add Timeline'), array('' => ts('- select activity set -')) + $reports); } $this->addElement('submit', $this->getButtonName('next'), ts('Go'), array('class' => 'form-submit-inline', 'onclick' => "return checkSelection( this );")); if ($this->_mergeCases) { $allCases = CRM_Case_BAO_Case::getContactCases($this->_contactID); $otherCases = array(); foreach ($allCases as $caseId => $details) { //filter current and own cases. if ($caseId == $this->_caseID || !$this->_hasAccessToAllCases && !array_key_exists($caseId, $this->_userCases)) { continue; } $otherCases[$caseId] = 'Case ID: ' . $caseId . ' Type: ' . $details['case_type'] . ' Start: ' . $details['case_start_date']; } if (empty($otherCases)) { $this->_mergeCases = false; $this->assign('mergeCases', $this->_mergeCases); } else { $this->add('select', 'merge_case_id', ts('Select Case for Merge'), array('' => ts('- select case -')) + $otherCases); $this->addElement('submit', $this->getButtonName('next', 'merge_case'), ts('Merge'), array('class' => 'form-submit-inline', 'onclick' => "return checkSelection( this );")); } } $this->add('text', 'change_client_id', ts('Assign to another Client')); $this->add('hidden', 'contact_id', '', array('id' => 'contact_id')); $this->addElement('submit', $this->getButtonName('next', 'edit_client'), ts('Reassign Case'), array('class' => 'form-submit-inline', 'onclick' => "return checkSelection( this );")); $activityStatus = CRM_Core_PseudoConstant::activityStatus(); $this->add('select', 'status_id', ts('Status'), array("" => ts(' - any status - ')) + $activityStatus); // activity dates $this->addDate('activity_date_low', ts('Activity Dates - From'), false, array('formatType' => 'searchDate')); $this->addDate('activity_date_high', ts('To'), false, array('formatType' => 'searchDate')); require_once "CRM/Core/Permission.php"; if (CRM_Core_Permission::check('administer CiviCRM')) { $this->add('checkbox', 'activity_deleted', ts('Deleted Activities')); } //get case related relationships (Case Role) $caseRelationships = CRM_Case_BAO_Case::getCaseRoles($this->_contactID, $this->_caseID); //build reporter select $reporters = array("" => ts(' - any reporter - ')); foreach ($caseRelationships as $key => &$value) { $reporters[$value['cid']] = $value['name'] . " ( {$value['relation']} )"; if ($managerRoleId == $value['relation_type']) { $value['relation'] = $caseRoles[$managerRoleId]; } //calculate roles that don't have relationships if (CRM_Utils_Array::value($value['relation_type'], $caseRoles)) { unset($caseRoles[$value['relation_type']]); } } // take all case activity types for search filter, CRM-7187 $aTypesFilter = array(); $allCaseActTypes = CRM_Case_PseudoConstant::activityType(); foreach ($allCaseActTypes as $typeDetails) { if (!in_array($typeDetails['name'], array('Open Case'))) { $aTypesFilter[$typeDetails['id']] = CRM_Utils_Array::value('label', $typeDetails); } } asort($aTypesFilter); $this->add('select', 'activity_type_filter_id', ts('Activity Type'), array('' => ts('- select activity type -')) + $aTypesFilter); $this->assign('caseRelationships', $caseRelationships); //also add client as role. CRM-4438 $caseRoles['client'] = CRM_Case_BAO_Case::getContactNames($this->_caseID); $this->assign('caseRoles', $caseRoles); $this->add('select', 'reporter_id', ts('Reporter/Role'), $reporters); // Retrieve ALL client relationships $relClient = CRM_Contact_BAO_Relationship::getRelationship($this->_contactID, CRM_Contact_BAO_Relationship::CURRENT, 0, 0, 0, null, null, false); // Now build 'Other Relationships' array by removing relationships that are already listed under Case Roles // so they don't show up twice. $clientRelationships = array(); foreach ($relClient as $r) { if (!array_key_exists($r['id'], $caseRelationships)) { $clientRelationships[] = $r; } } $this->assign('clientRelationships', $clientRelationships); // Now global contact list that appears on all cases. $globalGroupInfo = array(); $relGlobal = CRM_Case_BAO_Case::getGlobalContacts($globalGroupInfo); $this->assign('globalRelationships', $relGlobal); $this->assign('globalGroupInfo', $globalGroupInfo); // List of relationship types require_once 'CRM/Contact/BAO/Relationship.php'; $baoRel = new CRM_Contact_BAO_Relationship(); $relType = $baoRel->getRelationType('Individual'); $roleTypes = array(); foreach ($relType as $k => $v) { $roleTypes[substr($k, 0, strpos($k, '_'))] = $v; } $this->add('select', 'role_type', ts('Relationship Type'), array('' => ts('- select type -')) + $roleTypes); require_once 'CRM/Utils/Hook.php'; $hookCaseSummary = CRM_Utils_Hook::caseSummary($this->_caseID); if (is_array($hookCaseSummary)) { $this->assign('hookCaseSummary', $hookCaseSummary); } require_once 'CRM/Core/BAO/EntityTag.php'; require_once 'CRM/Core/BAO/Tag.php'; $allTags = CRM_Core_BAO_Tag::getTags('civicrm_case'); if (!empty($allTags)) { $this->add('select', 'case_tag', ts('Tags'), $allTags, false, array('id' => 'tags', 'multiple' => 'multiple', 'title' => ts('- select -'))); $tags = CRM_Core_BAO_EntityTag::getTag($this->_caseID, 'civicrm_case'); $this->setDefaults(array('case_tag' => $tags)); foreach ($tags as $tid) { $tags[$tid] = $allTags[$tid]; } $this->assign('tags', implode(', ', array_filter($tags))); $this->assign('showTags', true); } else { $this->assign('showTags', false); } // build tagset widget require_once 'CRM/Core/Form/Tag.php'; // see if we have any tagsets which can be assigned to cases $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_case'); if ($parentNames) { $this->assign('showTagsets', true); } else { $this->assign('showTagsets', false); } CRM_Core_Form_Tag::buildQuickForm($this, $parentNames, 'civicrm_case', $this->_caseID, false, true); $this->addButtons(array(array('type' => 'cancel', 'name' => ts('Done'), 'spacing' => ' ', 'isDefault' => true))); }
/** * Build the form object. */ public function buildQuickForm() { //this call is for show related cases. if ($this->_showRelatedCases) { return; } $allowedRelationshipTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType($this->_contactID); CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js', 1, 'html-header')->addScriptFile('civicrm', 'templates/CRM/Case/Form/CaseView.js', 2, 'html-header')->addVars('relationshipTypes', CRM_Contact_Form_Relationship::getRelationshipTypeMetadata($allowedRelationshipTypes)); $xmlProcessor = new CRM_Case_XMLProcessor_Process(); $caseRoles = $xmlProcessor->get($this->_caseType, 'CaseRoles'); $reports = $xmlProcessor->get($this->_caseType, 'ActivitySets'); //adding case manager.CRM-4510. $managerRoleId = $xmlProcessor->getCaseManagerRoleId($this->_caseType); if (!empty($managerRoleId)) { $caseRoles[$managerRoleId] = $caseRoles[$managerRoleId] . '<br />' . '(' . ts('Case Manager') . ')'; } $aTypes = $xmlProcessor->get($this->_caseType, 'ActivityTypes', TRUE); $allActTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'name'); $emailActivityType = array_search('Email', $allActTypes); $pdfActivityType = array_search('Print PDF Letter', $allActTypes); if ($pdfActivityType) { $this->assign('exportDoc', CRM_Utils_System::url('civicrm/activity/pdf/add', "action=add&context=standalone&reset=1&cid={$this->_contactID}&caseid={$this->_caseID}&atype={$pdfActivityType}")); } // remove Open Case activity type since we're inside an existing case if ($openActTypeId = array_search('Open Case', $allActTypes)) { unset($aTypes[$openActTypeId]); } // Only show "link cases" activity if other cases exist. $linkActTypeId = array_search('Link Cases', $allActTypes); if ($linkActTypeId) { $count = civicrm_api3('Case', 'getcount', array('check_permissions' => TRUE, 'id' => array('!=' => $this->_caseID), 'is_deleted' => 0)); if (!$count) { unset($aTypes[$linkActTypeId]); } } if (!$xmlProcessor->getNaturalActivityTypeSort()) { asort($aTypes); } $activityLinks = array('' => ts('Add Activity')); foreach ($aTypes as $type => $label) { if ($type == $emailActivityType) { $url = CRM_Utils_System::url('civicrm/activity/email/add', "action=add&context=standalone&reset=1&caseid={$this->_caseID}&atype={$type}", FALSE, NULL, FALSE); } elseif ($type == $pdfActivityType) { $url = CRM_Utils_System::url('civicrm/activity/pdf/add', "action=add&context=standalone&reset=1&cid={$this->_contactID}&caseid={$this->_caseID}&atype={$type}", FALSE, NULL, FALSE); } else { $url = CRM_Utils_System::url('civicrm/case/activity', "action=add&reset=1&cid={$this->_contactID}&caseid={$this->_caseID}&atype={$type}", FALSE, NULL, FALSE); } $activityLinks[$url] = $label; } $this->add('select', 'add_activity_type_id', '', $activityLinks, FALSE, array('class' => 'crm-select2 crm-action-menu fa-calendar-check-o twenty')); if ($this->_hasAccessToAllCases) { $this->add('select', 'report_id', '', array('' => ts('Activity Audit')) + $reports, FALSE, array('class' => 'crm-select2 crm-action-menu fa-list-alt')); $this->add('select', 'timeline_id', '', array('' => ts('Add Timeline')) + $reports, FALSE, array('class' => 'crm-select2 crm-action-menu fa-list-ol')); } $this->addElement('submit', $this->getButtonName('next'), ' ', array('class' => 'hiddenElement')); $this->buildMergeCaseForm(); //call activity form self::activityForm($this, $aTypes); //get case related relationships (Case Role) $caseRelationships = CRM_Case_BAO_Case::getCaseRoles($this->_contactID, $this->_caseID); //save special label because we unset it in the loop $managerLabel = empty($managerRoleId) ? '' : $caseRoles[$managerRoleId]; foreach ($caseRelationships as $key => &$value) { if (!empty($managerRoleId)) { if ($managerRoleId == $value['relation_type']) { $value['relation'] = $managerLabel; } } //calculate roles that don't have relationships if (!empty($caseRoles[$value['relation_type']])) { unset($caseRoles[$value['relation_type']]); } } $this->assign('caseRelationships', $caseRelationships); //also add client as role. CRM-4438 $caseRoles['client'] = CRM_Case_BAO_Case::getContactNames($this->_caseID); $this->assign('caseRoles', $caseRoles); // Retrieve ALL client relationships $relClient = CRM_Contact_BAO_Relationship::getRelationship($this->_contactID, CRM_Contact_BAO_Relationship::CURRENT, 0, 0, 0, NULL, NULL, FALSE); // Now build 'Other Relationships' array by removing relationships that are already listed under Case Roles // so they don't show up twice. $clientRelationships = array(); foreach ($relClient as $r) { if (!array_key_exists($r['id'], $caseRelationships)) { $clientRelationships[] = $r; } } $this->assign('clientRelationships', $clientRelationships); // Now global contact list that appears on all cases. $globalGroupInfo = array(); CRM_Case_BAO_Case::getGlobalContacts($globalGroupInfo); $this->assign('globalGroupInfo', $globalGroupInfo); // List relationship types for adding an arbitrary new role to the case $this->add('select', 'role_type', ts('Relationship Type'), array('' => ts('- select type -')) + $allowedRelationshipTypes, FALSE, array('class' => 'crm-select2 twenty', 'data-select-params' => '{"allowClear": false}')); $hookCaseSummary = CRM_Utils_Hook::caseSummary($this->_caseID); if (is_array($hookCaseSummary)) { $this->assign('hookCaseSummary', $hookCaseSummary); } CRM_Core_BAO_Tag::getTags('civicrm_case', $allTags, NULL, ' ', TRUE); if (!empty($allTags)) { $this->add('select', 'case_tag', ts('Tags'), $allTags, FALSE, array('id' => 'tags', 'multiple' => 'multiple', 'class' => 'crm-select2')); $tags = CRM_Core_BAO_EntityTag::getTag($this->_caseID, 'civicrm_case'); $this->setDefaults(array('case_tag' => $tags)); foreach ($tags as $tid) { if (isset($allTags[$tid])) { $tags[$tid] = $allTags[$tid]; } else { unset($tags[$tid]); } } $this->assign('tags', implode(', ', array_filter($tags))); $this->assign('showTags', TRUE); } else { $this->assign('showTags', FALSE); } // build tagset widget // see if we have any tagsets which can be assigned to cases $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_case'); $tagSetTags = array(); if ($parentNames) { $this->assign('showTags', TRUE); $tagSetItems = civicrm_api3('entityTag', 'get', array('entity_id' => $this->_caseID, 'entity_table' => 'civicrm_case', 'tag_id.parent_id.is_tagset' => 1, 'options' => array('limit' => 0), 'return' => array("tag_id.parent_id", "tag_id.parent_id.name", "tag_id.name"))); foreach ($tagSetItems['values'] as $tag) { $tagSetTags += array($tag['tag_id.parent_id'] => array('name' => $tag['tag_id.parent_id.name'], 'items' => array())); $tagSetTags[$tag['tag_id.parent_id']]['items'][] = $tag['tag_id.name']; } } $this->assign('tagSetTags', $tagSetTags); CRM_Core_Form_Tag::buildQuickForm($this, $parentNames, 'civicrm_case', $this->_caseID, FALSE, TRUE); $this->addButtons(array(array('type' => 'cancel', 'name' => ts('Done'), 'spacing' => ' ', 'isDefault' => TRUE))); }
/** * Save entity tags when it is not save used AJAX. * * @param array $params * @param int $entityId * Entity id, eg: contact id, activity id, case id, file id. * @param string $entityTable * Entity table. * @param CRM_Core_Form $form * Form object. */ public static function postProcess(&$params, $entityId, $entityTable = 'civicrm_contact', &$form) { if ($form && !empty($form->_entityTagValues)) { $existingTags = $form->_entityTagValues; } else { $existingTags = CRM_Core_BAO_EntityTag::getTag($entityId, $entityTable); } if ($form) { // if the key is missing from the form response then all the tags were deleted / cleared // in that case we create empty tagset params so that below logic works and tagset are // deleted correctly foreach ($form->_tagsetInfo as $tagsetName => $tagsetInfo) { $tagsetId = explode('parentId_', $tagsetName); $tagsetId = $tagsetId[1]; if (empty($params[$tagsetId])) { $params[$tagsetId] = ''; } } } // when form is submitted with tagset values below logic will work and in the case when all tags in a tagset // are deleted we will have to set $params[tagset id] = '' which is done by above logic foreach ($params as $parentId => $value) { $newTagIds = array(); $tagIds = array(); if ($value) { $tagIds = explode(',', $value); foreach ($tagIds as $tagId) { if ($form && $form->_action != CRM_Core_Action::UPDATE || !array_key_exists($tagId, $existingTags)) { $newTagIds[] = $tagId; } } } // Any existing entity tags from this tagset missing from the $params should be deleted $deleteSQL = "DELETE FROM civicrm_entity_tag\n USING civicrm_entity_tag, civicrm_tag\n WHERE civicrm_tag.id=civicrm_entity_tag.tag_id\n AND civicrm_entity_tag.entity_table='{$entityTable}'\n AND entity_id={$entityId} AND parent_id={$parentId}"; if (!empty($tagIds)) { $deleteSQL .= " AND tag_id NOT IN (" . implode(', ', $tagIds) . ");"; } CRM_Core_DAO::executeQuery($deleteSQL); if (!empty($newTagIds)) { // New tag ids can be inserted directly into the db table. $insertValues = array(); foreach ($newTagIds as $tagId) { $insertValues[] = "( {$tagId}, {$entityId}, '{$entityTable}' ) "; } $insertSQL = 'INSERT INTO civicrm_entity_tag ( tag_id, entity_id, entity_table ) VALUES ' . implode(', ', $insertValues) . ';'; CRM_Core_DAO::executeQuery($insertSQL); } } }
/** * Returns all Tags assigned to a single entity instance. For example, you can use this API to find out what tag(s) have been assigned to a particular organization. * * @param $entity object Valid object of one of the supported entity types. * * @return array An array of Tag objects. * @access public */ function crm_tags_by_entity(&$entity) { require_once 'CRM/Core/BAO/EntityTag.php'; if (!isset($entity->id)) { return _crm_error('Required parameters missing'); } $entityID = $entity->id; return CRM_Core_BAO_EntityTag::getTag($entityTable = 'civicrm_contact', $entityID); }
/** * 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>'; } } } } }
/** * * @param <type> $params * * @return <type> * @todo EM 7 Jan 2011 - believe this should be deleted * @deprecated */ function civicrm_api3_entity_tag_display($params) { civicrm_api3_verify_one_mandatory($params, NULL, array('entity_id', 'contact_id')); $entityID = NULL; $entityTable = 'civicrm_contact'; if (!($entityID = CRM_Utils_Array::value('entity_id', $params))) { $entityID = CRM_Utils_Array::value('contact_id', $params); } if (CRM_Utils_Array::value('entity_table', $params)) { $entityTable = $params['entity_table']; } require_once 'CRM/Core/BAO/EntityTag.php'; $values = CRM_Core_BAO_EntityTag::getTag($entityID, $entityTable); $result = array(); $tags = CRM_Core_PseudoConstant::tag(); foreach ($values as $v) { $result[] = $tags[$v]; } return implode(',', $result); }
/** * Set defaults for relevant form elements. * * @param int $id * The contact id. * @param array $defaults * The defaults array to store the values in. * @param int $type * What components are we interested in. * @param string $fieldName * This is used in batch profile(i.e to build multiple blocks). * * @param string $groupElementType * * @return void */ public static function setDefaults($id, &$defaults, $type = self::ALL, $fieldName = NULL, $groupElementType = 'checkbox') { $type = (int) $type; if ($type & self::GROUP) { $fName = 'group'; if ($fieldName) { $fName = $fieldName; } $contactGroup = CRM_Contact_BAO_GroupContact::getContactGroup($id, 'Added', NULL, FALSE, TRUE); if ($contactGroup) { foreach ($contactGroup as $group) { if ($groupElementType == 'select') { $defaults[$fName][] = $group['group_id']; } else { $defaults[$fName . '[' . $group['group_id'] . ']'] = 1; } } } } if ($type & self::TAG) { $fName = 'tag'; if ($fieldName) { $fName = $fieldName; } $contactTag = CRM_Core_BAO_EntityTag::getTag($id); if ($contactTag) { foreach ($contactTag as $tag) { $defaults[$fName . '[' . $tag . ']'] = 1; } } } }
/** * Fix what blocks to show/hide based on the default values set * * @param array $defaults the array of default values * @param boolean $force should we set show hide based on input defaults * * @return void */ function setShowHide(&$defaults, $force) { $this->_showHide =& new CRM_Core_ShowHideBlocks(array('commPrefs' => 1), ''); if ($this->_contactType == 'Individual') { $this->_showHide->addShow('demographics[show]'); $this->_showHide->addHide('demographics'); } // first do the defaults showing CRM_Contact_Form_Location::setShowHideDefaults($this->_showHide, CRM_CONTACT_FORM_EDIT_LOCATION_BLOCKS); if ($this->_action & CRM_CORE_ACTION_ADD) { // notes are only included in the template for New Contact $this->_showHide->addShow('notes[show]'); $this->_showHide->addHide('notes'); } //add group and tags $contactGroup = $contactTag = array(); if ($this->_contactId) { $contactGroup =& CRM_Contact_BAO_GroupContact::getContactGroup($this->_contactId, 'Added'); $contactTag =& CRM_Core_BAO_EntityTag::getTag('civicrm_contact', $this->_contactId); } if (empty($contactGroup) || empty($contactTag)) { $this->_showHide->addShow('group[show]'); $this->_showHide->addHide('group'); } else { $this->_showHide->addShow('group'); $this->_showHide->addHide('group[show]'); } // is there any demographics data? if (CRM_Utils_Array::value('gender_id', $defaults) || CRM_Utils_Array::value('is_deceased', $defaults) || CRM_Utils_Array::value('birth_date', $defaults)) { $this->_showHide->addShow('demographics'); $this->_showHide->addHide('demographics[show]'); } if ($force) { $locationDefaults = CRM_Utils_Array::value('location', $defaults); CRM_Contact_Form_Location::updateShowHide($this->_showHide, $locationDefaults, CRM_CONTACT_FORM_EDIT_LOCATION_BLOCKS); } $this->_showHide->addToTemplate(); }
/** * * @param <type> $params * * @return <type> */ function civicrm_entity_tag_display(&$params) { if (!is_array($params)) { return civicrm_create_error(ts('params should be an array.')); } $entityID = NULL; $entityTable = 'civicrm_contact'; if (!($entityID = CRM_Utils_Array::value('entity_id', $params))) { $entityID = CRM_Utils_Array::value('contact_id', $params); } if (empty($entityID)) { return civicrm_create_error(ts('entity_id is a required field.')); } if (CRM_Utils_Array::value('entity_table', $params)) { $entityTable = $params['entity_table']; } require_once 'CRM/Core/BAO/EntityTag.php'; $values = CRM_Core_BAO_EntityTag::getTag($entityID, $entityTable); $result = array(); $tags = CRM_Core_PseudoConstant::tag(); foreach ($values as $v) { $result[] = $tags[$v]; } return implode(',', $result); }
/** * Takes an associative array and creates tag entity record for all tag entities. * * @param array $params * (reference) an assoc array of name/value pairs. * @param $entityTable * @param int $entityID * * @return void */ public static function create(&$params, $entityTable, $entityID) { // get categories for the entity id $entityTag = CRM_Core_BAO_EntityTag::getTag($entityID, $entityTable); // get the list of all the categories $allTag = CRM_Core_BAO_Tag::getTags($entityTable); // this fix is done to prevent warning generated by array_key_exits incase of empty array is given as input if (!is_array($params)) { $params = array(); } // this fix is done to prevent warning generated by array_key_exits incase of empty array is given as input if (!is_array($entityTag)) { $entityTag = array(); } // check which values has to be inserted/deleted for contact foreach ($allTag as $key => $varValue) { $tagParams['entity_table'] = $entityTable; $tagParams['entity_id'] = $entityID; $tagParams['tag_id'] = $key; if (array_key_exists($key, $params) && !array_key_exists($key, $entityTag)) { // insert a new record CRM_Core_BAO_EntityTag::add($tagParams); } elseif (!array_key_exists($key, $params) && array_key_exists($key, $entityTag)) { // delete a record for existing contact CRM_Core_BAO_EntityTag::del($tagParams); } } }
/** * get all the files and associated object associated with this * combination */ static function getEntityFile($entityTable, $entityID, $addDeleteArgs = false) { if (empty($entityTable) || !$entityID) { $results = NULL; return $results; } $config = CRM_Core_Config::singleton(); list($sql, $params) = self::sql($entityTable, $entityID, NULL); $dao = CRM_Core_DAO::executeQuery($sql, $params); $results = array(); while ($dao->fetch()) { $result['fileID'] = $dao->cfID; $result['entityID'] = $dao->cefID; $result['mime_type'] = $dao->mime_type; $result['fileName'] = $dao->uri; $result['description'] = $dao->description; $result['cleanName'] = CRM_Utils_File::cleanFileName($dao->uri); $result['fullPath'] = $config->customFileUploadDir . DIRECTORY_SEPARATOR . $dao->uri; $result['url'] = CRM_Utils_System::url('civicrm/file', "reset=1&id={$dao->cfID}&eid={$entityID}"); $result['href'] = "<a href=\"{$result['url']}\">{$result['cleanName']}</a>"; $result['tag'] = CRM_Core_BAO_EntityTag::getTag($dao->cfID, 'civicrm_file'); if ($addDeleteArgs) { $result['deleteURLArgs'] = self::deleteURLArgs($entityTable, $entityID, $dao->cfID); } $results[$dao->cfID] = $result; } //fix tag names $tags = CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE)); foreach ($results as &$values) { if (!empty($values['tag'])) { $tagNames = array(); foreach ($values['tag'] as $tid) { $tagNames[] = $tags[$tid]; } $values['tag'] = implode(', ', $tagNames); } else { $values['tag'] = ''; } } $dao->free(); return $results; }
/** * set defaults for relevant form elements * * @param int $id the contact id * @param array $defaults the defaults array to store the values in * @param int $type what components are we interested in * @param string $fieldName this is used in batch profile(i.e to build multiple blocks) * * @return void * @access public * @static */ static function setDefaults($id, &$defaults, $type = CRM_Contact_Form_Edit_TagsandGroups::ALL, $fieldName = null) { $type = (int) $type; if ($type & self::GROUP) { $fName = 'group'; if ($fieldName) { $fName = $fieldName; } require_once 'CRM/Contact/BAO/GroupContact.php'; $contactGroup =& CRM_Contact_BAO_GroupContact::getContactGroup($id, 'Added', null, false, true); if ($contactGroup) { foreach ($contactGroup as $group) { $defaults[$fName . "[" . $group['group_id'] . "]"] = 1; } } } if ($type & self::TAG) { $fName = 'tag'; if ($fieldName) { $fName = $fieldName; } require_once 'CRM/Core/BAO/EntityTag.php'; $contactTag =& CRM_Core_BAO_EntityTag::getTag($id); if ($contactTag) { foreach ($contactTag as $tag) { $defaults[$fName . "[" . $tag . "]"] = 1; } } } }
/** * Process the view. * * * @return void */ public function preProcess() { $contactID = CRM_Utils_Request::retrieve('cid', 'Integer', $this, TRUE); $activityID = CRM_Utils_Request::retrieve('aid', 'Integer', $this, TRUE); $revs = CRM_Utils_Request::retrieve('revs', 'Boolean', CRM_Core_DAO::$_nullObject); $caseID = CRM_Utils_Request::retrieve('caseID', 'Boolean', CRM_Core_DAO::$_nullObject); $activitySubject = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $activityID, 'subject'); //check for required permissions, CRM-6264 if ($activityID && !CRM_Activity_BAO_Activity::checkPermission($activityID, CRM_Core_Action::VIEW)) { CRM_Core_Error::fatal(ts('You do not have permission to access this page.')); } $this->assign('contactID', $contactID); $this->assign('caseID', $caseID); // CRM-9145 $this->assign('activityID', $activityID); $xmlProcessor = new CRM_Case_XMLProcessor_Report(); $report = $xmlProcessor->getActivityInfo($contactID, $activityID, TRUE); $attachmentUrl = CRM_Core_BAO_File::attachmentInfo('civicrm_activity', $activityID); if ($attachmentUrl) { $report['fields'][] = array('label' => 'Attachment(s)', 'value' => $attachmentUrl, 'type' => 'Link'); } $tags = CRM_Core_BAO_EntityTag::getTag($activityID, 'civicrm_activity'); if (!empty($tags)) { $allTag = CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE)); foreach ($tags as $tid) { $tags[$tid] = $allTag[$tid]; } $report['fields'][] = array('label' => 'Tags', 'value' => implode('<br />', $tags), 'type' => 'String'); } $this->assign('report', $report); $latestRevisionID = CRM_Activity_BAO_Activity::getLatestActivityId($activityID); $viewPriorActivities = array(); $priorActivities = CRM_Activity_BAO_Activity::getPriorAcitivities($activityID); foreach ($priorActivities as $activityId => $activityValues) { if (CRM_Case_BAO_Case::checkPermission($activityId, 'view', NULL, $contactID)) { $viewPriorActivities[$activityId] = $activityValues; } } if ($revs) { CRM_Utils_System::setTitle(ts('Activity Revision History')); $this->assign('revs', $revs); $this->assign('result', $viewPriorActivities); $this->assign('subject', $activitySubject); $this->assign('latestRevisionID', $latestRevisionID); } else { if (count($viewPriorActivities) > 1) { $this->assign('activityID', $activityID); } if ($latestRevisionID != $activityID) { $this->assign('latestRevisionID', $latestRevisionID); } } $parentID = CRM_Activity_BAO_Activity::getParentActivity($activityID); if ($parentID) { $this->assign('parentID', $parentID); } //viewing activity should get diplayed in recent list.CRM-4670 $activityTypeID = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $activityID, 'activity_type_id'); $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name'); $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts); $activityTargetContacts = CRM_Activity_BAO_ActivityContact::retrieveContactIdsByActivityId($activityID, $targetID); if (!empty($activityTargetContacts)) { $recentContactId = $activityTargetContacts[0]; } else { $recentContactId = $contactID; } if (!isset($caseID)) { $caseID = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_CaseActivity', $activityID, 'case_id', 'activity_id'); } $url = CRM_Utils_System::url('civicrm/case/activity/view', "reset=1&aid={$activityID}&cid={$recentContactId}&caseID={$caseID}&context=home"); $recentContactDisplay = CRM_Contact_BAO_Contact::displayName($recentContactId); // add the recently created Activity $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE); $title = ""; if (isset($activitySubject)) { $title = $activitySubject . ' - '; } $title = $title . $recentContactDisplay . ' (' . $activityTypes[$activityTypeID] . ')'; $recentOther = array(); if (CRM_Case_BAO_Case::checkPermission($activityID, 'edit')) { $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/case/activity', "reset=1&action=update&id={$activityID}&cid={$recentContactId}&caseid={$caseID}&context=home"); } if (CRM_Case_BAO_Case::checkPermission($activityID, 'delete')) { $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/case/activity', "reset=1&action=delete&id={$activityID}&cid={$recentContactId}&caseid={$caseID}&context=home"); } CRM_Utils_Recent::add($title, $url, $activityID, 'Activity', $recentContactId, $recentContactDisplay, $recentOther); }
/** * This function sets the default values for the form. For edit/view mode * the default values are retrieved from the database * * @access public * @return None */ function setDefaultValues() { if ($this->_cdType) { return CRM_Custom_Form_CustomData::setDefaultValues($this); } $defaults = array(); $params = array(); $config = CRM_Core_Config::singleton(); // if we're editing... if (isset($this->_activityId)) { $params = array('id' => $this->_activityId); CRM_Activity_BAO_Activity::retrieve($params, $defaults); $defaults['source_contact_qid'] = $defaults['source_contact_id']; $defaults['source_contact_id'] = $defaults['source_contact']; if (!CRM_Utils_Array::crmIsEmptyArray($defaults['target_contact'])) { $target_contact_value = explode(';', trim($defaults['target_contact_value'])); $this->assign('target_contact', array_combine(array_unique($defaults['target_contact']), $target_contact_value)); } if (!CRM_Utils_Array::crmIsEmptyArray($defaults['assignee_contact'])) { $assignee_contact_value = explode(';', trim($defaults['assignee_contact_value'])); $this->assign('assignee_contact', array_combine($defaults['assignee_contact'], $assignee_contact_value)); } if (!CRM_Utils_Array::value('activity_date_time', $defaults)) { list($defaults['activity_date_time'], $defaults['activity_date_time_time']) = CRM_Utils_Date::setDateDefaults(null, 'activityDateTime'); } else { if ($this->_action & CRM_Core_Action::UPDATE) { $this->assign('current_activity_date_time', $defaults['activity_date_time']); list($defaults['activity_date_time'], $defaults['activity_date_time_time']) = CRM_Utils_Date::setDateDefaults($defaults['activity_date_time'], 'activityDateTime'); } } //set the assigneed contact count to template if (!empty($defaults['assignee_contact'])) { $this->assign('assigneeContactCount', count($defaults['assignee_contact'])); } else { $this->assign('assigneeContactCount', 1); } //set the target contact count to template if (!empty($defaults['target_contact'])) { $this->assign('targetContactCount', count($defaults['target_contact'])); } else { $this->assign('targetContactCount', 1); } if ($this->_context != 'standalone') { $this->assign('target_contact_value', CRM_Utils_Array::value('target_contact_value', $defaults)); $this->assign('assignee_contact_value', CRM_Utils_Array::value('assignee_contact_value', $defaults)); $this->assign('source_contact_value', CRM_Utils_Array::value('source_contact', $defaults)); } // set default tags if exists require_once 'CRM/Core/BAO/EntityTag.php'; $defaults['tag'] = CRM_Core_BAO_EntityTag::getTag($this->_activityId, 'civicrm_activity'); } else { // if it's a new activity, we need to set default values for associated contact fields // since those are jQuery fields, unfortunately we cannot use defaults directly $this->_sourceContactId = $this->_currentUserId; $this->_targetContactId = $this->_currentlyViewedContactId; $target_contact = array(); $defaults['source_contact_id'] = self::_getDisplayNameById($this->_sourceContactId); $defaults['source_contact_qid'] = $this->_sourceContactId; if ($this->_context != 'standalone' && isset($this->_targetContactId)) { $target_contact[$this->_targetContactId] = self::_getDisplayNameById($this->_targetContactId); } $this->assign('target_contact', $target_contact); list($defaults['activity_date_time'], $defaults['activity_date_time_time']) = CRM_Utils_Date::setDateDefaults(null, 'activityDateTime'); } if ($this->_activityTypeId) { $defaults['activity_type_id'] = $this->_activityTypeId; } if ($this->_action & (CRM_Core_Action::DELETE | CRM_Core_Action::RENEW)) { $this->assign('delName', $defaults['subject']); } if ($this->_activityTypeFile) { eval('$defaults += CRM_' . $this->_crmDir . '_Form_Activity_' . $this->_activityTypeFile . '::setDefaultValues($this);'); } if (!CRM_Utils_Array::value('priority_id', $defaults)) { require_once 'CRM/Core/PseudoConstant.php'; $priority = CRM_Core_PseudoConstant::priority(); $defaults['priority_id'] = array_search('Normal', $priority); } return $defaults; }