From 31c31c920d79d9c377232460e12c87752383a18b Mon Sep 17 00:00:00 2001 From: Brian Shaughnessy Date: Sat, 1 Mar 2014 01:56:55 -0500 Subject: [PATCH] CRM-14190 restructure how we handle parent group selection; add to smart group task --- CRM/Contact/Form/Task/SaveSearch.php | 11 ++ CRM/Group/Form/Edit.php | 110 ++++++++++-------- .../CRM/Contact/Form/Task/SaveSearch.tpl | 56 ++++----- templates/CRM/Group/Form/Edit.tpl | 25 +--- templates/CRM/Group/Form/ParentGroups.tpl | 49 ++++++++ 5 files changed, 156 insertions(+), 95 deletions(-) create mode 100644 templates/CRM/Group/Form/ParentGroups.tpl diff --git a/CRM/Contact/Form/Task/SaveSearch.php b/CRM/Contact/Form/Task/SaveSearch.php index 6e7875e183..7d7ad48aed 100644 --- a/CRM/Contact/Form/Task/SaveSearch.php +++ b/CRM/Contact/Form/Task/SaveSearch.php @@ -122,6 +122,9 @@ class CRM_Contact_Form_Task_SaveSearch extends CRM_Contact_Form_Task { ); } + //CRM-14190 + CRM_Group_Form_Edit::buildParentGroups($this); + // get the group id for the saved search $groupID = NULL; if (isset($this->_id)) { @@ -208,6 +211,9 @@ class CRM_Contact_Form_Task_SaveSearch extends CRM_Contact_Form_Task { $params['saved_search_id'] = $savedSearch->id; $params['is_active'] = 1; + //CRM-14190 + $params['parents'] = $formValues['parents']; + if ($this->_id) { $params['id'] = CRM_Contact_BAO_SavedSearch::getName($this->_id, 'id'); } @@ -216,6 +222,11 @@ class CRM_Contact_Form_Task_SaveSearch extends CRM_Contact_Form_Task { // CRM-9464 $this->_id = $savedSearch->id; + + //CRM-14190 + if ( !empty($formValues['parents']) ) { + CRM_Contact_BAO_GroupNestingCache::update(); + } } } diff --git a/CRM/Group/Form/Edit.php b/CRM/Group/Form/Edit.php index d0c026dbd0..f87214777e 100644 --- a/CRM/Group/Form/Edit.php +++ b/CRM/Group/Form/Edit.php @@ -250,51 +250,9 @@ class CRM_Group_Form_Edit extends CRM_Core_Form { $this->add('select', 'visibility', ts('Visibility'), CRM_Core_SelectValues::groupVisibility(), TRUE); - $groupNames = CRM_Core_PseudoConstant::group(); + //CRM-14190 + $parentGroups = self::buildParentGroups($this); - $parentGroups = $parentGroupElements = array(); - if (isset($this->_id) && !empty($this->_groupValues['parents'])) { - $parentGroupIds = explode(',', $this->_groupValues['parents']); - foreach ($parentGroupIds as $parentGroupId) { - $parentGroups[$parentGroupId] = $groupNames[$parentGroupId]; - if (array_key_exists($parentGroupId, $groupNames)) { - $parentGroupElements[$parentGroupId] = $groupNames[$parentGroupId]; - $this->addElement('checkbox', "remove_parent_group_$parentGroupId", - $groupNames[$parentGroupId] - ); - } - } - } - $this->assign_by_ref('parent_groups', $parentGroupElements); - - if (isset($this->_id)) { - $potentialParentGroupIds = CRM_Contact_BAO_GroupNestingCache::getPotentialCandidates($this->_id, - $groupNames - ); - } - else { - $potentialParentGroupIds = array_keys($groupNames); - } - - $parentGroupSelectValues = array('' => '- ' . ts('select') . ' -'); - foreach ($potentialParentGroupIds as $potentialParentGroupId) { - if (array_key_exists($potentialParentGroupId, $groupNames)) { - $parentGroupSelectValues[$potentialParentGroupId] = $groupNames[$potentialParentGroupId]; - } - } - - if (count($parentGroupSelectValues) > 1) { - if (CRM_Core_Permission::isMultisiteEnabled()) { - $required = empty($parentGroups) ? TRUE : FALSE; - $required = (($this->_id && CRM_Core_BAO_Domain::isDomainGroup($this->_id)) || - !isset($this->_id) - ) ? FALSE : $required; - } - else { - $required = FALSE; - } - $this->add('select', 'parents', ts('Add Parent'), $parentGroupSelectValues, $required); - } if (CRM_Core_Permission::check('administer Multiple Organizations') && CRM_Core_Permission::isMultisiteEnabled()) { //group organization Element $props = array('api' => array('params' => array('contact_type' => 'Organization'))); @@ -438,8 +396,8 @@ WHERE title = %1 $group = CRM_Contact_BAO_Group::create($params); /* - * Remove any parent groups requested to be removed - */ + * Remove any parent groups requested to be removed + */ if (!empty($this->_groupValues['parents'])) { $parentGroupIds = explode(',', $this->_groupValues['parents']); @@ -471,5 +429,65 @@ WHERE title = %1 CRM_Contact_BAO_GroupNestingCache::update(); } } + + /* + * Build parent groups form elements + * + * @obj form object passed by reference + * + * @return parent groups array + * @static + * @access public + */ + static function buildParentGroups( &$obj ) { + $groupNames = CRM_Core_PseudoConstant::group(); + $parentGroups = $parentGroupElements = array(); + if (isset($obj->_id) && + CRM_Utils_Array::value('parents', $obj->_groupValues) + ) { + $parentGroupIds = explode(',', $obj->_groupValues['parents']); + foreach ($parentGroupIds as $parentGroupId) { + $parentGroups[$parentGroupId] = $groupNames[$parentGroupId]; + if (array_key_exists($parentGroupId, $groupNames)) { + $parentGroupElements[$parentGroupId] = $groupNames[$parentGroupId]; + $obj->addElement('checkbox', "remove_parent_group_$parentGroupId", + $groupNames[$parentGroupId] + ); + } + } + } + $obj->assign_by_ref('parent_groups', $parentGroupElements); + + if (isset($obj->_id)) { + $potentialParentGroupIds = CRM_Contact_BAO_GroupNestingCache::getPotentialCandidates($obj->_id, + $groupNames + ); + } + else { + $potentialParentGroupIds = array_keys($groupNames); + } + + $parentGroupSelectValues = array('' => '- ' . ts('select') . ' -'); + foreach ($potentialParentGroupIds as $potentialParentGroupId) { + if (array_key_exists($potentialParentGroupId, $groupNames)) { + $parentGroupSelectValues[$potentialParentGroupId] = $groupNames[$potentialParentGroupId]; + } + } + + if (count($parentGroupSelectValues) > 1) { + if (CRM_Core_Permission::isMultisiteEnabled()) { + $required = empty($parentGroups) ? TRUE : FALSE; + $required = (($obj->_id && CRM_Core_BAO_Domain::isDomainGroup($obj->_id)) || + !isset($obj->_id) + ) ? FALSE : $required; + } + else { + $required = FALSE; + } + $obj->add('select', 'parents', ts('Add Parent'), $parentGroupSelectValues, $required); + } + + return $parentGroups; + } } diff --git a/templates/CRM/Contact/Form/Task/SaveSearch.tpl b/templates/CRM/Contact/Form/Task/SaveSearch.tpl index 3520e08681..eadf864362 100644 --- a/templates/CRM/Contact/Form/Task/SaveSearch.tpl +++ b/templates/CRM/Contact/Form/Task/SaveSearch.tpl @@ -24,32 +24,36 @@ +--------------------------------------------------------------------+ *}
-

