Skip to content

Commit

Permalink
extension now 4.6 and 4.7 compliant
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikHommel committed Oct 28, 2016
1 parent 316b7c4 commit 768a209
Show file tree
Hide file tree
Showing 10 changed files with 345 additions and 18 deletions.
51 changes: 49 additions & 2 deletions CRM/Groupprotect/BAO/GroupProtect.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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':
Expand All @@ -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;
}
}
Expand Down
Empty file modified CRM/Groupprotect/CiviRulesActions/Add.php
100644 → 100755
Empty file.
Empty file modified CRM/Groupprotect/CiviRulesActions/Remove.php
100644 → 100755
Empty file.
Empty file modified CRM/Groupprotect/CiviRulesActions/actions.mgd.php
100644 → 100755
Empty file.
17 changes: 17 additions & 0 deletions groupprotect.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
10 changes: 3 additions & 7 deletions info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,12 @@
<url desc="Support">http://www.civicoop.org</url>
<url desc="Licensing">http://www.gnu.org/licenses/agpl-3.0.html</url>
</urls>
<<<<<<< HEAD
<releaseDate>2016-01-12</releaseDate>
<version>2.0</version>
=======
<releaseDate>2016-10-19</releaseDate>
<version>1.2</version>
>>>>>>> c02caaaa8511581cf03c63e5dd25035805d62cb8
<releaseDate>2016-10-28</releaseDate>
<version>2.2</version>
<develStage>beta</develStage>
<compatibility>
<ver>4.6</ver>
<ver>4.7</ver>
</compatibility>
<comments>Extension is being tested</comments>
<civix>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@
</tr>
</thead>
{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}
<tr id="group_contact-{$row.id}" class="crm-entity {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.group_id`"}">
Expand All @@ -62,14 +69,7 @@
<td>{ts 1=$row.in_method}Added (by %1){/ts}</td>
<td>{$row.in_date|crmDate}</td>
<td>
{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}
<a class="action-item crm-hover-button" href="#Removed" title={ts 1=$displayName 2=$row.title}Remove %1 from %2? (status in this group will be changed to 'Removed').{/ts}">
{ts}Remove{/ts}</a>
<a class="action-item crm-hover-button" href="#Deleted" title="{ts 1=$displayName 2=$row.title}Delete %1 from %2? (remove contact AND delete their record of having been in this group).{/ts}">
Expand Down Expand Up @@ -175,6 +175,7 @@
{assign var='actionItemsAllowed' value=0}
{/if}
{/foreach}
<td>
{if $permission EQ 'edit' AND $actionItemsAllowed}
<a class="action-item crm-hover-button" href="#Added" title="{ts 1=$displayName 2=$row.title}Add %1 back into %2?{/ts}">
{ts}Rejoin Group{/ts}</a>
Expand Down
Loading

0 comments on commit 768a209

Please sign in to comment.