CRM-14190 restructure how we handle parent group selection; add to smart group task
authorBrian Shaughnessy <brian@lcdservices.biz>
Sat, 1 Mar 2014 06:56:55 +0000 (01:56 -0500)
committerBrian Shaughnessy <brian@lcdservices.biz>
Sat, 1 Mar 2014 06:56:55 +0000 (01:56 -0500)
CRM/Contact/Form/Task/SaveSearch.php
CRM/Group/Form/Edit.php
templates/CRM/Contact/Form/Task/SaveSearch.tpl
templates/CRM/Group/Form/Edit.tpl
templates/CRM/Group/Form/ParentGroups.tpl [new file with mode: 0644]

index 6e7875e183d1f278e2cc9ab2de329be1d436bc32..7d7ad48aed302a88878df7f55621f704e21ba130 100644 (file)
@@ -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();
+    }
   }
 }
 
index d0c026dbd04c8a2cdce3d7f20e9bc12b19e24c87..f87214777e9dc171f60bd3ab7cc73a70d0ab9b93 100644 (file)
@@ -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;
+  }
 }
 
index 3520e08681874b5f5be1a4cb90ac7da2f3d30d17..eadf8643629b03b3d748482cd174683301010caa 100644 (file)
  +--------------------------------------------------------------------+
 *}
 <div class="crm-form-block crm-block crm-contact-task-createsmartgroup-form-block">
-<h3>{ts}Smart Group{/ts}</h3>
-    {if $qill[0]}
-        <div id="search-status">
-            <ul>
-                {foreach from=$qill[0] item=criteria}
-                    <li>{$criteria}</li>
-                {/foreach}
-            </ul>
-            <br />
-        </div>
-    {/if}
+  <h3>{ts}Smart Group{/ts}</h3>
+  {if $qill[0]}
+    <div id="search-status">
+      <ul>
+        {foreach from=$qill[0] item=criteria}
+          <li>{$criteria}</li>
+        {/foreach}
+      </ul>
+      <br />
+    </div>
+  {/if}
   <table class="form-layout-compressed">
-        <tr class="crm-contact-task-createsmartgroup-form-block-title">
-            <td class="label">{$form.title.label}</td>
-            <td>{$form.title.html}</td>
-        </tr>
-  <tr class="crm-contact-task-createsmartgroup-form-block-description">
-            <td class="label">{$form.description.label}</td>
-            <td>{$form.description.html}</td>
-        </tr>
-          {if $form.group_type}
-        <tr class="crm-contact-task-createsmartgroup-form-block-group_type">
-            <td class="label">{$form.group_type.label}</td>
-            <td>{$form.group_type.html}</td>
-        </tr>
-          {/if}
+    <tr class="crm-contact-task-createsmartgroup-form-block-title">
+      <td class="label">{$form.title.label}</td>
+      <td>{$form.title.html}</td>
+    </tr>
+    <tr class="crm-contact-task-createsmartgroup-form-block-description">
+      <td class="label">{$form.description.label}</td>
+      <td>{$form.description.html}</td>
+    </tr>
+    {if $form.group_type}
+      <tr class="crm-contact-task-createsmartgroup-form-block-group_type">
+        <td class="label">{$form.group_type.label}</td>
+        <td>{$form.group_type.html}</td>
+      </tr>
+    {/if}
   </table>
- <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
+
+  {*CRM-14190*}
+  {include file="CRM/Group/Form/ParentGroups.tpl"}
+
+  <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
 </div>
index e93e9092cd29c4083f514032749d368299fe39be..bca800e8e8128c8ac35f08c60c0d8778fa926259 100644 (file)
   </tr>
     </table>
 
-    {if $parent_groups|@count > 0 or $form.parents.html}
-  <h3>{ts}Parent Groups{/ts} {help id="id-group-parent" file="CRM/Group/Page/Group.hlp"}</h3>
-        {if $parent_groups|@count > 0}
-      <table class="form-layout-compressed">
-    <tr>
-        <td><label>{ts}Remove Parent?{/ts}</label></td>
-    </tr>
-    {foreach from=$parent_groups item=cgroup key=group_id}
-        {assign var="element_name" value="remove_parent_group_"|cat:$group_id}
-        <tr>
-      <td>&nbsp;&nbsp;{$form.$element_name.html}&nbsp;{$form.$element_name.label}</td>
-        </tr>
-    {/foreach}
-      </table>
-      <br />
-        {/if}
-        <table class="form-layout-compressed">
-      <tr class="crm-group-form-block-parents">
-          <td class="label">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{$form.parents.label}</td>
-          <td>{$form.parents.html|crmAddClass:huge}</td>
-      </tr>
-  </table>
-    {/if}
+  {*CRM-14190*}
+  {include file="CRM/Group/Form/ParentGroups.tpl"}
 
     {if $form.organization_id}
   <h3>{ts}Associated Organization{/ts} {help id="id-group-organization" file="CRM/Group/Page/Group.hlp"}</h3>
diff --git a/templates/CRM/Group/Form/ParentGroups.tpl b/templates/CRM/Group/Form/ParentGroups.tpl
new file mode 100644 (file)
index 0000000..cf27b6f
--- /dev/null
@@ -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}
+  <h3>{ts}Parent Groups{/ts} {help id="id-group-parent" file="CRM/Group/Page/Group.hlp"}</h3>
+  {if $parent_groups|@count > 0}
+    <table class="form-layout-compressed">
+      <tr>
+        <td><label>{ts}Remove Parent?{/ts}</label></td>
+      </tr>
+      {foreach from=$parent_groups item=cgroup key=group_id}
+        {assign var="element_name" value="remove_parent_group_"|cat:$group_id}
+        <tr>
+          <td>&nbsp;&nbsp;{$form.$element_name.html}&nbsp;{$form.$element_name.label}</td>
+        </tr>
+      {/foreach}
+    </table>
+    <br />
+  {/if}
+  <table class="form-layout-compressed">
+    <tr class="crm-group-form-block-parents">
+      <td class="label">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{$form.parents.label}</td>
+      <td>{$form.parents.html|crmAddClass:huge}</td>
+    </tr>
+  </table>
+{/if}