$order = $limit = '';
if (!$count) {
- $order = ' ORDER BY civicrm_relationship_type_id, sort_name ';
+ if (empty($params['sort'])) {
+ $order = ' ORDER BY civicrm_relationship_type_id, sort_name ';
+ }
+ else {
+ $order = " ORDER BY {$params['sort']} ";
+ }
+
+ $offset = 0;
+ if (!empty($params['offset'])) {
+ $offset = $params['offset'];
+ }
if ($numRelationship) {
- $limit = " LIMIT 0, $numRelationship";
+ $limit = " LIMIT {$offset}, $numRelationship";
}
}
// building the query string
- $queryString = '';
$queryString = $select1 . $from1 . $where1 . $select2 . $from2 . $where2 . $order . $limit;
$relationship = new CRM_Contact_DAO_Relationship();
}
}
}
+
+
+ /**
+ * This function is a wrapper for contact relationship selector
+ *
+ * @param array $params associated array for params record id.
+ *
+ * @return array $contactRelationships associated array of contact relationships
+ * @access public
+ */
+ public static function getContactRelationshipSelector(&$params) {
+ // format the params
+ $params['offset'] = ($params['page'] - 1) * $params['rp'];
+ $params['sort'] = CRM_Utils_Array::value('sortBy', $params);
+
+ if ($params['context'] == 'past') {
+ $relationshipStatus = CRM_Contact_BAO_Relationship::INACTIVE;
+ }
+ else {
+ $relationshipStatus = CRM_Contact_BAO_Relationship::CURRENT;
+ }
+
+ // check logged in user for permission
+ $page = new CRM_Core_Page();
+ CRM_Contact_Page_View::checkUserPermission($page, $params['contact_id']);
+ $permissions = array($page->_permission);
+ if ($page->_permission == CRM_Core_Permission::EDIT) {
+ $permissions[] = CRM_Core_Permission::DELETE;
+ }
+ $mask = CRM_Core_Action::mask($permissions);
+
+ // get contact relationships
+ $relationships = CRM_Contact_BAO_Relationship::getRelationship($params['contact_id'],
+ $relationshipStatus,
+ $params['rp'], 0, 0,
+ CRM_Contact_Page_View_Relationship::links(), $mask,
+ FALSE,
+ $params
+ );
+
+ $contactRelationships = array();
+ if (!empty($relationships)) {
+ // add total
+ $params['total'] = CRM_Contact_BAO_Relationship::getRelationship($params['contact_id'],
+ $relationshipStatus,
+ 0, 1);
+
+ // format params
+ foreach ($relationships as $relationshipId => $values) {
+ $contactRelationships[$relationshipId]['name'] = CRM_Utils_System::href(
+ $values['name'],
+ 'civicrm/contact/view',
+ "reset=1&cid={$values['contact_id_b']}");
+
+ $contactRelationships[$relationshipId]['relation'] = CRM_Utils_System::href(
+ $values['relation'],
+ 'civicrm/contact/view/rel',
+ "action=view&reset=1&cid={$values['contact_id_a']}&id={$values['id']}&rtype={$values['rtype']}");
+
+ if ($params['context'] != 'past') {
+ if (($params['contact_id'] == $values['contact_id_a'] AND $values['is_permission_a_b'] == 1) OR
+ ($params['contact_id'] == $values['contact_id_b'] AND $values['is_permission_b_a'] == 1)
+ ) {
+ $contactRelationships[$relationshipId]['name'] .= '<span id="permission-a-b" class="crm-marker permission-relationship"> *</span>';
+ }
+
+ if (($values['cid'] == $values['contact_id_a'] AND $values['is_permission_a_b'] == 1) OR
+ ($values['cid'] == $values['contact_id_b'] AND $values['is_permission_b_a'] == 1)
+ ) {
+ $contactRelationships[$relationshipId]['relation'] .= '<span id="permission-b-a" class="crm-marker permission-relationship"> *</span>';
+ }
+ }
+
+ if (!empty($values['description'])) {
+ $contactRelationships[$relationshipId]['relation'] .= "<p class='description'>{$values['description']}</p>";
+ }
+
+ $contactRelationships[$relationshipId]['start_date'] = CRM_Utils_Date::customFormat($values['start_date']);
+ $contactRelationships[$relationshipId]['end_date'] = CRM_Utils_Date::customFormat($values['end_date']);
+ $contactRelationships[$relationshipId]['city'] = $values['city'];
+ $contactRelationships[$relationshipId]['state'] = $values['state'];
+ $contactRelationships[$relationshipId]['email'] = $values['email'];
+ $contactRelationships[$relationshipId]['phone'] = $values['phone'];
+ $contactRelationships[$relationshipId]['links'] = $values['action'];
+ }
+ }
+ return $contactRelationships;
+ }
+
}
echo json_encode($addressVal);
CRM_Utils_System::civiExit();
}
+
+ /**
+ * Function to retrieve contact relationships
+ */
+ public static function getContactRelationships() {
+ $contactID = CRM_Utils_Type::escape($_GET['cid'], 'Integer');
+ $context = CRM_Utils_Type::escape($_GET['context'], 'String');
+
+ $sortMapper = array(
+ 0 => 'relation',
+ 1 => 'sort_name',
+ 2 => 'start_date',
+ 3 => 'end_date',
+ 4 => 'city',
+ 5 => 'state',
+ 6 => 'email',
+ 7 => 'phone',
+ 8 => 'links',
+ );
+
+ $sEcho = CRM_Utils_Type::escape($_REQUEST['sEcho'], 'Integer');
+ $offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayStart'], 'Integer') : 0;
+ $rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayLength'], 'Integer') : 25;
+ $sort = isset($_REQUEST['iSortCol_0']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_REQUEST['iSortCol_0'], 'Integer'), $sortMapper) : NULL;
+ $sortOrder = isset($_REQUEST['sSortDir_0']) ? CRM_Utils_Type::escape($_REQUEST['sSortDir_0'], 'String') : 'asc';
+
+ $params = $_POST;
+ if ($sort && $sortOrder) {
+ $params['sortBy'] = $sort . ' ' . $sortOrder;
+ }
+
+ $params['page'] = ($offset / $rowCount) + 1;
+ $params['rp'] = $rowCount;
+
+ $params['contact_id'] = $contactID;
+ $params['context'] = $context;
+
+ // get the contact relationships
+ $relationships = CRM_Contact_BAO_Relationship::getContactRelationshipSelector($params);
+
+ $iFilteredTotal = $iTotal = $params['total'];
+ $selectorElements = array(
+ 'relation',
+ 'name',
+ 'start_date',
+ 'end_date',
+ 'city',
+ 'state',
+ 'email',
+ 'phone',
+ 'links',
+ );
+
+ echo CRM_Utils_JSON::encodeDataTableSelector($relationships, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
+ CRM_Utils_System::civiExit();
+ }
}
* @access public
*/
function browse() {
- $links = self::links();
-
- //CRM-4418, handling edit and delete separately.
- $permissions = array($this->_permission);
- if ($this->_permission == CRM_Core_Permission::EDIT) {
- //previously delete was subset of edit
- //so for consistency lets grant delete also.
- $permissions[] = CRM_Core_Permission::DELETE;
- }
- $mask = CRM_Core_Action::mask($permissions);
-
- $currentRelationships = CRM_Contact_BAO_Relationship::getRelationship($this->_contactId,
- CRM_Contact_BAO_Relationship::CURRENT,
- 0, 0, 0,
- $links, $mask
- );
-
- $inactiveRelationships = CRM_Contact_BAO_Relationship::getRelationship($this->_contactId,
- CRM_Contact_BAO_Relationship::INACTIVE,
- 0, 0, 0,
- $links, $mask
- );
-
- $this->assign('currentRelationships', $currentRelationships);
- // to show the 'Current Relationships' title and links only when viewed
- // from relationship tab, not from dashboard
- $this->assign('relationshipTabContext', TRUE);
- $this->assign('inactiveRelationships', $inactiveRelationships);
-
- $this->ajaxResponse['tabCount'] = count($currentRelationships);
+ // do nothing :) we are using datatable for rendering relationship selectors
}
/**
<title>Activities</title>
<page_callback>CRM_Contact_Form_Task_SMS</page_callback>
</item>
+ <item>
+ <path>civicrm/ajax/contactrelationships</path>
+ <page_callback>CRM_Contact_Page_AJAX::getContactRelationships</page_callback>
+ <access_arguments>access CiviCRM</access_arguments>
+ </item>
</menu>
{elseif $action neq 16} {* add, update or view *}
{include file="CRM/Contact/Form/Relationship.tpl"}
{else}
-<div class="view-content">
-<div class="crm-block crm-content-block">
- {if $permission EQ 'edit'}
- <div class="action-link">
- <a accesskey="N" href="{crmURL p='civicrm/contact/view/rel' q="cid=`$contactId`&action=add&reset=1"}" class="button"><span><div class="icon add-icon"></div>{ts}Add Relationship{/ts}</span></a>
- </div>
- {/if}
- {include file="CRM/common/jsortable.tpl" useAjax=0}
- {* start of code to show current relationships *}
- {if $currentRelationships}
- {* show browse table for any action *}
- <div id="current-relationships">
- {if $relationshipTabContext} {*to show the title and links only when viewed from relationship tab, not from dashboard*}
- <h3>{ts}Current Relationships{/ts}</h3>
- {/if}
- {strip}
- <table id="current_relationship" class="display">
- <thead>
- <tr>
- <th>{ts}Relationship{/ts}</th>
- <th></th>
- <th id="tr-active-start_date">{ts}Start{/ts}</th>
- <th id="tr-active-end_date">{ts}End{/ts}</th>
- <th>{ts}City{/ts}</th>
- <th>{ts}State/Prov{/ts}</th>
- <th>{ts}Email{/ts}</th>
- <th>{ts}Phone{/ts}</th>
- <th></th>
- <th class="hiddenElement"></th>
- <th class="hiddenElement"></th>
- </tr>
- </thead>
- {foreach from=$currentRelationships item=rel}
- <tr id="relationship-{$rel.id}" class="crm-entity {cycle values="odd-row,even-row"} row-relationship {if $rel.is_permission_a_b eq 1 or $rel.is_permission_b_a eq 1}row-highlight{/if}">
+ <div class="view-content">
+ {if $permission EQ 'edit'}
+ <div class="action-link">
+ <a accesskey="N" href="{crmURL p='civicrm/contact/view/rel' q="cid=`$contactId`&action=add&reset=1"}"
+ class="button"><span><div class="icon add-icon"></div>{ts}Add Relationship{/ts}</span></a>
+ </div>
+ {/if}
+
+ {* display current relationships *}
+ <h3>{ts}Current Relationships{/ts}</h3>
+ {include file="CRM/Contact/Page/View/RelationshipSelector.tpl" context="current"}
+ <div id="permission-legend" class="crm-content-block">
+ <span class="crm-marker">* </span>
+ {ts}Indicates a permissioned relationship. This contact can be viewed and updated by the other.{/ts}
+ </div>
+
+ <div class="spacer"></div>
+ <p></p>
+ {* display past relationships *}
+ <div class="label font-red">{ts}Inactive Relationships{/ts}</div>
+ <div class="description">{ts}These relationships are Disabled OR have a past End Date.{/ts}</div>
+ {include file="CRM/Contact/Page/View/RelationshipSelector.tpl" context="past"}
+ </div>
- {if $relationshipTabContext}
- <td class="bold">
- <a href="{crmURL p='civicrm/contact/view/rel' q="action=view&reset=1&selectedChild=rel&cid=`$contactId`&id=`$rel.id`&rtype=`$rel.rtype`"}">{$rel.relation}</a>
- {if ($rel.cid eq $rel.contact_id_a and $rel.is_permission_a_b eq 1) OR
- ($rel.cid eq $rel.contact_id_b and $rel.is_permission_b_a eq 1) }
- <span id="permission-b-a" class="crm-marker permission-relationship"> *</span>
- {/if}
- {if $rel.description}<p class='description'>{$rel.description}</p>{/if}
- </td>
- <td>
- <a href="{crmURL p='civicrm/contact/view' q="action=view&reset=1&cid=`$rel.cid`"}">{$rel.name}</a>
- {if ($contactId eq $rel.contact_id_a and $rel.is_permission_a_b eq 1) OR
- ($contactId eq $rel.contact_id_b and $rel.is_permission_b_a eq 1) }
- <span id="permission-a-b" class="crm-marker permission-relationship"> *</span>
- {/if}
- </td>
- {else}
- <td class="bold">{$rel.relation}</strong></td>
- <td>{$rel.name}</td>
- {/if}
- <td class="crm-rel-start_date">{$rel.start_date}</td>
- <td class="crm-rel-end_date">{$rel.end_date}</td>
- <td>{$rel.city}</td>
- <td>{$rel.state}</td>
- <td>{$rel.email}</td>
- <td>{$rel.phone}</td>
- <td class="nowrap">{$rel.action|replace:'xx':$rel.id}</td>
- <td class="tr-active-start_date hiddenElement">{$rel.start_date|crmDate}</td>
- <td class="tr-active-end_date hiddenElement">{$rel.end_date|crmDate}</td>
- </tr>
- {/foreach}
- </table>
- {/strip}
- </div>
-
- {if $relationshipTabContext}
- <div id="permission-legend" class="crm-content-block">
- <span class="crm-marker">* </span>{ts}Indicates a permissioned relationship. This contact can be viewed and updated by the other.{/ts}
- </div>
- {/if}
-{/if}
-{* end of code to show current relationships *}
-
-{if $currentRelationships or $inactiveRelationships}
{include file="CRM/common/enableDisableApi.tpl"}
-{else}
- <div class="messages status no-popup">
- <div class="icon inform-icon"></div>
- {capture assign=link}accesskey="N" class="action-item action-item-first" href="{crmURL p='civicrm/contact/view/rel' q="cid=`$contactId`&action=add&reset=1"}"{/capture}
- {if $permission EQ 'edit'}
- {ts 1=$link}There are no Relationships entered for this contact. You can <a %1>add one</a>.{/ts}
- {elseif ! $relationshipTabContext}
- {ts}There are no related contacts / organizations on record for you.{/ts}
- {else}
- {ts}There are no Relationships entered for this contact.{/ts}
- {/if}
- </div>
-{/if}
-</div>
-<div class="spacer"></div>
-
-{* start of code to show inactive relationships *}
-{if $inactiveRelationships}
- {* show browse table for any action *}
- <div id="inactive-relationships">
- <p></p>
- <div class="label font-red">{ts}Inactive Relationships{/ts}</div>
- <div class="description">{ts}These relationships are Disabled OR have a past End Date.{/ts}</div>
- {strip}
- <table id="inactive_relationship" class="display">
- <thead>
- <tr>
- <th>{ts}Relationship{/ts}</th>
- <th></th>
- <th id="tr-inactive-start_date">{ts}Start{/ts}</th>
- <th id="tr-inactive-end_date">{ts}End{/ts}</th>
- <th>{ts}City{/ts}</th>
- <th>{ts}State/Prov{/ts}</th>
- <th>{ts}Email{/ts}</th>
- <th>{ts}Phone{/ts}</th>
- <th></th>
- <th class="hiddenElement"></th>
- <th class="hiddenElement"></th>
- </tr>
- </thead>
- {foreach from=$inactiveRelationships item=rel}
- {assign var = "rtype" value = "" }
- {if $rel.contact_a > 0 }
- {assign var = "rtype" value = "b_a" }
- {else}
- {assign var = "rtype" value = "a_b" }
- {/if}
- <tr id="relationship-{$rel.id}" class="crm-entity {cycle values="odd-row,even-row"}">
- <td class="bold">
- {$rel.relation}
- {if $rel.description}<p class='description'>{$rel.description}</p>{/if}
- </td>
- <td><a href="{crmURL p='civicrm/contact/view' q="reset=1&cid=`$rel.cid`"}">{$rel.name}</a></td>
- <td class="dis-crm-rel-start_date">{$rel.start_date}</td>
- <td class="dis-crm-rel-end_date">{$rel.end_date}</td>
- <td>{$rel.city}</td>
- <td>{$rel.state}</td>
- <td>{$rel.email}</td>
- <td>{$rel.phone}</td>
- <td class="nowrap">{$rel.action|replace:'xx':$rel.id}</td>
- <td class="tr-inactive-start_date hiddenElement">{$rel.start_date|crmDate}</td>
- <td class="tr-inactive-end_date hiddenElement">{$rel.end_date|crmDate}</td>
- </tr>
- {/foreach}
- </table>
- {/strip}
- </div>
-{/if}
-
-{* end of code to show inactive relationships *}
-
-
-</div>
{/if} {* close of custom data else*}
{if !empty($searchRows) }
- {*include custom data js file*}
- {include file="CRM/common/customData.tpl"}
+ {*include custom data js file*}
+ {include file="CRM/common/customData.tpl"}
{/if}
--- /dev/null
+{*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.4 |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2013 |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM. |
+ | |
+ | CiviCRM is free software; you can copy, modify, and distribute it |
+ | under the terms of the GNU Affero General Public License |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
+ | |
+ | CiviCRM is distributed in the hope that it will be useful, but |
+ | WITHOUT ANY WARRANTY; without even the implied warranty of |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
+ | See the GNU Affero General Public License for more details. |
+ | |
+ | You should have received a copy of the GNU Affero General Public |
+ | License and the CiviCRM Licensing Exception along |
+ | with this program; if not, contact CiviCRM LLC |
+ | at info[AT]civicrm[DOT]org. If you have questions about the |
+ | GNU Affero General Public License or the licensing of CiviCRM, |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing |
+ +--------------------------------------------------------------------+
+*}
+{* relationship selector *}
+
+<div class="crm-contact-relationship-{$context}">
+ <table id="crm-contact-relationship-selector-{$context}">
+ <thead>
+ <tr>
+ <th class='crm-contact-relationship-type'>{ts}Relationship{/ts}</th>
+ <th class='crm-contact-relationship-contact_name'> </th>
+ <th class='crm-contact-relationship-start_date'>{ts}Start{/ts}</th>
+ <th class='crm-contact-relationship-end_date'>{ts}End{/ts}</th>
+ <th class='crm-contact-relationship-city'>{ts}City{/ts}</th>
+ <th class='crm-contact-relationship-state'>{ts}State/Prov{/ts}</th>
+ <th class='crm-contact-relationship-email'>{ts}Email{/ts}</th>
+ <th class='crm-contact-relationship-phone'>{ts}Phone{/ts}</th>
+ <th class='crm-contact-relationship-links nosort'></th>
+ </tr>
+ </thead>
+ </table>
+</div>
+
+{literal}
+<script type="text/javascript">
+ var {/literal}{$context}{literal}oTable;
+
+ cj(function () {
+ buildContactRelationships{/literal}{$context}{literal}();
+ });
+
+ function buildContactRelationships{/literal}{$context}{literal}() {
+ var context = {/literal}"{$context}"{literal};
+ var sourceUrl = {/literal}'{crmURL p="civicrm/ajax/contactrelationships" h=0 q="context=$context&cid=$contactId"}'{literal};
+
+ var ZeroRecordText = {/literal}'{ts escape="js"}No matches found.{/ts}'{literal};
+
+ {/literal}{$context}{literal}oTable = cj('#crm-contact-relationship-selector-' + context).dataTable({
+ "bFilter": false,
+ "bAutoWidth": false,
+ "aaSorting": [],
+ "aoColumns": [
+ {sClass: 'crm-contact-relationship-type'},
+ {sClass: 'crm-contact-relationship-contact_name'},
+ {sClass: 'crm-contact-relationship-start_date'},
+ {sClass: 'crm-contact-relationship-end_date'},
+ {sClass: 'crm-contact-relationship-city'},
+ {sClass: 'crm-contact-relationship-state'},
+ {sClass: 'crm-contact-relationship-email'},
+ {sClass: 'crm-contact-relationship-phone'},
+ {sClass: 'crm-contact-relationship-links', bSortable: false},
+ ],
+ "bProcessing": true,
+ "sPaginationType": "full_numbers",
+ "sDom": '<"crm-datatable-pager-top"lfp>rt<"crm-datatable-pager-bottom"ip>',
+ "bServerSide": true,
+ "bJQueryUI": true,
+ "sAjaxSource": sourceUrl,
+ "iDisplayLength": 5,
+ "oLanguage": {
+ "sZeroRecords": ZeroRecordText,
+ "sProcessing": {/literal}"{ts escape='js'}Processing...{/ts}"{literal},
+ "sLengthMenu": {/literal}"{ts escape='js'}Show _MENU_ entries{/ts}"{literal},
+ "sInfo": {/literal}"{ts escape='js'}Showing _START_ to _END_ of _TOTAL_ entries{/ts}"{literal},
+ "sInfoEmpty": {/literal}"{ts escape='js'}Showing 0 to 0 of 0 entries{/ts}"{literal},
+ "sInfoFiltered": {/literal}"{ts escape='js'}(filtered from _MAX_ total entries){/ts}"{literal},
+ "sSearch": {/literal}"{ts escape='js'}Search:{/ts}"{literal},
+ "oPaginate": {
+ "sFirst": {/literal}"{ts escape='js'}First{/ts}"{literal},
+ "sPrevious": {/literal}"{ts escape='js'}Previous{/ts}"{literal},
+ "sNext": {/literal}"{ts escape='js'}Next{/ts}"{literal},
+ "sLast": {/literal}"{ts escape='js'}Last{/ts}"{literal}
+ }
+ },
+ "fnDrawCallback": function () {
+ {/literal}{if $context eq 'current'}{literal}
+ if (cj('#tab_rel').length) {
+ CRM.tabHeader.updateCount(cj('#tab_rel'), currentoTable.fnSettings().fnRecordsTotal());
+ }
+ {/literal}{/if}{literal}
+ }
+ });
+ }
+</script>
+{/literal}