From 926dcf009bafa3f13f45937353baaa3a446f6d7a Mon Sep 17 00:00:00 2001 From: Kurund Jalmi <kurund@civicrm.org> Date: Sun, 19 May 2013 23:53:46 -0400 Subject: [PATCH] more work on CRM-12466, added new files for contact smart group --- CRM/Contact/BAO/GroupContactCache.php | 3 +- CRM/Contact/Page/View/ContactSmartGroup.php | 107 ++++++++++++++++++ CRM/Contact/Page/View/GroupContact.php | 2 + .../Contact/Page/View/ContactSmartGroup.tpl | 80 +++++++++++++ .../CRM/Contact/Page/View/GroupContact.tpl | 56 +-------- 5 files changed, 192 insertions(+), 56 deletions(-) create mode 100644 CRM/Contact/Page/View/ContactSmartGroup.php create mode 100644 templates/CRM/Contact/Page/View/ContactSmartGroup.tpl diff --git a/CRM/Contact/BAO/GroupContactCache.php b/CRM/Contact/BAO/GroupContactCache.php index 33f59d79c0..48436136b9 100644 --- a/CRM/Contact/BAO/GroupContactCache.php +++ b/CRM/Contact/BAO/GroupContactCache.php @@ -483,7 +483,8 @@ AND civicrm_group_contact.group_id = $groupID "; SELECT gc.group_id, gc.contact_id, g.title, g.children, g.description FROM civicrm_group_contact_cache gc INNER JOIN civicrm_group g ON g.id = gc.group_id -WHERE gc.contact_id IN ($contactIDString) +WHERE g.saved_search_id IS NOT NULL AND + gc.contact_id IN ($contactIDString) $hiddenClause ORDER BY gc.contact_id, g.children "; diff --git a/CRM/Contact/Page/View/ContactSmartGroup.php b/CRM/Contact/Page/View/ContactSmartGroup.php new file mode 100644 index 0000000000..483045a8ef --- /dev/null +++ b/CRM/Contact/Page/View/ContactSmartGroup.php @@ -0,0 +1,107 @@ +<?php +/* + +--------------------------------------------------------------------+ + | CiviCRM version 4.3 | + +--------------------------------------------------------------------+ + | 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 | + +--------------------------------------------------------------------+ +*/ + +/** + * + * @package CRM + * @copyright CiviCRM LLC (c) 2004-2013 + * $Id$ + * + */ +class CRM_Contact_Page_View_ContactSmartGroup extends CRM_Core_Page { + + /** + * This function is called when action is browse + * + * return null + * @access public + */ + function browse() { + $in = CRM_Contact_BAO_GroupContact::getContactGroup($this->_contactId, 'Added'); + + // keep track of all 'added' contact groups so we can remove them from the smart group + // section + $staticGroups = array(); + if (!empty($in)) { + foreach ($in as $group) { + $staticGroups[$group['group_id']] = 1; + } + } + + $allGroup = CRM_Contact_BAO_GroupContactCache::contactGroup($this->_contactId); + $this->assign('groupSmart' , null); + $this->assign('groupParent', null); + + if (!empty($allGroup)) { + $smart = $parent = array( ); + foreach ($allGroup['group'] as $group) { + // delete all smart groups which are also in static groups + if (isset($staticGroups[$group['id']])) { + continue; + } + if (empty($group['children'])) { + $smart[] = $group; + } + else { + $parent[] = $group; + } + } + + if (!empty($smart)) { + $this->assign_by_ref('groupSmart', $smart); + } + if (!empty($parent)) { + $this->assign_by_ref('groupParent', $parent); + } + } + } + + function preProcess() { + $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE); + $this->assign('contactId', $this->_contactId); + + // check logged in url permission + CRM_Contact_Page_View::checkUserPermission($this); + + $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse'); + $this->assign('action', $this->_action); + } + + /** + * This function is the main function that is called + * when the page loads, it decides the which action has + * to be taken for the page. + * + * return null + * @access public + */ + function run() { + $this->preProcess(); + $this->browse(); + return parent::run(); + } +} \ No newline at end of file diff --git a/CRM/Contact/Page/View/GroupContact.php b/CRM/Contact/Page/View/GroupContact.php index 11f3b0f768..ab0b2accc8 100644 --- a/CRM/Contact/Page/View/GroupContact.php +++ b/CRM/Contact/Page/View/GroupContact.php @@ -62,6 +62,7 @@ class CRM_Contact_Page_View_GroupContact extends CRM_Core_Page { $this->assign_by_ref('groupPending', $pending); $this->assign_by_ref('groupOut', $out); + /* $allGroup = CRM_Contact_BAO_GroupContactCache::contactGroup($this->_contactId); $this->assign('groupSmart' , null); $this->assign('groupParent', null); @@ -88,6 +89,7 @@ class CRM_Contact_Page_View_GroupContact extends CRM_Core_Page { $this->assign_by_ref('groupParent', $parent); } } + */ } /** diff --git a/templates/CRM/Contact/Page/View/ContactSmartGroup.tpl b/templates/CRM/Contact/Page/View/ContactSmartGroup.tpl new file mode 100644 index 0000000000..830acee373 --- /dev/null +++ b/templates/CRM/Contact/Page/View/ContactSmartGroup.tpl @@ -0,0 +1,80 @@ +{* + +--------------------------------------------------------------------+ + | CiviCRM version 4.3 | + +--------------------------------------------------------------------+ + | 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 | + +--------------------------------------------------------------------+ +*} +<div class="view-content"> + {if $groupSmart} + <div class="ht-one"></div> + <h3>{ts}Smart Groups{/ts}</h3> + <div class="description"> + {ts 1=$displayName}%1 is currently included in these Smart group(s) (e.g. saved searches).{/ts} + </div> + {strip} + <table id="smart_group" class="display"> + <thead> + <tr> + <th>{ts}Group{/ts}</th> + <th>{ts}Description{/ts}</th> + </tr> + </thead> + {foreach from=$groupSmart item=row} + <tr id="grp_{$row.id}" class="{cycle values="odd-row,even-row"}"> + <td class="bold"> + <a href="{crmURL p='civicrm/group/search' q="reset=1&force=1&context=smog&gid=`$row.id`"}"> + {$row.title} + </a> + </td> + <td>{$row.description}</td> + </tr> + {/foreach} + </table> + {/strip} + {/if} + {if $groupParent} + <div class="ht-one"></div> + <h3>{ts}Parent Groups{/ts}</h3> + <div class="description"> + {ts 1=$displayName}%1 is included in these Parent group(s) based on belonging to group(s) which are their + children.{/ts} + </div> + {strip} + <table id="parent_group" class="display"> + <thead> + <tr> + <th>{ts}Group{/ts}</th> + </tr> + </thead> + {foreach from=$groupParent item=row} + <tr id="grp_{$row.id}" class="{cycle values="odd-row,even-row"}"> + <td class="bold"> + <a href="{crmURL p='civicrm/group/search' q="reset=1&force=1&context=smog&gid=`$row.id`"}"> + {$row.title} + </a> + </td> + </tr> + {/foreach} + </table> + {/strip} + {/if} +</div> diff --git a/templates/CRM/Contact/Page/View/GroupContact.tpl b/templates/CRM/Contact/Page/View/GroupContact.tpl index b33ed1f57b..ba6cd34470 100644 --- a/templates/CRM/Contact/Page/View/GroupContact.tpl +++ b/templates/CRM/Contact/Page/View/GroupContact.tpl @@ -81,62 +81,9 @@ {/strip} {/if} - {if $groupSmart} - <div class="ht-one"></div> - <h3>{ts}Smart Groups{/ts}</h3> - <div class="description"> - {ts 1=$displayName}%1 is currently included in these Smart group(s) (e.g. saved searches).{/ts} - </div> - {strip} - <table id="smart_group" class="display"> - <thead> - <tr> - <th>{ts}Group{/ts}</th> - <th>{ts}Description{/ts}</th> - </tr> - </thead> - {foreach from=$groupSmart item=row} - <tr id="grp_{$row.id}" class="{cycle values="odd-row,even-row"}"> - <td class="bold"> - <a href="{crmURL p='civicrm/group/search' q="reset=1&force=1&context=smog&gid=`$row.id`"}"> - {$row.title} - </a> - </td> - <td>{$row.description}</td> - </tr> - {/foreach} - </table> - {/strip} - {/if} - {if $groupParent} - <div class="ht-one"></div> - <h3>{ts}Parent Groups{/ts}</h3> - <div class="description"> - {ts 1=$displayName}%1 is included in these Parent group(s) based on belonging to group(s) which are their - children.{/ts} - </div> - {strip} - <table id="parent_group" class="display"> - <thead> - <tr> - <th>{ts}Group{/ts}</th> - </tr> - </thead> - {foreach from=$groupParent item=row} - <tr id="grp_{$row.id}" class="{cycle values="odd-row,even-row"}"> - <td class="bold"> - <a href="{crmURL p='civicrm/group/search' q="reset=1&force=1&context=smog&gid=`$row.id`"}"> - {$row.title} - </a> - </td> - </tr> - {/foreach} - </table> - {/strip} - {/if} - {if $groupPending } + {if $groupPending} <div class="ht-one"></div> <h3 class="status-pending">{ts}Pending{/ts}</h3> <div class="description">{ts}Joining these group(s) is pending confirmation by this contact.{/ts}</div> @@ -219,5 +166,4 @@ </table> {/strip} {/if} -</div> </div> \ No newline at end of file -- GitLab