CRM-16290 fix fatal on relationship edit
[civicrm-core.git] / CRM / Contact / Form / Relationship.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
39de6fd5 4 | CiviCRM version 4.6 |
6a488035 5 +--------------------------------------------------------------------+
e7112fa7 6 | Copyright CiviCRM LLC (c) 2004-2015 |
6a488035
TO
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
d25dd0ee 26 */
6a488035
TO
27
28/**
62e492d4 29 * This class generates form components for relationship.
6a488035
TO
30 */
31class CRM_Contact_Form_Relationship extends CRM_Core_Form {
32
6a488035
TO
33 /**
34 * The relationship id, used when editing the relationship
35 *
36 * @var int
37 */
d97a2fc1 38 public $_relationshipId;
6a488035
TO
39
40 /**
41 * The contact id, used when add/edit relationship
42 *
43 * @var int
44 */
d97a2fc1 45 public $_contactId;
6a488035
TO
46
47 /**
48 * This is a string which is either a_b or b_a used to determine the relationship between to contacts
6a488035 49 */
d97a2fc1 50 public $_rtype;
6a488035
TO
51
52 /**
53 * This is a string which is used to determine the relationship between to contacts
6a488035 54 */
d97a2fc1 55 public $_rtypeId;
6a488035
TO
56
57 /**
58 * Display name of contact a
6a488035 59 */
d97a2fc1 60 public $_display_name_a;
6a488035
TO
61
62 /**
63 * Display name of contact b
6a488035 64 */
d97a2fc1 65 public $_display_name_b;
6a488035
TO
66
67 /**
68 * The relationship type id
69 *
70 * @var int
71 */
d97a2fc1 72 public $_relationshipTypeId;
6a488035
TO
73
74 /**
100fef9d 75 * An array of all relationship names
6a488035
TO
76 *
77 * @var array
78 */
d97a2fc1 79 public $_allRelationshipNames;
6a488035 80
239dac31
CW
81 /**
82 * @var bool
83 */
d97a2fc1 84 public $_enabled;
239dac31
CW
85
86 /**
87 * @var bool
88 */
d97a2fc1 89 public $_isCurrentEmployer;
239dac31
CW
90
91 /**
92 * @var string
93 */
d97a2fc1 94 public $_contactType;
239dac31 95
6a488035
TO
96 /**
97 * The relationship values if Updating relationship
98 */
d97a2fc1 99 public $_values;
6a488035
TO
100
101 /**
100fef9d 102 * Casid if it called from case context
6a488035 103 */
d97a2fc1 104 public $_caseId;
6a488035 105
239dac31
CW
106 /**
107 * @var mixed
108 */
109 public $_cdType;
110
00be9182 111 public function preProcess() {
6a488035
TO
112 //custom data related code
113 $this->_cdType = CRM_Utils_Array::value('type', $_GET);
114 $this->assign('cdType', FALSE);
115 if ($this->_cdType) {
116 $this->assign('cdType', TRUE);
117 return CRM_Custom_Form_CustomData::preProcess($this);
118 }
119
120 $this->_contactId = $this->get('contactId');
121
239dac31
CW
122 $this->_contactType = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId, 'contact_type');
123
6a488035
TO
124 $this->_relationshipId = $this->get('id');
125
126 $this->_rtype = CRM_Utils_Request::retrieve('rtype', 'String', $this);
127
128 $this->_rtypeId = CRM_Utils_Request::retrieve('relTypeId', 'String', $this);
129
130 $this->_display_name_a = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId, 'display_name');
131
239dac31
CW
132 $this->assign('display_name_a', $this->_display_name_a);
133
134 // Set page title based on action
135 switch ($this->_action) {
136 case CRM_Core_Action::VIEW:
4dc79403 137 CRM_Utils_System::setTitle(ts('View Relationship for %1', array(1 => $this->_display_name_a)));
239dac31 138 break;
ea100cb5 139
239dac31 140 case CRM_Core_Action::ADD:
4dc79403 141 CRM_Utils_System::setTitle(ts('Add Relationship for %1', array(1 => $this->_display_name_a)));
239dac31 142 break;
ea100cb5 143
239dac31 144 case CRM_Core_Action::UPDATE:
4dc79403 145 CRM_Utils_System::setTitle(ts('Edit Relationship for %1', array(1 => $this->_display_name_a)));
239dac31 146 break;
ea100cb5 147
239dac31 148 case CRM_Core_Action::DELETE:
4dc79403 149 CRM_Utils_System::setTitle(ts('Delete Relationship for %1', array(1 => $this->_display_name_a)));
239dac31
CW
150 break;
151 }
6a488035
TO
152
153 $this->_caseId = CRM_Utils_Request::retrieve('caseID', 'Integer', $this);
154
155 //get the relationship values.
156 $this->_values = array();
157 if ($this->_relationshipId) {
158 $params = array('id' => $this->_relationshipId);
159 CRM_Core_DAO::commonRetrieve('CRM_Contact_DAO_Relationship', $params, $this->_values);
160 }
161
162 if (!$this->_rtypeId) {
163 $params = $this->controller->exportValues($this->_name);
164 if (isset($params['relationship_type_id'])) {
165 $this->_rtypeId = $params['relationship_type_id'];
166 }
167 elseif (!empty($this->_values)) {
168 $this->_rtypeId = $this->_values['relationship_type_id'] . '_' . $this->_rtype;
169 }
170 }
171
172 //get the relationship type id
173 $this->_relationshipTypeId = str_replace(array('_a_b', '_b_a'), array('', ''), $this->_rtypeId);
174
175 //get the relationship type
176 if (!$this->_rtype) {
177 $this->_rtype = str_replace($this->_relationshipTypeId . '_', '', $this->_rtypeId);
178 }
6a488035 179
239dac31
CW
180 //need to assign custom data type and subtype to the template - FIXME: explain why
181 $this->assign('customDataType', 'Relationship');
182 $this->assign('customDataSubType', $this->_relationshipTypeId);
183 $this->assign('entityID', $this->_relationshipId);
6a488035
TO
184
185 //use name as it remain constant, CRM-3336
186 $this->_allRelationshipNames = CRM_Core_PseudoConstant::relationshipType('name');
187
239dac31
CW
188 // Current employer?
189 if ($this->_action & CRM_Core_Action::UPDATE) {
190 if ($this->_allRelationshipNames[$this->_relationshipTypeId]["name_a_b"] == 'Employee of') {
191 $this->_isCurrentEmployer = $this->_values['contact_id_b'] == CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_values['contact_id_a'], 'employer_id');
192 }
193 }
194
6a488035 195 // when custom data is included in this page
a7488080 196 if (!empty($_POST['hidden_custom'])) {
6a488035
TO
197 CRM_Custom_Form_CustomData::preProcess($this);
198 CRM_Custom_Form_CustomData::buildQuickForm($this);
199 CRM_Custom_Form_CustomData::setDefaultValues($this);
200 }
201 }
202
203 /**
574d211d 204 * Set default values for the form.
6a488035 205 */
00be9182 206 public function setDefaultValues() {
6a488035
TO
207 if ($this->_cdType) {
208 return CRM_Custom_Form_CustomData::setDefaultValues($this);
209 }
210
211 $defaults = array();
212
213 if ($this->_action & CRM_Core_Action::UPDATE) {
214 if (!empty($this->_values)) {
215 $defaults['relationship_type_id'] = $this->_rtypeId;
a7488080 216 if (!empty($this->_values['start_date'])) {
6a488035
TO
217 list($defaults['start_date']) = CRM_Utils_Date::setDateDefaults($this->_values['start_date']);
218 }
a7488080 219 if (!empty($this->_values['end_date'])) {
6a488035
TO
220 list($defaults['end_date']) = CRM_Utils_Date::setDateDefaults($this->_values['end_date']);
221 }
222 $defaults['description'] = CRM_Utils_Array::value('description', $this->_values);
223 $defaults['is_active'] = CRM_Utils_Array::value('is_active', $this->_values);
239dac31
CW
224
225 // The javascript on the form will swap these fields if it is a b_a relationship, so we compensate here
226 $defaults['is_permission_a_b'] = CRM_Utils_Array::value('is_permission_' . $this->_rtype, $this->_values);
227 $defaults['is_permission_b_a'] = CRM_Utils_Array::value('is_permission_' . strrev($this->_rtype), $this->_values);
228
229 $defaults['is_current_employer'] = $this->_isCurrentEmployer;
230
231 // Load info about the related contact
6a488035
TO
232 $contact = new CRM_Contact_DAO_Contact();
233 if ($this->_rtype == 'a_b' && $this->_values['contact_id_a'] == $this->_contactId) {
234 $contact->id = $this->_values['contact_id_b'];
235 }
236 else {
237 $contact->id = $this->_values['contact_id_a'];
238 }
239 if ($contact->find(TRUE)) {
239dac31 240 $defaults['related_contact_id'] = $contact->id;
6a488035 241 $this->_display_name_b = $contact->display_name;
239dac31 242 $this->assign('display_name_b', $this->_display_name_b);
6a488035
TO
243 }
244
239dac31
CW
245 $noteParams = array(
246 'entity_id' => $this->_relationshipId,
247 'entity_table' => 'civicrm_relationship',
248 'limit' => 1,
21dfd5f5 249 'version' => 3,
239dac31 250 );
d3e86119 251 $note = civicrm_api('Note', 'getsingle', $noteParams);
239dac31 252 $defaults['note'] = CRM_Utils_Array::value('note', $note);
6a488035
TO
253 }
254 }
255 else {
239dac31 256 $defaults['is_active'] = $defaults['is_current_employer'] = 1;
6a488035
TO
257 $defaults['relationship_type_id'] = $this->_rtypeId;
258 }
259
260 $this->_enabled = $defaults['is_active'];
261 return $defaults;
262 }
263
264 /**
62e492d4 265 * Add the rules for form.
6a488035 266 */
00be9182 267 public function addRules() {
6a488035
TO
268 if ($this->_cdType) {
269 return;
270 }
271
272 if (!($this->_action & CRM_Core_Action::DELETE)) {
239dac31 273 $this->addFormRule(array('CRM_Contact_Form_Relationship', 'dateRule'));
6a488035
TO
274 }
275 }
276
277 /**
fe482240 278 * Build the form object.
6a488035
TO
279 */
280 public function buildQuickForm() {
281 if ($this->_cdType) {
282 return CRM_Custom_Form_CustomData::buildQuickForm($this);
283 }
284
6a488035 285 if ($this->_action & CRM_Core_Action::DELETE) {
6a488035
TO
286 $this->addButtons(array(
287 array(
288 'type' => 'next',
289 'name' => ts('Delete'),
290 'isDefault' => TRUE,
291 ),
292 array(
293 'type' => 'cancel',
294 'name' => ts('Cancel'),
295 ),
296 )
297 );
298 return;
299 }
239dac31
CW
300 // Just in case custom data includes a rich text field
301 $this->assign('includeWysiwygEditor', TRUE);
302
303 // Select list
304 $relationshipList = CRM_Contact_BAO_Relationship::getContactRelationshipType($this->_contactId, $this->_rtype, $this->_relationshipId);
305
306 // Metadata needed on clientside
307 $contactTypes = CRM_Contact_BAO_ContactType::contactTypeInfo(TRUE);
308 $jsData = array();
d97a2fc1 309 // Get just what we need to keep the dom small
239dac31 310 $whatWeWant = array_flip(array('contact_type_a', 'contact_type_b', 'contact_sub_type_a', 'contact_sub_type_b'));
22e263ad 311 foreach ($this->_allRelationshipNames as $id => $vals) {
239dac31
CW
312 if ($vals['name_a_b'] === 'Employee of') {
313 $this->assign('employmentRelationship', $id);
314 }
315 if (isset($relationshipList["{$id}_a_b"]) || isset($relationshipList["{$id}_b_a"])) {
316 $jsData[$id] = array_filter(array_intersect_key($this->_allRelationshipNames[$id], $whatWeWant));
317 // Add user-friendly placeholder
318 foreach (array('a', 'b') as $x) {
319 $type = !empty($jsData[$id]["contact_sub_type_$x"]) ? $jsData[$id]["contact_sub_type_$x"] : CRM_Utils_Array::value("contact_type_$x", $jsData[$id]);
320 $jsData[$id]["placeholder_$x"] = $type ? ts('- select %1 -', array(strtolower($contactTypes[$type]['label']))) : ts('- select contact -');
321 }
6a488035 322 }
6a488035 323 }
239dac31 324 $this->assign('relationshipData', $jsData);
6a488035 325
239dac31
CW
326 $this->add(
327 'select',
6a488035
TO
328 'relationship_type_id',
329 ts('Relationship Type'),
481a74f4 330 array('' => ts('- select -')) + $relationshipList,
239dac31
CW
331 TRUE,
332 array('class' => 'crm-select2 huge')
6a488035
TO
333 );
334
239dac31 335 $label = $this->_action & CRM_Core_Action::ADD ? ts('Contact(s)') : ts('Contact');
353ffa53
TO
336 $contactField = $this->addEntityRef('related_contact_id', $label, array(
337 'multiple' => TRUE,
bed98343 338 'create' => TRUE,
353ffa53 339 ), TRUE);
239dac31
CW
340 // This field cannot be updated
341 if ($this->_action & CRM_Core_Action::UPDATE) {
342 $contactField->freeze();
343 }
344
71331d2a 345 $this->add('advcheckbox', 'is_current_employer', $this->_contactType == 'Organization' ? ts('Current Employee') : ts('Current Employer'));
6a488035
TO
346
347 $this->addDate('start_date', ts('Start Date'), FALSE, array('formatType' => 'searchDate'));
348 $this->addDate('end_date', ts('End Date'), FALSE, array('formatType' => 'searchDate'));
6a488035 349
71331d2a 350 $this->add('advcheckbox', 'is_active', ts('Enabled?'));
239dac31 351
7dcb9f55
CW
352 // CRM-14612 - Don't use adv-checkbox as it interferes with the form js
353 $this->add('checkbox', 'is_permission_a_b');
354 $this->add('checkbox', 'is_permission_b_a');
6a488035
TO
355
356 $this->add('text', 'description', ts('Description'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Relationship', 'description'));
357
358 CRM_Contact_Form_Edit_Notes::buildQuickForm($this);
359
239dac31
CW
360 if ($this->_action & CRM_Core_Action::VIEW) {
361 $this->addButtons(array(
362 array(
363 'type' => 'cancel',
364 'name' => ts('Done'),
365 ),
366 ));
6a488035
TO
367 }
368 else {
239dac31
CW
369 // make this form an upload since we don't know if the custom data injected dynamically is of type file etc.
370 $this->addButtons(array(
371 array(
372 'type' => 'upload',
373 'name' => ts('Save Relationship'),
374 'isDefault' => TRUE,
375 ),
6a488035
TO
376 array(
377 'type' => 'cancel',
378 'name' => ts('Cancel'),
379 ),
239dac31
CW
380 ));
381 }
6a488035
TO
382 }
383
384 /**
62e492d4 385 * This function is called when the form is submitted.
6a488035
TO
386 */
387 public function postProcess() {
62e492d4 388 // Store the submitted values in an array.
6a488035 389 $params = $this->controller->exportValues($this->_name);
6a488035
TO
390
391 // action is taken depending upon the mode
6a488035
TO
392 if ($this->_action & CRM_Core_Action::DELETE) {
393 CRM_Contact_BAO_Relationship::del($this->_relationshipId);
394 return;
395 }
396
eff45dce
EM
397 $relationshipTypeParts = explode('_', $params['relationship_type_id']);
398 $params['relationship_type_id'] = $relationshipTypeParts[0];
399 if (!$this->_rtype) {
400 // Do we need to wrap this in an if - when is rtype used & is relationship_type_id always set then?
401 $this->_rtype = $params['relationship_type_id'];
402 }
403 $params['contact_id_' . $relationshipTypeParts[1]] = $this->_contactId;
404
71331d2a 405 // Update mode (always single)
6a488035 406 if ($this->_action & CRM_Core_Action::UPDATE) {
782bfb8a 407 $update = TRUE;
19e5c7f7 408 $params['id'] = $this->_relationshipId;
6a488035 409 $ids['relationship'] = $this->_relationshipId;
eff45dce 410 $relation = CRM_Contact_BAO_Relationship::getRelationshipByID($this->_relationshipId);
19e5c7f7 411 if ($relation->contact_id_a == $this->_contactId) {
6616f7c1 412 // I couldn't replicate this path in testing. See below.
19e5c7f7
EM
413 $params['contact_id_a'] = $this->_contactId;
414 $params['contact_id_b'] = array($params['related_contact_id']);
6616f7c1
EM
415 $outcome = CRM_Contact_BAO_Relationship::createMultiple($params, $relationshipTypeParts[1]);
416 $relationshipIds = $outcome['relationship_ids'];
19e5c7f7
EM
417 }
418 else {
6616f7c1
EM
419 // The only reason we have changed this to use the api & not the above is that this was broken.
420 // Recommend extracting all of update into a function that uses the api
421 // and ensuring api / bao take care of 'other stuff' in this form
422 // the contact_id_a & b can't be changed on this form so don't really need setting.
19e5c7f7 423 $params['contact_id_b'] = $this->_contactId;
6616f7c1
EM
424 $params['contact_id_a'] = $params['related_contact_id'];
425 $result = civicrm_api3('relationship', 'create', $params);
426 $relationshipIds = array($result['id']);
19e5c7f7 427 }
6a488035
TO
428 $ids['contactTarget'] = ($relation->contact_id_a == $this->_contactId) ? $relation->contact_id_b : $relation->contact_id_a;
429
2da59b29 430 // @todo this belongs in the BAO.
71331d2a
CW
431 if ($this->_isCurrentEmployer) {
432 // if relationship type changes, relationship is disabled, or "current employer" is unchecked,
433 // clear the current employer. CRM-3235.
eff45dce 434 $relChanged = $params['relationship_type_id'] != $this->_values['relationship_type_id'];
71331d2a
CW
435 if (!$params['is_active'] || !$params['is_current_employer'] || $relChanged) {
436 CRM_Contact_BAO_Contact_Utils::clearCurrentEmployer($this->_values['contact_id_a']);
2840a035
CW
437 // Refresh contact summary if in ajax mode
438 $this->ajaxResponse['reloadBlocks'] = array('#crm-contactinfo-content');
71331d2a 439 }
6a488035 440 }
6616f7c1 441 $this->setMessage(ts('The relationship has been updated'));
6a488035 442 }
71331d2a 443 // Create mode (could be 1 or more relationships)
239dac31 444 else {
62e492d4 445 $params['contact_id_' . $relationshipTypeParts[2]] = explode(',', $params['related_contact_id']);
6616f7c1
EM
446 $outcome = CRM_Contact_BAO_Relationship::createMultiple($params, $relationshipTypeParts[1]);
447 $relationshipIds = $outcome['relationship_ids'];
448 if (empty($outcome['saved']) && !empty($update)) {
449 $outcome['saved'] = $update;
450 }
451 $this->setMessage($outcome);
6a488035 452 }
6a488035 453
6a488035
TO
454
455 // if this is called from case view,
456 //create an activity for case role removal.CRM-4480
2da59b29 457 // @todo this belongs in the BAO.
6a488035
TO
458 if ($this->_caseId) {
459 CRM_Case_BAO_Case::createCaseRoleActivity($this->_caseId, $relationshipIds, $params['contact_check'], $this->_contactId);
460 }
461
239dac31 462 // Save notes
2da59b29 463 // @todo this belongs in the BAO.
30b335f1 464 if ($this->_action & CRM_Core_Action::UPDATE || $params['note']) {
239dac31
CW
465 foreach ($relationshipIds as $id) {
466 $noteParams = array(
467 'entity_id' => $id,
468 'entity_table' => 'civicrm_relationship',
469 );
d3e86119 470 $existing = civicrm_api3('note', 'get', $noteParams);
239dac31
CW
471 if (!empty($existing['id'])) {
472 $noteParams['id'] = $existing['id'];
473 }
474 $noteParams['note'] = $params['note'];
475 $noteParams['contact_id'] = $this->_contactId;
476 if (!empty($existing['id']) || $params['note']) {
477 $action = $params['note'] ? 'create' : 'delete';
478 civicrm_api3('note', $action, $noteParams);
479 }
6a488035 480 }
6a488035
TO
481 }
482
7e98675f
EM
483 $params['relationship_ids'] = $relationshipIds;
484
7e98675f
EM
485 // Refresh contact tabs which might have been affected
486 $this->ajaxResponse['updateTabs'] = array(
487 '#tab_member' => CRM_Contact_BAO_Contact::getCountComponent('membership', $this->_contactId),
488 '#tab_contribute' => CRM_Contact_BAO_Contact::getCountComponent('contribution', $this->_contactId),
489 );
490
239dac31 491 // Set current employee/employer relationship, CRM-3532
2da59b29
EM
492 if ($params['is_current_employer'] && $this->_allRelationshipNames[$params['relationship_type_id']]["name_a_b"] ==
493 'Employee of') {
239dac31
CW
494 $employerParams = array();
495 foreach ($relationshipIds as $id) {
496 // Fixme this is dumb why do we have to look this up again?
eff45dce 497 $rel = CRM_Contact_BAO_Relationship::getRelationshipByID($id);
239dac31 498 $employerParams[$rel->contact_id_a] = $rel->contact_id_b;
6a488035 499 }
2da59b29 500 // @todo this belongs in the BAO.
239dac31 501 CRM_Contact_BAO_Contact_Utils::setCurrentEmployer($employerParams);
2840a035
CW
502 // Refresh contact summary if in ajax mode
503 $this->ajaxResponse['reloadBlocks'] = array('#crm-contactinfo-content');
6a488035 504 }
6a488035
TO
505 }
506
507 /**
fe482240 508 * Date validation.
6a488035 509 *
77c5b619
TO
510 * @param array $params
511 * (reference ) an assoc array of name/value pairs.
6a488035 512 *
72b3a70c
CW
513 * @return bool|array
514 * mixed true or array of errors
6a488035 515 */
00be9182 516 public static function dateRule($params) {
6a488035
TO
517 $errors = array();
518
519 // check start and end date
8cc574cf 520 if (!empty($params['start_date']) && !empty($params['end_date'])) {
6a488035
TO
521 $start_date = CRM_Utils_Date::format(CRM_Utils_Array::value('start_date', $params));
522 $end_date = CRM_Utils_Date::format(CRM_Utils_Array::value('end_date', $params));
523 if ($start_date && $end_date && (int ) $end_date < (int ) $start_date) {
524 $errors['end_date'] = ts('The relationship end date cannot be prior to the start date.');
525 }
526 }
527
528 return empty($errors) ? TRUE : $errors;
529 }
530
2da59b29
EM
531 /**
532 * Set Status message to reflect outcome of the update action.
533 *
607fa308
EM
534 * @param array $outcome
535 * Outcome of save action - including
536 * - 'valid' : Number of valid relationships attempted.
537 * - 'invalid' : Number of invalid relationships attempted.
538 * - 'duplicate' : Number of duplicate relationships attempted.
539 * - 'saved' : boolean of whether save was successful
2da59b29 540 */
607fa308 541 protected function setMessage($outcome) {
782bfb8a 542 if (!empty($outcome['valid']) && empty($outcome['saved'])) {
2da59b29 543 CRM_Core_Session::setStatus(ts('Relationship created.', array(
607fa308 544 'count' => $outcome['valid'],
2da59b29
EM
545 'plural' => '%count relationships created.',
546 )), ts('Saved'), 'success');
547 }
607fa308 548 if (!empty($outcome['invalid'])) {
2da59b29 549 CRM_Core_Session::setStatus(ts('%count relationship record was not created due to an invalid contact type.', array(
607fa308 550 'count' => $outcome['invalid'],
2da59b29
EM
551 'plural' => '%count relationship records were not created due to invalid contact types.',
552 )), ts('%count invalid relationship record', array(
607fa308 553 'count' => $outcome['invalid'],
2da59b29
EM
554 'plural' => '%count invalid relationship records',
555 )));
556 }
607fa308 557 if (!empty($outcome['duplicate'])) {
2da59b29 558 CRM_Core_Session::setStatus(ts('One relationship was not created because it already exists.', array(
607fa308 559 'count' => $outcome['duplicate'],
2da59b29
EM
560 'plural' => '%count relationships were not created because they already exist.',
561 )), ts('%count duplicate relationship', array(
607fa308 562 'count' => $outcome['duplicate'],
2da59b29
EM
563 'plural' => '%count duplicate relationships',
564 )));
565 }
607fa308 566 if (!empty($outcome['saved'])) {
2da59b29
EM
567 CRM_Core_Session::setStatus(ts('Relationship record has been updated.'), ts('Saved'), 'success');
568 }
569 }
570
6a488035 571}