Skip to content

Commit

Permalink
CRM-20184_Missing_{contact.email_greeting}_in_Workflow_Templates [&di…
Browse files Browse the repository at this point in the history
…splayname in subject]
  • Loading branch information
jmcclelland authored and magnolia61 committed Apr 17, 2018
1 parent e7a0106 commit 638b464
Show file tree
Hide file tree
Showing 171 changed files with 5,467 additions and 770 deletions.
14 changes: 10 additions & 4 deletions CRM/Admin/Form/RelationshipType.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,12 @@ public function postProcess() {
CRM_Core_Session::setStatus(ts('Selected Relationship type has been deleted.'), ts('Record Deleted'), 'success');
}
else {
$ids = array();

// store the submitted values in an array
$params = $this->exportValues();
$params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE);

if ($this->_action & CRM_Core_Action::UPDATE) {
$ids['relationshipType'] = $this->_id;
$params['id'] = $this->_id;
}

$cTypeA = CRM_Utils_System::explode('__',
Expand All @@ -162,7 +160,15 @@ public function postProcess() {
$params['contact_sub_type_a'] = $cTypeA[1] ? $cTypeA[1] : 'NULL';
$params['contact_sub_type_b'] = $cTypeB[1] ? $cTypeB[1] : 'NULL';

$result = CRM_Contact_BAO_RelationshipType::add($params, $ids);
// if label B to A is blank, insert the value label A to B for it
if (!strlen(trim(CRM_Utils_Array::value('name_b_a', $params)))) {
$params['name_b_a'] = CRM_Utils_Array::value('name_a_b', $params);
}
if (!strlen(trim(CRM_Utils_Array::value('label_b_a', $params)))) {
$params['label_b_a'] = CRM_Utils_Array::value('label_a_b', $params);
}

$result = CRM_Contact_BAO_RelationshipType::add($params);

$this->ajaxResponse['relationshipType'] = $result->toArray();

Expand Down
11 changes: 10 additions & 1 deletion CRM/Admin/Form/ScheduleReminders.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,9 @@ public static function formRule($fields, $files, $self) {
$errors['absolute_date'] = ts('Absolute date cannot be earlier than the current time.');
}
}

if (!CRM_Utils_Rule::email($fields['from_email'])) {
$errors['from_email'] = ts('Please enter a valid email address.');
}
$recipientKind = array(
'participant_role' => array(
'name' => 'participant role',
Expand All @@ -349,6 +351,13 @@ public static function formRule($fields, $files, $self) {
$errors[$recipientKind[$fields['recipient']]['target_id']] = ts('If "Also include" or "Limit to" are selected, you must specify at least one %1', array(1 => $recipientKind[$fields['recipient']]['name']));
}

//CRM-21523
if (!empty($fields['is_repeat']) &&
(empty($fields['repetition_frequency_interval']) || ($fields['end_frequency_interval'] == NULL))
) {
$errors['is_repeat'] = ts('If you are enabling repetition you must indicate the frequency and ending term.');
}

$actionSchedule = $self->parseActionSchedule($fields);
if ($actionSchedule->mapping_id) {
$mapping = CRM_Core_BAO_ActionSchedule::getMapping($actionSchedule->mapping_id);
Expand Down
2 changes: 1 addition & 1 deletion CRM/Case/Form/Task/PDF.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ class CRM_Case_Form_Task_PDF extends CRM_Case_Form_Task {
* Build all the data structures needed to build the form.
*/
public function preProcess() {
CRM_Contact_Form_Task_PDFLetterCommon::preProcess($this);
$this->skipOnHold = $this->skipDeceased = FALSE;
parent::preProcess();
$this->setContactIDs();
CRM_Contact_Form_Task_PDFLetterCommon::preProcess($this);
}

/**
Expand Down
28 changes: 23 additions & 5 deletions CRM/Contact/BAO/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,27 @@ protected static function resolveStateProvinceID($values, $countryID) {
return NULL;
}

/**
* Get the relevant location entity for the array key.
*
* Based on the field name we determine which location entity
* we are dealing with. Apart from a few specific ones they
* are mostly 'address' (the default).
*
* @param string $fieldName
*
* @return string
*/
protected static function getLocationEntityForKey($fieldName) {
if (in_array($fieldName, ['email', 'phone', 'im', 'openid'])) {
return $fieldName;
}
if ($fieldName === 'phone_ext') {
return 'phone';
}
return 'address';
}

/**
* Create last viewed link to recently updated contact.
*
Expand Down Expand Up @@ -2181,7 +2202,7 @@ public static function formatProfileContactParams(

$loc = CRM_Utils_Array::key($index, $locationType);

$blockName = in_array($fieldName, $blocks) ? $fieldName : 'address';
$blockName = self::getLocationEntityForKey($fieldName);

$data[$blockName][$loc]['location_type_id'] = $locTypeId;

Expand Down Expand Up @@ -2219,9 +2240,6 @@ public static function formatProfileContactParams(
unset($data['phone'][$loc]['is_primary']);
}
}
elseif ($fieldName == 'phone_ext') {
$data['phone'][$loc]['phone_ext'] = $value;
}
elseif ($fieldName == 'email') {
$data['email'][$loc]['email'] = $value;
if (empty($contactID)) {
Expand Down Expand Up @@ -2278,7 +2296,7 @@ public static function formatProfileContactParams(
$data['address'][$loc][substr($fieldName, 8)] = $value;
}
else {
$data['address'][$loc][$fieldName] = $value;
$data[$blockName][$loc][$fieldName] = $value;
}
}
}
Expand Down
42 changes: 16 additions & 26 deletions CRM/Contact/BAO/RelationshipType.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,26 +79,20 @@ public static function setIsActive($id, $is_active) {
* Add the relationship type in the db.
*
* @param array $params
* (reference ) an assoc array of name/value pairs.
* @param array $ids
* The array that holds all the db ids.
*
* @return CRM_Contact_DAO_RelationshipType
*/
public static function add(&$params, $ids = []) {
$params['id'] = CRM_Utils_Array::value('id', $params, CRM_Utils_Array::value('relationshipType', $ids));
//to change name, CRM-3336
if (empty($params['label_a_b']) && !empty($params['name_a_b'])) {
$params['label_a_b'] = $params['name_a_b'];
}

if (empty($params['label_b_a']) && !empty($params['name_b_a'])) {
$params['label_b_a'] = $params['name_b_a'];
}
public static function add($params) {
if (empty($params['id'])) {
// Set name to label if not set
if (empty($params['label_a_b']) && !empty($params['name_a_b'])) {
$params['label_a_b'] = $params['name_a_b'];
}
if (empty($params['label_b_a']) && !empty($params['name_b_a'])) {
$params['label_b_a'] = $params['name_b_a'];
}

// set label to name if it's not set - but *only* for
// ADD action. CRM-3336 as part from (CRM-3522)
if (!$params['id']) {
// set label to name if it's not set
if (empty($params['name_a_b']) && !empty($params['label_a_b'])) {
$params['name_a_b'] = $params['label_a_b'];
}
Expand All @@ -110,22 +104,18 @@ public static function add(&$params, $ids = []) {
// action is taken depending upon the mode
$relationshipType = new CRM_Contact_DAO_RelationshipType();

$relationshipType->copyValues($params);
$hook = empty($params['id']) ? 'create' : 'edit';
CRM_Utils_Hook::pre($hook, 'RelationshipType', CRM_Utils_Array::value('id', $params), $params);

// if label B to A is blank, insert the value label A to B for it
if (!strlen(trim($strName = CRM_Utils_Array::value('name_b_a', $params)))) {
$relationshipType->name_b_a = CRM_Utils_Array::value('name_a_b', $params);
}
if (!strlen(trim($strName = CRM_Utils_Array::value('label_b_a', $params)))) {
$relationshipType->label_b_a = CRM_Utils_Array::value('label_a_b', $params);
}
$relationshipType->copyValues($params);
$relationshipType->save();

$result = $relationshipType->save();
CRM_Utils_Hook::post($hook, 'RelationshipType', $relationshipType->id, $relationshipType);

CRM_Core_PseudoConstant::relationshipType('label', TRUE);
CRM_Core_PseudoConstant::relationshipType('name', TRUE);
CRM_Case_XMLProcessor::flushStaticCaches();
return $result;
return $relationshipType;
}

/**
Expand Down
111 changes: 61 additions & 50 deletions CRM/Contact/Form/Edit/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,56 +158,7 @@ public static function buildQuickForm(&$form, $addressBlockCount = NULL, $sharin
}
$form->assign('geoCode', $geoCode);

// Process any address custom data -
$groupTree = CRM_Core_BAO_CustomGroup::getTree('Address', NULL, $entityId);

if (isset($groupTree) && is_array($groupTree)) {
// use simplified formatted groupTree
$groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, $form);

// make sure custom fields are added /w element-name in the format - 'address[$blockId][custom-X]'
foreach ($groupTree as $id => $group) {
foreach ($group['fields'] as $fldId => $field) {
$groupTree[$id]['fields'][$fldId]['element_custom_name'] = $field['element_name'];
$groupTree[$id]['fields'][$fldId]['element_name'] = "address[$blockId][{$field['element_name']}]";
}
}

$defaults = array();
CRM_Core_BAO_CustomGroup::setDefaults($groupTree, $defaults);

// since we change element name for address custom data, we need to format the setdefault values
$addressDefaults = array();
foreach ($defaults as $key => $val) {
if (empty($val)) {
continue;
}

// inorder to set correct defaults for checkbox custom data, we need to converted flat key to array
// this works for all types custom data
$keyValues = explode('[', str_replace(']', '', $key));
$addressDefaults[$keyValues[0]][$keyValues[1]][$keyValues[2]] = $val;
}

$form->setDefaults($addressDefaults);

// we setting the prefix to 'dnc_' below, so that we don't overwrite smarty's grouptree var.
// And we can't set it to 'address_' because we want to set it in a slightly different format.
CRM_Core_BAO_CustomGroup::buildQuickForm($form, $groupTree, FALSE, 'dnc_');

// during contact editing : if no address is filled
// required custom data must not produce 'required' form rule error
// more handling done in formRule func
CRM_Contact_Form_Edit_Address::storeRequiredCustomDataInfo($form, $groupTree);

$tplGroupTree = CRM_Core_Smarty::singleton()->get_template_vars('address_groupTree');
$tplGroupTree = empty($tplGroupTree) ? array() : $tplGroupTree;

$form->assign('address_groupTree', $tplGroupTree + array($blockId => $groupTree));
// unset the temp smarty var that got created
$form->assign('dnc_groupTree', NULL);
}
// address custom data processing ends ..
self::addCustomDataToForm($form, $entityId, $blockId);

if ($sharing) {
// shared address
Expand Down Expand Up @@ -434,4 +385,64 @@ public static function storeRequiredCustomDataInfo(&$form, $groupTree) {
}
}

/**
* Add custom data to the form.
*
* @param CRM_Core_Form $form
* @param int $entityId
* @param int $blockId
*/
protected static function addCustomDataToForm(&$form, $entityId, $blockId) {
$groupTree = CRM_Core_BAO_CustomGroup::getTree('Address', NULL, $entityId);

if (isset($groupTree) && is_array($groupTree)) {
// use simplified formatted groupTree
$groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, $form);

// make sure custom fields are added /w element-name in the format - 'address[$blockId][custom-X]'
foreach ($groupTree as $id => $group) {
foreach ($group['fields'] as $fldId => $field) {
$groupTree[$id]['fields'][$fldId]['element_custom_name'] = $field['element_name'];
$groupTree[$id]['fields'][$fldId]['element_name'] = "address[$blockId][{$field['element_name']}]";
}
}

$defaults = array();
CRM_Core_BAO_CustomGroup::setDefaults($groupTree, $defaults);

// since we change element name for address custom data, we need to format the setdefault values
$addressDefaults = array();
foreach ($defaults as $key => $val) {
if (empty($val)) {
continue;
}

// inorder to set correct defaults for checkbox custom data, we need to converted flat key to array
// this works for all types custom data
$keyValues = explode('[', str_replace(']', '', $key));
$addressDefaults[$keyValues[0]][$keyValues[1]][$keyValues[2]] = $val;
}

$form->setDefaults($addressDefaults);

// we setting the prefix to 'dnc_' below, so that we don't overwrite smarty's grouptree var.
// And we can't set it to 'address_' because we want to set it in a slightly different format.
CRM_Core_BAO_CustomGroup::buildQuickForm($form, $groupTree, FALSE, 'dnc_');

// during contact editing : if no address is filled
// required custom data must not produce 'required' form rule error
// more handling done in formRule func
CRM_Contact_Form_Edit_Address::storeRequiredCustomDataInfo($form, $groupTree);

$tplGroupTree = CRM_Core_Smarty::singleton()
->get_template_vars('address_groupTree');
$tplGroupTree = empty($tplGroupTree) ? array() : $tplGroupTree;

$form->assign('address_groupTree', $tplGroupTree + array($blockId => $groupTree));
// unset the temp smarty var that got created
$form->assign('dnc_groupTree', NULL);
}
// address custom data processing ends ..
}

}
14 changes: 10 additions & 4 deletions CRM/Contact/Form/Merge.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ class CRM_Contact_Form_Merge extends CRM_Core_Form {

var $_contactType = NULL;

/**
* @var array
*/
public $criteria = array();

/**
* Query limit to be retained in the urls.
*
Expand Down Expand Up @@ -74,8 +79,9 @@ public function preProcess() {
$this->_gid = $gid = CRM_Utils_Request::retrieve('gid', 'Positive', $this, FALSE);
$this->_mergeId = CRM_Utils_Request::retrieve('mergeId', 'Positive', $this, FALSE);
$this->limit = CRM_Utils_Request::retrieve('limit', 'Positive', $this, FALSE);
$this->criteria = CRM_Utils_Request::retrieve('criteria', 'Json', $this, FALSE, '{}');

$urlParams = ['reset' => 1, 'rgid' => $this->_rgid, 'gid' => $this->_gid, 'limit' => $this->limit];
$urlParams = ['reset' => 1, 'rgid' => $this->_rgid, 'gid' => $this->_gid, 'limit' => $this->limit, 'criteria' => $this->criteria];

$this->bounceIfInvalid($this->_cid, $this->_oid);

Expand All @@ -100,7 +106,7 @@ public function preProcess() {
CRM_Core_Session::singleton()->pushUserContext($browseUrl);
}

$cacheKey = CRM_Dedupe_Merger::getMergeCacheKeyString($this->_rgid, $gid);
$cacheKey = CRM_Dedupe_Merger::getMergeCacheKeyString($this->_rgid, $gid, json_decode($this->criteria, TRUE));

$join = CRM_Dedupe_Merger::getJoinOnDedupeTable();
$where = "de.id IS NULL";
Expand Down Expand Up @@ -300,7 +306,7 @@ public function postProcess() {
$message = '<ul><li>' . ts('%1 has been updated.', array(1 => $name)) . '</li><li>' . ts('Contact ID %1 has been deleted.', array(1 => $this->_oid)) . '</li></ul>';
CRM_Core_Session::setStatus($message, ts('Contacts Merged'), 'success');

$urlParams = ['reset' => 1, 'cid' => $this->_cid, 'rgid' => $this->_rgid, 'gid' => $this->_gid, 'limit' => $this->limit];
$urlParams = ['reset' => 1, 'cid' => $this->_cid, 'rgid' => $this->_rgid, 'gid' => $this->_gid, 'limit' => $this->limit, 'criteria' => $this->criteria];
$contactViewUrl = CRM_Utils_System::url('civicrm/contact/view', ['reset' => 1, 'cid' => $this->_cid]);

if (!empty($formValues['_qf_Merge_submit'])) {
Expand All @@ -314,7 +320,7 @@ public function postProcess() {
}

if ($this->next && $this->_mergeId) {
$cacheKey = CRM_Dedupe_Merger::getMergeCacheKeyString($this->_rgid, $this->_gid);
$cacheKey = CRM_Dedupe_Merger::getMergeCacheKeyString($this->_rgid, $this->_gid, json_decode($this->criteria, TRUE));

$join = CRM_Dedupe_Merger::getJoinOnDedupeTable();
$where = "de.id IS NULL";
Expand Down
8 changes: 6 additions & 2 deletions CRM/Contact/Form/Task/EmailCommon.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,12 @@ public static function preProcessFromAddress(&$form, $bounce = TRUE) {

$form->_emails = array();

$contactID = CRM_Core_Session::singleton()->getLoggedInContactID();
$form->_contactIds = array($contactID);
// @TODO remove these line and to it somewhere more appropriate. Currently some classes (e.g Case
// are having to re-write contactIds afterwards due to this inappropriate variable setting
// If we don't have any contact IDs, use the logged in contact ID
if (empty($form->_contactIds)) {
$form->_contactIds = $form->_contactIds ?: [CRM_Core_Session::getLoggedInContactID()];
}

$fromEmailValues = CRM_Core_BAO_Email::getFromEmail();

Expand Down
Loading

0 comments on commit 638b464

Please sign in to comment.