From: kurund Date: Sat, 1 Mar 2014 20:57:31 +0000 (+0530) Subject: CRM-14201, converted contact relationship listing to ajax/datatable listing X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=40458f6cf58a53ee3aac5fc419e7d853231fd699;p=civicrm-core.git CRM-14201, converted contact relationship listing to ajax/datatable listing ---------------------------------------- * CRM-14201: Contact Relationships tab needs pagination http://issues.civicrm.org/jira/browse/CRM-14201 --- diff --git a/CRM/Contact/BAO/Relationship.php b/CRM/Contact/BAO/Relationship.php index a707f5f41d..41deda8d4e 100644 --- a/CRM/Contact/BAO/Relationship.php +++ b/CRM/Contact/BAO/Relationship.php @@ -963,15 +963,24 @@ LEFT JOIN civicrm_country ON (civicrm_address.country_id = civicrm_country.id) $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(); @@ -1599,5 +1608,94 @@ AND cc.sort_name LIKE '%$name%'"; } } } + + + /** + * 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'] .= ' *'; + } + + 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'] .= ' *'; + } + } + + if (!empty($values['description'])) { + $contactRelationships[$relationshipId]['relation'] .= "

{$values['description']}

"; + } + + $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; + } + } diff --git a/CRM/Contact/Page/AJAX.php b/CRM/Contact/Page/AJAX.php index e4995f7163..2dfdbf0c2e 100644 --- a/CRM/Contact/Page/AJAX.php +++ b/CRM/Contact/Page/AJAX.php @@ -1182,4 +1182,60 @@ LIMIT {$offset}, {$rowCount} 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(); + } } diff --git a/CRM/Contact/Page/View/Relationship.php b/CRM/Contact/Page/View/Relationship.php index 0c0763ad8b..7e352d1975 100644 --- a/CRM/Contact/Page/View/Relationship.php +++ b/CRM/Contact/Page/View/Relationship.php @@ -143,36 +143,7 @@ class CRM_Contact_Page_View_Relationship extends CRM_Core_Page { * @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 } /** diff --git a/CRM/Core/xml/Menu/Contact.xml b/CRM/Core/xml/Menu/Contact.xml index a79deb2344..7da14e0df8 100644 --- a/CRM/Core/xml/Menu/Contact.xml +++ b/CRM/Core/xml/Menu/Contact.xml @@ -409,4 +409,9 @@ Activities CRM_Contact_Form_Task_SMS + + civicrm/ajax/contactrelationships + CRM_Contact_Page_AJAX::getContactRelationships + access CiviCRM + diff --git a/templates/CRM/Contact/Page/View/Relationship.tpl b/templates/CRM/Contact/Page/View/Relationship.tpl index 68b58db466..99762d16f7 100644 --- a/templates/CRM/Contact/Page/View/Relationship.tpl +++ b/templates/CRM/Contact/Page/View/Relationship.tpl @@ -29,162 +29,34 @@ {elseif $action neq 16} {* add, update or view *} {include file="CRM/Contact/Form/Relationship.tpl"} {else} -
-
- {if $permission EQ 'edit'} - - {/if} - {include file="CRM/common/jsortable.tpl" useAjax=0} - {* start of code to show current relationships *} - {if $currentRelationships} - {* show browse table for any action *} -
- {if $relationshipTabContext} {*to show the title and links only when viewed from relationship tab, not from dashboard*} -

{ts}Current Relationships{/ts}

- {/if} - {strip} - - - - - - - - - - - - - - - - - {foreach from=$currentRelationships item=rel} - +
+ {if $permission EQ 'edit'} + + {/if} + + {* display current relationships *} +

{ts}Current Relationships{/ts}

+ {include file="CRM/Contact/Page/View/RelationshipSelector.tpl" context="current"} +
+ * + {ts}Indicates a permissioned relationship. This contact can be viewed and updated by the other.{/ts} +
+ +
+

+ {* display past relationships *} +
{ts}Inactive Relationships{/ts}
+
{ts}These relationships are Disabled OR have a past End Date.{/ts}
+ {include file="CRM/Contact/Page/View/RelationshipSelector.tpl" context="past"} +
- {if $relationshipTabContext} - - - {else} - - - {/if} - - - - - - - - - - - {/foreach} -
{ts}Relationship{/ts}{ts}Start{/ts}{ts}End{/ts}{ts}City{/ts}{ts}State/Prov{/ts}{ts}Email{/ts}{ts}Phone{/ts}
- {$rel.relation} - {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) } - * - {/if} - {if $rel.description}

{$rel.description}

{/if} -
- {$rel.name} - {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) } - * - {/if} - {$rel.relation}{$rel.name}{$rel.start_date}{$rel.end_date}{$rel.city}{$rel.state}{$rel.email}{$rel.phone}{$rel.action|replace:'xx':$rel.id}{$rel.start_date|crmDate}{$rel.end_date|crmDate}
- {/strip} -
- - {if $relationshipTabContext} -
- * {ts}Indicates a permissioned relationship. This contact can be viewed and updated by the other.{/ts} -
- {/if} -{/if} -{* end of code to show current relationships *} - -{if $currentRelationships or $inactiveRelationships} {include file="CRM/common/enableDisableApi.tpl"} -{else} -
-
- {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 add one.{/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} -
-{/if} -
-
- -{* start of code to show inactive relationships *} -{if $inactiveRelationships} - {* show browse table for any action *} -
-

-
{ts}Inactive Relationships{/ts}
-
{ts}These relationships are Disabled OR have a past End Date.{/ts}
- {strip} - - - - - - - - - - - - - - - - - {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} - - - - - - - - - - - - - - {/foreach} -
{ts}Relationship{/ts}{ts}Start{/ts}{ts}End{/ts}{ts}City{/ts}{ts}State/Prov{/ts}{ts}Email{/ts}{ts}Phone{/ts}
- {$rel.relation} - {if $rel.description}

{$rel.description}

{/if} -
{$rel.name}{$rel.start_date}{$rel.end_date}{$rel.city}{$rel.state}{$rel.email}{$rel.phone}{$rel.action|replace:'xx':$rel.id}{$rel.start_date|crmDate}{$rel.end_date|crmDate}
- {/strip} -
-{/if} - -{* end of code to show inactive relationships *} - - -
{/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} diff --git a/templates/CRM/Contact/Page/View/RelationshipSelector.tpl b/templates/CRM/Contact/Page/View/RelationshipSelector.tpl new file mode 100644 index 0000000000..425f436195 --- /dev/null +++ b/templates/CRM/Contact/Page/View/RelationshipSelector.tpl @@ -0,0 +1,107 @@ +{* + +--------------------------------------------------------------------+ + | 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 *} + +
+ + + + + + + + + + + + + + +
{ts}Relationship{/ts} {ts}Start{/ts}{ts}End{/ts}{ts}City{/ts}{ts}State/Prov{/ts}{ts}Email{/ts}{ts}Phone{/ts}
+
+ +{literal} + +{/literal}