From bf076628ddbcd7f0c511e3023c400ba5987656a7 Mon Sep 17 00:00:00 2001 From: Pratik Joshi Date: Fri, 28 Mar 2014 21:06:10 +0530 Subject: [PATCH] CRM-14327 : added save and new button --- CRM/Contact/Form/CustomData.php | 20 +++++++++++++++++++- CRM/Core/BAO/CustomGroup.php | 5 ++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/CRM/Contact/Form/CustomData.php b/CRM/Contact/Form/CustomData.php index 2ce48819c4..f2f49e5360 100644 --- a/CRM/Contact/Form/CustomData.php +++ b/CRM/Contact/Form/CustomData.php @@ -131,6 +131,12 @@ class CRM_Contact_Form_CustomData extends CRM_Core_Form { if ($this->_multiRecordDisplay) { $this->_groupID = CRM_Utils_Request::retrieve('groupID', 'Positive', $this); $this->_tableID = $this->_entityId; + $this->_contactType = CRM_Contact_BAO_Contact::getContactType($this->_tableID); + $mode = CRM_Utils_Request::retrieve('mode', 'String', $this); + $hasReachedMax = CRM_Core_BAO_CustomGroup::hasReachedMaxLimit($this->_groupID, $this->_tableID); + if ($hasReachedMax && $mode == 'add') { + CRM_Core_Error::statusBounce(ts('The maximum record limit is reached')); + } $this->_copyValueId = CRM_Utils_Request::retrieve('copyValueId', 'Positive', $this); $groupTitle = CRM_Core_BAO_CustomGroup::getTitle($this->_groupID); @@ -187,6 +193,11 @@ class CRM_Contact_Form_CustomData extends CRM_Core_Form { 'name' => ts('%1', array(1 => $saveButtonName)), 'isDefault' => TRUE, ), + array( + 'type' => 'upload', + 'name' => ts('Save and New'), + 'subName' => 'new', + ), array( 'type' => 'cancel', 'name' => ts('Cancel'), @@ -286,13 +297,20 @@ class CRM_Contact_Form_CustomData extends CRM_Core_Form { public function postProcess() { // Get the form values and groupTree $params = $this->controller->exportValues($this->_name); + CRM_Core_BAO_CustomValueTable::postProcess($params, $this->_groupTree[$this->_groupID]['fields'], 'civicrm_contact', $this->_tableID, $this->_entityType ); - + $table = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_groupID, 'table_name'); + $cgcount = CRM_Core_BAO_CustomGroup::customGroupDataExistsForEntity($this->_tableID, $table, TRUE); + $cgcount += 1; + $buttonName = $this->controller->getButtonName(); + if ($buttonName == $this->getButtonName('upload', 'new')) { + CRM_Core_Session::singleton()->pushUserContext(CRM_Utils_System::url('civicrm/contact/view/cd/edit', "reset=1&type={$this->_contactType}&groupID={$this->_groupID}&entityID={$this->_tableID}&cgcount={$cgcount}&multiRecordDisplay=single&mode=add")); + } // reset the group contact cache for this group CRM_Contact_BAO_GroupContactCache::remove(); } diff --git a/CRM/Core/BAO/CustomGroup.php b/CRM/Core/BAO/CustomGroup.php index 306538c3e0..94d277c6c6 100644 --- a/CRM/Core/BAO/CustomGroup.php +++ b/CRM/Core/BAO/CustomGroup.php @@ -614,13 +614,16 @@ ORDER BY civicrm_custom_group.weight, * * @return boolean does this entity have data in this custom table */ - static public function customGroupDataExistsForEntity($entityID, $table){ + static public function customGroupDataExistsForEntity($entityID, $table, $getCount = FALSE){ $query = " SELECT count(id) FROM $table WHERE entity_id = $entityID "; $recordExists = CRM_Core_DAO::singleValueQuery($query); + if ($getCount) { + return $recordExists; + } return $recordExists ? TRUE : FALSE; } -- 2.25.1