{ts}Smart Group{/ts}

- {if $qill[0]} -
-
    - {foreach from=$qill[0] item=criteria} -
  • {$criteria}
  • - {/foreach} -
-
-
- {/if} +

{ts}Smart Group{/ts}

+ {if $qill[0]} +
+
    + {foreach from=$qill[0] item=criteria} +
  • {$criteria}
  • + {/foreach} +
+
+
+ {/if} - - - - - - - - - {if $form.group_type} - - - - - {/if} + + + + + + + + + {if $form.group_type} + + + + + {/if}
{$form.title.label}{$form.title.html}
{$form.description.label}{$form.description.html}
{$form.group_type.label}{$form.group_type.html}
{$form.title.label}{$form.title.html}
{$form.description.label}{$form.description.html}
{$form.group_type.label}{$form.group_type.html}
-
{include file="CRM/common/formButtons.tpl" location="bottom"}
+ + {*CRM-14190*} + {include file="CRM/Group/Form/ParentGroups.tpl"} + +
{include file="CRM/common/formButtons.tpl" location="bottom"}
diff --git a/templates/CRM/Group/Form/Edit.tpl b/templates/CRM/Group/Form/Edit.tpl index e93e9092cd..bca800e8e8 100644 --- a/templates/CRM/Group/Form/Edit.tpl +++ b/templates/CRM/Group/Form/Edit.tpl @@ -87,29 +87,8 @@ - {if $parent_groups|@count > 0 or $form.parents.html} -

{ts}Parent Groups{/ts} {help id="id-group-parent" file="CRM/Group/Page/Group.hlp"}

- {if $parent_groups|@count > 0} - - - - - {foreach from=$parent_groups item=cgroup key=group_id} - {assign var="element_name" value="remove_parent_group_"|cat:$group_id} - - - - {/foreach} -
  {$form.$element_name.html} {$form.$element_name.label}
-
- {/if} - - - - - -
      {$form.parents.label}{$form.parents.html|crmAddClass:huge}
- {/if} + {*CRM-14190*} + {include file="CRM/Group/Form/ParentGroups.tpl"} {if $form.organization_id}

{ts}Associated Organization{/ts} {help id="id-group-organization" file="CRM/Group/Page/Group.hlp"}

diff --git a/templates/CRM/Group/Form/ParentGroups.tpl b/templates/CRM/Group/Form/ParentGroups.tpl new file mode 100644 index 0000000000..cf27b6f924 --- /dev/null +++ b/templates/CRM/Group/Form/ParentGroups.tpl @@ -0,0 +1,49 @@ +{* + +--------------------------------------------------------------------+ + | 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 | + +--------------------------------------------------------------------+ +*} +{*CRM-14190*} +{if $parent_groups|@count > 0 or $form.parents.html} +

{ts}Parent Groups{/ts} {help id="id-group-parent" file="CRM/Group/Page/Group.hlp"}

+ {if $parent_groups|@count > 0} + + + + + {foreach from=$parent_groups item=cgroup key=group_id} + {assign var="element_name" value="remove_parent_group_"|cat:$group_id} + + + + {/foreach} +
  {$form.$element_name.html} {$form.$element_name.label}
+
+ {/if} + + + + + +
      {$form.parents.label}{$form.parents.html|crmAddClass:huge}
+{/if} -- 2.25.1