From 3d700d009f9505b7d97be55497b6ab928f6e4c60 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Mon, 30 Dec 2013 20:31:00 -0800 Subject: [PATCH] CRM-13863 - Ajaxify contact groups tab --- CRM/Contact/Form/GroupContact.php | 1 - api/v3/GroupContact.php | 29 +++-- .../CRM/Contact/Page/View/GroupContact.tpl | 108 ++++++++++-------- tests/phpunit/api/v3/GroupContactTest.php | 16 ++- 4 files changed, 88 insertions(+), 66 deletions(-) diff --git a/CRM/Contact/Form/GroupContact.php b/CRM/Contact/Form/GroupContact.php index c33ce3c819..df4a795612 100644 --- a/CRM/Contact/Form/GroupContact.php +++ b/CRM/Contact/Form/GroupContact.php @@ -124,7 +124,6 @@ class CRM_Contact_Form_GroupContact extends CRM_Core_Form { public function postProcess() { $contactID = array($this->_contactId); $groupId = $this->controller->exportValue('GroupContact', 'group_id'); - $method = 'Admin'; $method = ($this->_context == 'user') ? 'Web' : 'Admin'; $session = CRM_Core_Session::singleton(); diff --git a/api/v3/GroupContact.php b/api/v3/GroupContact.php index 85bfa54941..4b40cff003 100644 --- a/api/v3/GroupContact.php +++ b/api/v3/GroupContact.php @@ -58,7 +58,7 @@ function civicrm_api3_group_contact_get($params) { $params['status'] = 'Added'; } //ie. id passed in so we have to return something - return _civicrm_api3_basic_get('CRM_Contact_BAO_GroupContact', $params); + return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); } $status = CRM_Utils_Array::value('status', $params, 'Added'); @@ -104,22 +104,20 @@ function civicrm_api3_group_contact_get($params) { * {@getfields GroupContact_create} */ function civicrm_api3_group_contact_create($params) { - + // Nonstandard bao - doesn't accept ID as a param, so convert id to group_id + contact_id + if (!empty($params['id'])) { + $getParams = array('id' => $params['id']); + $info = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $getParams); + if (!empty($info['values'][$params['id']])) { + $params['group_id'] = $info['values'][$params['id']]['group_id']; + $params['contact_id'] = $info['values'][$params['id']]['contact_id']; + } + } + civicrm_api3_verify_mandatory($params, NULL, array('group_id', 'contact_id')); $action = CRM_Utils_Array::value('status', $params, 'Added'); return _civicrm_api3_group_contact_common($params, $action); } -/** - * Adjust Metadata for Create action - * - * The metadata is used for setting defaults, documentation & validation - * @param array $params array or parameters determined by getfields - */ -function _civicrm_api3_group_contact_create_spec(&$params) { - $params['group_id']['api.required'] = 1; - $params['contact_id']['api.required'] = 1; -} - /** * * @param $params @@ -128,8 +126,9 @@ function _civicrm_api3_group_contact_create_spec(&$params) { * @deprecated */ function civicrm_api3_group_contact_delete($params) { - $params['status'] = 'Removed'; - return civicrm_api('GroupContact', 'Create', $params); + $params['status'] = CRM_Utils_Array::value('status', $params, empty($params['skip_undelete']) ? 'Removed' : 'Deleted'); + // "Deleted" isn't a real option so skip the api wrapper to avoid pseudoconstant validation + return civicrm_api3_group_contact_create($params); } /** diff --git a/templates/CRM/Contact/Page/View/GroupContact.tpl b/templates/CRM/Contact/Page/View/GroupContact.tpl index 8302db560a..811f023246 100644 --- a/templates/CRM/Contact/Page/View/GroupContact.tpl +++ b/templates/CRM/Contact/Page/View/GroupContact.tpl @@ -53,7 +53,7 @@ {foreach from=$groupIn item=row} - + {$row.title} @@ -63,16 +63,10 @@ {$row.in_date|crmDate} {if $permission EQ 'edit'} - - [ {ts}Remove{/ts} ] - {/if} - {if $permission EQ 'edit'} - [ {ts}Delete{/ts} - ] + + {ts}Remove{/ts} + + {ts}Delete{/ts} {/if} @@ -82,19 +76,19 @@ {/if} {if $contactSmartGroupSettings neq 3} -
-
-
- {ts}Smart Groups{/ts} -
- -
-
+
+
+
+ {ts}Smart Groups{/ts} +
+ +
+
+
+
- +
- -
{/if} {if $groupPending} @@ -112,7 +106,7 @@ {foreach from=$groupPending item=row} - + {$row.title} @@ -122,16 +116,10 @@ {$row.pending_date|crmDate} {if $permission EQ 'edit'} - - [ {ts}Remove{/ts} ] - {/if} - {if $permission EQ 'edit'} - - [ {ts}Delete{/ts} ] + + {ts}Remove{/ts} + + {ts}Delete{/ts} {/if} @@ -156,7 +144,7 @@ {foreach from=$groupOut item=row} - + {$row.title} @@ -166,14 +154,10 @@ {$row.date_added|crmDate} {$row.out_date|crmDate} {if $permission EQ 'edit'} - - [ {ts}Rejoin Group{/ts} ]{/if} - {if $permission EQ 'edit'} - - [ {ts}Delete{/ts} ]{/if} + + {ts}Rejoin Group{/ts} + + {ts}Delete{/ts}{/if} {/foreach} @@ -185,8 +169,6 @@ {literal} -{/literal} diff --git a/tests/phpunit/api/v3/GroupContactTest.php b/tests/phpunit/api/v3/GroupContactTest.php index 64966bb08e..4ad7ea1218 100644 --- a/tests/phpunit/api/v3/GroupContactTest.php +++ b/tests/phpunit/api/v3/GroupContactTest.php @@ -34,6 +34,7 @@ class api_v3_GroupContactTest extends CiviUnitTestCase { protected $_contactId1; protected $_apiversion = 3; protected $_groupId1; + protected $_groupContactId; function get_info() { return array( @@ -60,6 +61,7 @@ class api_v3_GroupContactTest extends CiviUnitTestCase { ); $result = $this->callAPISuccess('group_contact', 'create', $params); + $this->_groupContactId = $result['id']; $group = array( 'name' => 'Test Group 2', @@ -71,10 +73,6 @@ class api_v3_GroupContactTest extends CiviUnitTestCase { ); $this->_groupId2 = $this->groupCreate($group, 3); - $params = array( - 'contact_id.1' => $this->_contactId, - 'group_id' => $this->_groupId2, - ); $this->_group = array( $this->_groupId1 => array('title' => 'New Test Group Created', @@ -183,5 +181,15 @@ class api_v3_GroupContactTest extends CiviUnitTestCase { $this->assertEquals($result['removed'], 1, "in line " . __LINE__); $this->assertEquals($result['total_count'], 1, "in line " . __LINE__); } + + function testDeletePermanent() { + $params = array( + 'id' => $this->_groupContactId, + 'skip_undelete' => TRUE, + ); + $this->callAPIAndDocument('group_contact', 'delete', $params, __FUNCTION__, __FILE__); + $result = $this->callAPISuccess('group_contact', 'get', $params); + $this->assertEquals(0, $result['count'], "in line " . __LINE__); + } } -- 2.25.1