From 768a2093d5592ab22549a66cf334b2e8964682a2 Mon Sep 17 00:00:00 2001 From: Erik Hommel Date: Fri, 28 Oct 2016 16:22:34 +0200 Subject: [PATCH] extension now 4.6 and 4.7 compliant --- CRM/Groupprotect/BAO/GroupProtect.php | 51 +++- CRM/Groupprotect/CiviRulesActions/Add.php | 0 CRM/Groupprotect/CiviRulesActions/Remove.php | 0 .../CiviRulesActions/actions.mgd.php | 0 groupprotect.php | 17 ++ info.xml | 10 +- .../GroupContact.tpl => GroupContact46.tpl} | 17 +- templates/GroupContact47.tpl | 246 ++++++++++++++++++ templates/GroupProtect.tpl | 2 +- templates/RemoveAddToGroupButton.tpl | 20 ++ 10 files changed, 345 insertions(+), 18 deletions(-) mode change 100644 => 100755 CRM/Groupprotect/CiviRulesActions/Add.php mode change 100644 => 100755 CRM/Groupprotect/CiviRulesActions/Remove.php mode change 100644 => 100755 CRM/Groupprotect/CiviRulesActions/actions.mgd.php rename templates/{CRM/Contact/Page/View/GroupContact.tpl => GroupContact46.tpl} (95%) create mode 100755 templates/GroupContact47.tpl create mode 100755 templates/RemoveAddToGroupButton.tpl diff --git a/CRM/Groupprotect/BAO/GroupProtect.php b/CRM/Groupprotect/BAO/GroupProtect.php index b7af503..4329a45 100755 --- a/CRM/Groupprotect/BAO/GroupProtect.php +++ b/CRM/Groupprotect/BAO/GroupProtect.php @@ -8,11 +8,52 @@ * @license AGPL-3.0 */ class CRM_Groupprotect_BAO_GroupProtect { + + /** + * Method to process civicrm validateForm hook + * @param $formName + * @param $fields + * @param $files + * @param $form + * @param $errors + */ + public static function validateForm($formName, &$fields, &$files, &$form, &$errors) { + if ($formName == 'CRM_Contact_Form_GroupContact') { + if (self::userProtectPermitted() == FALSE) { + if (self::groupIsProtected($fields['group_id']) == TRUE) { + $errors['group_id'] = 'You are not allowed to add to this group'; + } + } + } + } + /** + * Method to process civicrm alterTemplateFile hook + * + * @param $formName + * @param $form + * @param $context + * @param $tplName + */ + public static function alterTemplateFile($formName, &$form, $context, &$tplName) { + if ($formName == "CRM_Contact_Page_View_GroupContact") { + $domainVersion = civicrm_api3('Domain', 'getvalue', array('return' => 'version')); + $version = substr($domainVersion,0,3); + switch ($version) { + case '4.6': + $tplName = 'GroupContact46.tpl'; + break; + case '4.7': + $tplName = 'GroupContact47.tpl'; + break; + } + } + + + } /** * Method to process civicrm pageRun hook * * action items only allowed for unprotected groups or if user has permission - * // todo now fixed in copy of template in extension, fix with core fix using jQuery * * @param object page */ @@ -35,7 +76,6 @@ public static function pageRun(&$page) { * @static */ public static function buildForm($formName, &$form) { - // todo make sure groups are NOT removed in smog contact? if possible.... if (self::userProtectPermitted() == FALSE) { switch ($formName) { case 'CRM_Group_Form_Edit': @@ -49,6 +89,13 @@ public static function buildForm($formName, &$form) { self::removeProtectedGroups($form); break; case 'CRM_Contact_Form_GroupContact': + self::removeProtectedGroups($form); + break; + case 'CRM_Contact_Form_Search_Basic': + $groupId = $form->getVar('_groupID'); + if ($groupId && self::groupIsProtected($groupId)) { + CRM_Core_Region::instance('page-body')->add(array('template' => 'RemoveAddToGroupButton.tpl')); + } break; } } diff --git a/CRM/Groupprotect/CiviRulesActions/Add.php b/CRM/Groupprotect/CiviRulesActions/Add.php old mode 100644 new mode 100755 diff --git a/CRM/Groupprotect/CiviRulesActions/Remove.php b/CRM/Groupprotect/CiviRulesActions/Remove.php old mode 100644 new mode 100755 diff --git a/CRM/Groupprotect/CiviRulesActions/actions.mgd.php b/CRM/Groupprotect/CiviRulesActions/actions.mgd.php old mode 100644 new mode 100755 diff --git a/groupprotect.php b/groupprotect.php index d5e36d5..ae66b48 100755 --- a/groupprotect.php +++ b/groupprotect.php @@ -13,6 +13,23 @@ function groupprotect_civicrm_buildForm($formName, &$form) { CRM_Groupprotect_BAO_GroupProtect::buildForm($formName, $form); } +function groupprotect_civicrm_validateForm($formName, &$fields, &$files, &$form, &$errors) { + CRM_Groupprotect_BAO_GroupProtect::validateForm($formName, $fields, $files, $form, $errors); +} +/** + * Implements hook_civicrm_alterTemplateFile for specific extension processing + * + * @param $formName + * @param $form + * @param $context + * @param $tplName + * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_alterTemplateFile + * + */ +function groupprotect_civicrm_alterTemplateFile($formName, &$form, $context, &$tplName) { + CRM_Groupprotect_BAO_GroupProtect::alterTemplateFile($formName, $form, $context, $tplName); +} + /** * Implements hook_civicrm_searchTasks for specific extension processing * diff --git a/info.xml b/info.xml index d36e40b..a028931 100755 --- a/info.xml +++ b/info.xml @@ -14,16 +14,12 @@ http://www.civicoop.org http://www.gnu.org/licenses/agpl-3.0.html -<<<<<<< HEAD - 2016-01-12 - 2.0 -======= - 2016-10-19 - 1.2 ->>>>>>> c02caaaa8511581cf03c63e5dd25035805d62cb8 + 2016-10-28 + 2.2 beta 4.6 + 4.7 Extension is being tested diff --git a/templates/CRM/Contact/Page/View/GroupContact.tpl b/templates/GroupContact46.tpl similarity index 95% rename from templates/CRM/Contact/Page/View/GroupContact.tpl rename to templates/GroupContact46.tpl index 614a3d3..8816899 100755 --- a/templates/CRM/Contact/Page/View/GroupContact.tpl +++ b/templates/GroupContact46.tpl @@ -53,6 +53,13 @@ {foreach from=$groupIn item=row} + {assign var='actionItemsAllowed' value=1} + {crmAPI var='result' entity='Group' action='getprotect' group_id=$row.group_id} + {foreach from=$result.values item=group} + {if $group.protected AND !$userHasProtectGroup} + {assign var='actionItemsAllowed' value=0} + {/if} + {/foreach} @@ -62,14 +69,7 @@ {ts 1=$row.in_method}Added (by %1){/ts} {$row.in_date|crmDate} - {assign var='actionItemsAllowed' value=1} - {crmAPI var='result' entity='Group' action='getprotect' group_id=$row.group_id} - {foreach from=$result.values item=group} - {if $group.protected AND !$userHasProtectGroup} - {assign var='actionItemsAllowed' value=0} - {/if} - {/foreach} - {if $permission EQ 'edit' AND $actionItemsAllowed} + {if $permission EQ 'edit' and $actionItemsAllowed} {ts}Remove{/ts} @@ -175,6 +175,7 @@ {assign var='actionItemsAllowed' value=0} {/if} {/foreach} + {if $permission EQ 'edit' AND $actionItemsAllowed} {ts}Rejoin Group{/ts} diff --git a/templates/GroupContact47.tpl b/templates/GroupContact47.tpl new file mode 100755 index 0000000..9c7daa5 --- /dev/null +++ b/templates/GroupContact47.tpl @@ -0,0 +1,246 @@ +{* + +--------------------------------------------------------------------+ + | CiviCRM version 4.7 | + +--------------------------------------------------------------------+ + | Copyright CiviCRM LLC (c) 2004-2016 | + +--------------------------------------------------------------------+ + | 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 | + +--------------------------------------------------------------------+ +*} +
+ {if $groupCount eq 0} +
+
+  {ts}This contact does not currently belong to any groups.{/ts} +
+ {else} + {include file="CRM/common/jsortable.tpl"} + {/if} + + {* Include 'add to new group' form if session has edit contact permissions *} + {if $permission EQ 'edit'} + {include file="CRM/Contact/Form/GroupContact.tpl"} + {/if} + + {if $groupIn } +
+

{ts}Regular Groups{/ts}

+
{ts 1=$displayName}%1 has joined or been added to these group(s).{/ts}
+ {strip} + + + + + + + + + + {foreach from=$groupIn item=row} + {assign var='actionItemsAllowed' value=1} + {crmAPI var='groupProtected' entity='Group' action='getprotect' group_id=$row.group_id} + {foreach from=$groupProtected.values item=apiGroup} + {if $apiGroup.protected AND !$userHasProtectGroup} + {assign var='actionItemsAllowed' value=0} + {/if} + {/foreach} + + + + + + + {/foreach} +
{ts}Group{/ts}{ts}Status{/ts}{ts}Date Added{/ts}
+ + {$row.title} + + {ts 1=$row.in_method}Added (by %1){/ts}{$row.in_date|crmDate} + {if $permission EQ 'edit' AND $actionItemsAllowed} + + {ts}Remove{/ts} + + {ts}Delete{/ts} + {/if} +
+ {/strip} + {/if} + + {if $contactSmartGroupSettings neq 3} +
+
+
+
+ {ts}Smart Groups{/ts} +
+ +
+
+
+ +
+ +
+ {/if} + + {if $groupPending} +
+

{ts}Pending{/ts}

+
{ts}Joining these group(s) is pending confirmation by this contact.{/ts}
+ {strip} + + + + + + + + + + {foreach from=$groupPending item=row} + {assign var='actionItemsAllowed' value=1} + {crmAPI var='groupProtected' entity='Group' action='getprotect' group_id=$row.group_id} + {foreach from=$groupProtected.values item=apiGroup} + {if $apiGroup.protected AND !$userHasProtectGroup} + {assign var='actionItemsAllowed' value=0} + {/if} + {/foreach} + + + + + + + {/foreach} +
{ts}Group{/ts}{ts}Status{/ts}{ts}Date Pending{/ts}
+ + {$row.title} + + {ts 1=$row.pending_method}Pending (by %1){/ts}{$row.pending_date|crmDate} + {if $permission EQ 'edit' AND $actionItemsAllowed} + + {ts}Remove{/ts} + + {ts}Delete{/ts} + {/if} +
+ {/strip} + {/if} + + {if $groupOut} +
+

{ts}Past Groups{/ts}

+
{ts 1=$displayName}%1 is no longer part of these group(s).{/ts}
+ {strip} + + + + + + + + + + + {foreach from=$groupOut item=row} + {assign var='actionItemsAllowed' value=1} + {crmAPI var='groupProtected' entity='Group' action='getprotect' group_id=$row.group_id} + {foreach from=$groupProtected.values item=apiGroup} + {if $apiGroup.protected AND !$userHasProtectGroup} + {assign var='actionItemsAllowed' value=0} + {/if} + {/foreach} + + + + + + + + {/foreach} +
{ts}Group{/ts}{ts}Status{/ts}{ts}Date Added{/ts}{ts}Date Removed{/ts}
+ + {$row.title} + + {ts 1=$row.out_method}Removed (by %1){/ts}{$row.date_added|crmDate}{$row.out_date|crmDate} + {if $permission EQ 'edit' AND $actionItemsAllowed} + + {ts}Rejoin Group{/ts} + + {ts}Delete{/ts}{/if} +
+ {/strip} + {/if} +
+ + +{literal} + diff --git a/templates/GroupProtect.tpl b/templates/GroupProtect.tpl index e6a26b1..db0267f 100755 --- a/templates/GroupProtect.tpl +++ b/templates/GroupProtect.tpl @@ -1,7 +1,7 @@ {literal} +{/literal}