Merge remote-tracking branch 'upstream/4.4' into 4.4-master-2014-06-01-20-54-24
[civicrm-core.git] / CRM / Report / Form / Contact / Relationship.php
CommitLineData
6a488035 1<?php
6a488035
TO
2
3/*
4 +--------------------------------------------------------------------+
06b69b18 5 | CiviCRM version 4.5 |
6a488035 6 +--------------------------------------------------------------------+
06b69b18 7 | Copyright CiviCRM LLC (c) 2004-2014 |
6a488035
TO
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
10 | |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
19 | |
20 | You should have received a copy of the GNU Affero General Public |
21 | License and the CiviCRM Licensing Exception along |
22 | with this program; if not, contact CiviCRM LLC |
23 | at info[AT]civicrm[DOT]org. If you have questions about the |
24 | GNU Affero General Public License or the licensing of CiviCRM, |
25 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 +--------------------------------------------------------------------+
27*/
28
29/**
30 *
31 * @package CRM
06b69b18 32 * @copyright CiviCRM LLC (c) 2004-2014
6a488035
TO
33 * $Id$
34 *
35 */
36class CRM_Report_Form_Contact_Relationship extends CRM_Report_Form {
37
38 protected $_summary = NULL;
39 protected $_emailField_a = FALSE;
40 protected $_emailField_b = FALSE;
7393ba64
M
41 protected $_phoneField_a = FALSE;
42 protected $_phoneField_b = FALSE;
6a488035 43 protected $_customGroupExtends = array(
2f4c2f5d 44 'Relationship');
6a488035 45 public $_drilldownReport = array('contact/detail' => 'Link to Detail Report');
2f4c2f5d 46
74cf4551
EM
47 /**
48 *
49 */
50 /**
51 *
52 */
6a488035
TO
53 function __construct() {
54
55 $contact_type = CRM_Contact_BAO_ContactType::getSelectElements(FALSE, TRUE, '_');
56
57 $this->_columns = array(
58 'civicrm_contact' =>
59 array(
60 'dao' => 'CRM_Contact_DAO_Contact',
61 'fields' =>
62 array(
63 'sort_name_a' =>
64 array('title' => ts('Contact A'),
65 'name' => 'sort_name',
66 'required' => TRUE,
67 ),
68 'id' =>
69 array(
70 'no_display' => TRUE,
71 'required' => TRUE,
72 ),
30f85891
RN
73 'contact_type_a' =>
74 array(
75 'title' => ts('Contact Type (Contact A)'),
76 'name' => 'contact_type',
77 ),
78 'contact_sub_type_a' =>
79 array(
80 'title' => ts('Contact SubType (Contact A)'),
81 'name' => 'contact_sub_type',
82 ),
6a488035
TO
83 ),
84 'filters' =>
85 array(
86 'sort_name_a' =>
87 array('title' => ts('Contact A'),
88 'name' => 'sort_name',
89 'operator' => 'like',
90 'type' => CRM_Report_Form::OP_STRING,
91 ),
92 ),
93 'grouping' => 'conact_a_fields',
94 ),
95 'civicrm_contact_b' =>
96 array(
97 'dao' => 'CRM_Contact_DAO_Contact',
98 'alias' => 'contact_b',
99 'fields' =>
100 array(
101 'sort_name_b' =>
102 array('title' => ts('Contact B'),
103 'name' => 'sort_name',
104 'required' => TRUE,
105 ),
106 'id' =>
107 array(
108 'no_display' => TRUE,
109 'required' => TRUE,
110 ),
30f85891
RN
111 'contact_type_b' =>
112 array(
113 'title' => ts('Contact Type (Contact B)'),
114 'name' => 'contact_type',
115 ),
116 'contact_sub_type_b' =>
117 array(
118 'title' => ts('Contact SubType (Contact B)'),
119 'name' => 'contact_sub_type',
120 ),
6a488035
TO
121 ),
122 'filters' =>
123 array(
124 'sort_name_b' =>
125 array('title' => ts('Contact B'),
126 'name' => 'sort_name',
127 'operator' => 'like',
128 'type' => CRM_Report_Form::OP_STRING,
129 ),
130 ),
131 'grouping' => 'conact_b_fields',
132 ),
133 'civicrm_email' =>
134 array(
135 'dao' => 'CRM_Core_DAO_Email',
136 'fields' =>
137 array(
138 'email_a' =>
a9315b5e 139 array('title' => ts('Email (Contact A)'),
6a488035
TO
140 'name' => 'email',
141 ),
142 ),
143 'grouping' => 'conact_a_fields',
144 ),
145 'civicrm_email_b' =>
146 array(
147 'dao' => 'CRM_Core_DAO_Email',
148 'alias' => 'email_b',
149 'fields' =>
150 array(
151 'email_b' =>
a9315b5e 152 array('title' => ts('Email (Contact B)'),
6a488035
TO
153 'name' => 'email',
154 ),
155 ),
156 'grouping' => 'conact_b_fields',
157 ),
7393ba64
M
158 'civicrm_phone' =>
159 array(
160 'dao' => 'CRM_Core_DAO_Phone',
161 'alias' => 'phone_a',
162 'fields' =>
163 array(
74cf4551 164 'phone_a' =>
7393ba64 165 array(
a9315b5e 166 'title' => ts('Phone (Contact A)'),
7393ba64
M
167 'name' => 'phone',
168 ),
74cf4551 169 'phone_ext_a' =>
7393ba64 170 array(
a9315b5e 171 'title' => ts('Phone Ext (Contact A)'),
7393ba64
M
172 'name' => 'phone_ext',
173 ),
174 ),
175 'grouping' => 'conact_a_fields',
176 ),
177 'civicrm_phone_b' =>
178 array(
179 'dao' => 'CRM_Core_DAO_Phone',
180 'alias' => 'phone_b',
181 'fields' =>
182 array(
74cf4551 183 'phone_b' =>
7393ba64 184 array(
a9315b5e 185 'title' => ts('Phone (Contact B)'),
7393ba64
M
186 'name' => 'phone'
187 ),
74cf4551 188 'phone_ext_b' =>
7393ba64 189 array(
a9315b5e 190 'title' => ts('Phone Ext (Contact B)'),
7393ba64
M
191 'name' => 'phone_ext'
192 ),
193 ),
194 'grouping' => 'conact_b_fields',
195 ),
6a488035
TO
196 'civicrm_relationship_type' =>
197 array(
198 'dao' => 'CRM_Contact_DAO_RelationshipType',
199 'fields' =>
200 array(
201 'label_a_b' =>
202 array('title' => ts('Relationship A-B '),
203 'default' => TRUE,
204 ),
205 'label_b_a' =>
206 array('title' => ts('Relationship B-A '),
207 'default' => TRUE,
208 ),
209 ),
210 'filters' =>
211 array(
212 'contact_type_a' =>
213 array('title' => ts('Contact Type A'),
214 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
215 'options' => $contact_type,
216 'type' => CRM_Utils_Type::T_STRING,
217 ),
218 'contact_type_b' =>
219 array('title' => ts('Contact Type B'),
220 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
221 'options' => $contact_type,
222 'type' => CRM_Utils_Type::T_STRING,
223 ),
224 ),
225 'grouping' => 'relation-fields',
226 ),
227 'civicrm_relationship' =>
228 array(
229 'dao' => 'CRM_Contact_DAO_Relationship',
230 'fields' =>
231 array(
232 'start_date' =>
233 array('title' => ts('Relationship Start Date'),
234 ),
235 'end_date' =>
236 array('title' => ts('Relationship End Date'),
237 ),
238 'description' =>
239 array('title' => ts('Description'),
240 ),
a9315b5e
DG
241 'relationship_id' =>
242 array(
243 'title' => ts('Rel ID'),
244 'name' => 'id',
245 ),
6a488035
TO
246 ),
247 'filters' =>
248 array(
249 'is_active' =>
250 array('title' => ts('Relationship Status'),
251 'operatorType' => CRM_Report_Form::OP_SELECT,
252 'options' =>
253 array(
254 '' => '- Any -',
255 1 => 'Active',
256 0 => 'Inactive',
257 ),
258 'type' => CRM_Utils_Type::T_INT,
259 ),
260 'relationship_type_id' =>
261 array('title' => ts('Relationship'),
262 'operatorType' => CRM_Report_Form::OP_SELECT,
263 'options' =>
264 array(
265 '' => '- any relationship type -') +
266 CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, 'null', NULL, NULL, TRUE),
267 'type' => CRM_Utils_Type::T_INT,
268 ),
269 ),
270 'grouping' => 'relation-fields',
271 ),
272 'civicrm_address' =>
273 array(
274 'dao' => 'CRM_Core_DAO_Address',
275 'filters' =>
276 array(
277 'country_id' =>
278 array('title' => ts('Country'),
279 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
280 'options' => CRM_Core_PseudoConstant::country(),
281 ),
282 'state_province_id' =>
283 array('title' => ts('State/Province'),
284 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
285 'options' => CRM_Core_PseudoConstant::stateProvince(),
286 ),
287 ),
288 'grouping' => 'contact-fields',
289 ),
290 'civicrm_group' =>
291 array(
292 'dao' => 'CRM_Contact_DAO_Group',
293 'alias' => 'cgroup',
294 'filters' =>
295 array(
296 'gid' =>
297 array(
298 'name' => 'group_id',
299 'title' => ts('Group'),
300 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
301 'group' => TRUE,
302 'options' => CRM_Core_PseudoConstant::group(),
303 ),
304 ),
305 ),
306 );
307
308 $this->_tagFilter = TRUE;
309 parent::__construct();
310 }
311
312 function preProcess() {
313 parent::preProcess();
314 }
315
316 function select() {
317 $select = $this->_columnHeaders = array();
318 foreach ($this->_columns as $tableName => $table) {
319 if (array_key_exists('fields', $table)) {
320 foreach ($table['fields'] as $fieldName => $field) {
8cc574cf 321 if (!empty($field['required']) || !empty($this->_params['fields'][$fieldName])) {
6a488035
TO
322
323 if ($fieldName == 'email_a') {
324 $this->_emailField_a = TRUE;
325 }
326 if ($fieldName == 'email_b') {
327 $this->_emailField_b = TRUE;
328 }
7393ba64
M
329 if ($fieldName == 'phone_a'){
330 $this->_phoneField_a = TRUE;
331 }
332 if ($fieldName == 'phone_b'){
333 $this->_phoneField_b = TRUE;
334 }
6a488035
TO
335 $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
336 $this->_columnHeaders["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array::value('type', $field);
337 $this->_columnHeaders["{$tableName}_{$fieldName}"]['title'] = CRM_Utils_Array::value('title', $field);
338 }
339 }
340 }
341 }
342
343 $this->_select = "SELECT " . implode(', ', $select) . " ";
344 }
345
346 function from() {
347 $this->_from = "
348 FROM civicrm_relationship {$this->_aliases['civicrm_relationship']}
2f4c2f5d 349
6a488035 350 INNER JOIN civicrm_contact {$this->_aliases['civicrm_contact']}
2f4c2f5d 351 ON ( {$this->_aliases['civicrm_relationship']}.contact_id_a =
6a488035
TO
352 {$this->_aliases['civicrm_contact']}.id )
353
354 INNER JOIN civicrm_contact {$this->_aliases['civicrm_contact_b']}
2f4c2f5d 355 ON ( {$this->_aliases['civicrm_relationship']}.contact_id_b =
6a488035
TO
356 {$this->_aliases['civicrm_contact_b']}.id )
357
358 {$this->_aclFrom} ";
359
360 if (!empty($this->_params['country_id_value']) ||
361 !empty($this->_params['state_province_id_value'])
362 ) {
363 $this->_from .= "
2f4c2f5d 364 INNER JOIN civicrm_address {$this->_aliases['civicrm_address']}
6a488035
TO
365 ON (( {$this->_aliases['civicrm_address']}.contact_id =
366 {$this->_aliases['civicrm_contact']}.id OR
367 {$this->_aliases['civicrm_address']}.contact_id =
2f4c2f5d 368 {$this->_aliases['civicrm_contact_b']}.id ) AND
6a488035
TO
369 {$this->_aliases['civicrm_address']}.is_primary = 1 ) ";
370 }
371
372 $this->_from .= "
373 INNER JOIN civicrm_relationship_type {$this->_aliases['civicrm_relationship_type']}
2f4c2f5d 374 ON ( {$this->_aliases['civicrm_relationship']}.relationship_type_id =
6a488035
TO
375 {$this->_aliases['civicrm_relationship_type']}.id ) ";
376
377 // include Email Field
378 if ($this->_emailField_a) {
2f4c2f5d 379 $this->_from .= "
6a488035
TO
380 LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']}
381 ON ( {$this->_aliases['civicrm_contact']}.id =
2f4c2f5d 382 {$this->_aliases['civicrm_email']}.contact_id AND
6a488035
TO
383 {$this->_aliases['civicrm_email']}.is_primary = 1 )";
384 }
385 if ($this->_emailField_b) {
2f4c2f5d 386 $this->_from .= "
387 LEFT JOIN civicrm_email {$this->_aliases['civicrm_email_b']}
6a488035 388 ON ( {$this->_aliases['civicrm_contact_b']}.id =
2f4c2f5d 389 {$this->_aliases['civicrm_email_b']}.contact_id AND
6a488035
TO
390 {$this->_aliases['civicrm_email_b']}.is_primary = 1 )";
391 }
7393ba64
M
392 // include Phone Field
393 if ($this->_phoneField_a) {
394 $this->_from .= "
395 LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']}
396 ON ( {$this->_aliases['civicrm_contact']}.id =
397 {$this->_aliases['civicrm_phone']}.contact_id AND
398 {$this->_aliases['civicrm_phone']}.is_primary = 1 )";
399 }
400 if ($this->_phoneField_b) {
401 $this->_from .= "
402 LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone_b']}
403 ON ( {$this->_aliases['civicrm_contact_b']}.id =
404 {$this->_aliases['civicrm_phone_b']}.contact_id AND
405 {$this->_aliases['civicrm_phone_b']}.is_primary = 1 )";
406 }
6a488035
TO
407 }
408
409 function where() {
410 $whereClauses = $havingClauses = array();
411 foreach ($this->_columns as $tableName => $table) {
412 if (array_key_exists('filters', $table)) {
413 foreach ($table['filters'] as $fieldName => $field) {
414
415 $clause = NULL;
416 if (CRM_Utils_Array::value('type', $field) & CRM_Utils_Type::T_DATE) {
417 $relative = CRM_Utils_Array::value("{$fieldName}_relative", $this->_params);
418 $from = CRM_Utils_Array::value("{$fieldName}_from", $this->_params);
419 $to = CRM_Utils_Array::value("{$fieldName}_to", $this->_params);
420
421 $clause = $this->dateClause($field['name'], $relative, $from, $to, $field['type']);
422 }
423 else {
424 $op = CRM_Utils_Array::value("{$fieldName}_op", $this->_params);
425 if ($op) {
426
427 if ($tableName == 'civicrm_relationship_type' &&
428 ($fieldName == 'contact_type_a' || $fieldName == 'contact_type_b')
429 ) {
430 $cTypes = CRM_Utils_Array::value("{$fieldName}_value", $this->_params);
431 $contactTypes = $contactSubTypes = array();
432 if (!empty($cTypes)) {
433 foreach ($cTypes as $ctype) {
434 $getTypes = CRM_Utils_System::explode('_', $ctype, 2);
435 if ($getTypes[1] && !in_array($getTypes[1], $contactSubTypes)) {
436 $contactSubTypes[] = $getTypes[1];
437 }
438 elseif ($getTypes[0] && !in_array($getTypes[0], $contactTypes)) {
439 $contactTypes[] = $getTypes[0];
440 }
441 }
442 }
443
444 if (!empty($contactTypes)) {
445 $clause = $this->whereClause($field,
446 $op,
447 $contactTypes,
448 CRM_Utils_Array::value("{$fieldName}_min", $this->_params),
449 CRM_Utils_Array::value("{$fieldName}_max", $this->_params)
450 );
451 }
452
453 if (!empty($contactSubTypes)) {
454 if ($fieldName == 'contact_type_a') {
455 $field['name'] = 'contact_sub_type_a';
456 }
457 else {
458 $field['name'] = 'contact_sub_type_b';
459 }
460 $field['dbAlias'] = $field['alias'] . '.' . $field['name'];
461 $subTypeClause = $this->whereClause($field,
462 $op,
463 $contactSubTypes,
464 CRM_Utils_Array::value("{$fieldName}_min", $this->_params),
465 CRM_Utils_Array::value("{$fieldName}_max", $this->_params)
466 );
467 if ($clause) {
468 $clause = '(' . $clause . ' OR ' . $subTypeClause . ')';
469 }
470 else {
471 $clause = $subTypeClause;
472 }
473 }
474 }
475 else {
476
477 $clause = $this->whereClause($field,
478 $op,
479 CRM_Utils_Array::value("{$fieldName}_value", $this->_params),
480 CRM_Utils_Array::value("{$fieldName}_min", $this->_params),
481 CRM_Utils_Array::value("{$fieldName}_max", $this->_params)
482 );
483 }
484 }
485 }
486
487 if (!empty($clause)) {
a7488080 488 if (!empty($field['having'])) {
6a488035
TO
489 $havingClauses[] = $clause;
490 }
491 else {
492 $whereClauses[] = $clause;
493 }
494 }
495 }
496 }
497 }
498
499 if (empty($whereClauses)) {
500 $this->_where = 'WHERE ( 1 ) ';
501 $this->_having = '';
502 }
503 else {
504 $this->_where = 'WHERE ' . implode(' AND ', $whereClauses);
505 }
506
507 if ($this->_aclWhere) {
508 $this->_where .= " AND {$this->_aclWhere} ";
509 }
510
511 if (!empty($havingClauses)) {
512 // use this clause to construct group by clause.
513 $this->_having = 'HAVING ' . implode(' AND ', $havingClauses);
514 }
515 }
516
74cf4551
EM
517 /**
518 * @param $rows
519 *
520 * @return array
521 */
6a488035
TO
522 function statistics(&$rows) {
523 $statistics = parent::statistics($rows);
524
525 $isStatusFilter = FALSE;
526 $relStatus = NULL;
527 if (CRM_Utils_Array::value('is_active_value', $this->_params) == '1') {
528 $relStatus = 'Is equal to Active';
529 }
530 elseif (CRM_Utils_Array::value('is_active_value', $this->_params) == '0') {
531 $relStatus = 'Is equal to Inactive';
532 }
a7488080 533 if (!empty($statistics['filters'])) {
6a488035
TO
534 foreach ($statistics['filters'] as $id => $value) {
535 //for displaying relationship type filter
536 if ($value['title'] == 'Relationship') {
537 $relTypes = CRM_Core_PseudoConstant::relationshipType();
538 $statistics['filters'][$id]['value'] = 'Is equal to ' . $relTypes[$this->_params['relationship_type_id_value']]['label_' . $this->relationType];
539 }
540
541 //for displaying relationship status
542 if ($value['title'] == 'Relationship Status') {
543 $isStatusFilter = TRUE;
544 $statistics['filters'][$id]['value'] = $relStatus;
545 }
546 }
547 }
548 //for displaying relationship status
549 if (!$isStatusFilter && $relStatus) {
550 $statistics['filters'][] = array(
551 'title' => 'Relationship Status',
552 'value' => $relStatus,
553 );
554 }
555 return $statistics;
556 }
557
558 function groupBy() {
559 $this->_groupBy = " ";
560 $groupBy = array();
561 if ($this->relationType == 'a_b') {
562 $groupBy[] = " {$this->_aliases['civicrm_contact']}.id";
563 }
564 elseif ($this->relationType == 'b_a') {
565 $groupBy[] = " {$this->_aliases['civicrm_contact_b']}.id";
566 }
567
568 if (!empty($groupBy)) {
569 $this->_groupBy = " GROUP BY " . implode(', ', $groupBy) . " , {$this->_aliases['civicrm_relationship']}.id ";
570 }
571 else {
572 $this->_groupBy = " GROUP BY {$this->_aliases['civicrm_relationship']}.id ";
573 }
574 }
575
576 function orderBy() {
577 $this->_orderBy = " ORDER BY {$this->_aliases['civicrm_contact']}.sort_name, {$this->_aliases['civicrm_contact_b']}.sort_name ";
578 }
579
580 function postProcess() {
581 $this->beginPostProcess();
582
583 $this->relationType = NULL;
584 $relType = array();
a7488080 585 if (!empty($this->_params['relationship_type_id_value'])) {
6a488035
TO
586 $relType = explode('_', $this->_params['relationship_type_id_value']);
587
588 $this->relationType = $relType[1] . '_' . $relType[2];
589 $this->_params['relationship_type_id_value'] = intval($relType[0]);
590 }
591
592 $this->buildACLClause(array($this->_aliases['civicrm_contact'], $this->_aliases['civicrm_contact_b']));
593 $sql = $this->buildQuery();
594 $this->buildRows($sql, $rows);
595
596 $this->formatDisplay($rows);
597 $this->doTemplateAssignment($rows);
598
599 if (!empty($relType)) {
600 // store its old value, CRM-5837
601 $this->_params['relationship_type_id_value'] = implode('_', $relType);
602 }
603 $this->endPostProcess($rows);
604 }
605
74cf4551
EM
606 /**
607 * @param $rows
608 */
6a488035
TO
609 function alterDisplay(&$rows) {
610 // custom code to alter rows
611 $entryFound = FALSE;
612
613 foreach ($rows as $rowNum => $row) {
614
615 // handle country
616 if (array_key_exists('civicrm_address_country_id', $row)) {
617 if ($value = $row['civicrm_address_country_id']) {
618 $rows[$rowNum]['civicrm_address_country_id'] = CRM_Core_PseudoConstant::country($value, FALSE);
619 }
620 $entryFound = TRUE;
621 }
622
623 if (array_key_exists('civicrm_address_state_province_id', $row)) {
624 if ($value = $row['civicrm_address_state_province_id']) {
625 $rows[$rowNum]['civicrm_address_state_province_id'] = CRM_Core_PseudoConstant::stateProvince($value, FALSE);
626 }
627 $entryFound = TRUE;
628 }
629
630 if (array_key_exists('civicrm_contact_sort_name_a', $row) &&
631 array_key_exists('civicrm_contact_id', $row)
632 ) {
633 $url = CRM_Report_Utils_Report::getNextUrl('contact/detail',
634 'reset=1&force=1&id_op=eq&id_value=' . $row['civicrm_contact_id'],
635 $this->_absoluteUrl, $this->_id, $this->_drilldownReport
636 );
a9315b5e 637 $rows[$rowNum]['civicrm_contact_sort_name_a'] = $rows[$rowNum]['civicrm_contact_sort_name_a'] . ' (' . $rows[$rowNum]['civicrm_contact_id'] . ')';
6a488035
TO
638 $rows[$rowNum]['civicrm_contact_sort_name_a_link'] = $url;
639 $rows[$rowNum]['civicrm_contact_sort_name_a_hover'] = ts("View Contact details for this contact.");
640 $entryFound = TRUE;
641 }
642
643 if (array_key_exists('civicrm_contact_b_sort_name_b', $row) &&
644 array_key_exists('civicrm_contact_b_id', $row)
645 ) {
646 $url = CRM_Report_Utils_Report::getNextUrl('contact/detail',
647 'reset=1&force=1&id_op=eq&id_value=' . $row['civicrm_contact_b_id'],
648 $this->_absoluteUrl, $this->_id, $this->_drilldownReport
649 );
a9315b5e 650 $rows[$rowNum]['civicrm_contact_b_sort_name_b'] = $rows[$rowNum]['civicrm_contact_b_sort_name_b'] . ' (' . $rows[$rowNum]['civicrm_contact_b_id'] . ')';
6a488035
TO
651 $rows[$rowNum]['civicrm_contact_b_sort_name_b_link'] = $url;
652 $rows[$rowNum]['civicrm_contact_b_sort_name_b_hover'] = ts("View Contact details for this contact.");
653 $entryFound = TRUE;
654 }
655
a9315b5e
DG
656 if (array_key_exists('civicrm_relationship_relationship_id', $row) && array_key_exists('civicrm_contact_id', $row)) {
657 $url = "/civicrm/contact/view/rel?reset=1&action=update&rtype=a_b&cid=" . $row['civicrm_contact_id'] . "&id=" . $row['civicrm_relationship_relationship_id'];
658 $rows[$rowNum]['civicrm_relationship_relationship_id_link'] = $url;
659 $rows[$rowNum]['civicrm_relationship_relationship_id_hover'] = ts("Edit this relationship.");
660 $entryFound = TRUE;
661 }
662
6a488035
TO
663 // skip looking further in rows, if first row itself doesn't
664 // have the column we need
665 if (!$entryFound) {
666 break;
667 }
668 }
669 }
670}
671