Skip to content
Snippets Groups Projects
Commit bf076628 authored by pratik.joshi's avatar pratik.joshi
Browse files

CRM-14327 : added save and new button

parent 7ab9bfe8
No related branches found
No related tags found
No related merge requests found
...@@ -131,6 +131,12 @@ class CRM_Contact_Form_CustomData extends CRM_Core_Form { ...@@ -131,6 +131,12 @@ class CRM_Contact_Form_CustomData extends CRM_Core_Form {
if ($this->_multiRecordDisplay) { if ($this->_multiRecordDisplay) {
$this->_groupID = CRM_Utils_Request::retrieve('groupID', 'Positive', $this); $this->_groupID = CRM_Utils_Request::retrieve('groupID', 'Positive', $this);
$this->_tableID = $this->_entityId; $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); $this->_copyValueId = CRM_Utils_Request::retrieve('copyValueId', 'Positive', $this);
$groupTitle = CRM_Core_BAO_CustomGroup::getTitle($this->_groupID); $groupTitle = CRM_Core_BAO_CustomGroup::getTitle($this->_groupID);
...@@ -187,6 +193,11 @@ class CRM_Contact_Form_CustomData extends CRM_Core_Form { ...@@ -187,6 +193,11 @@ class CRM_Contact_Form_CustomData extends CRM_Core_Form {
'name' => ts('%1', array(1 => $saveButtonName)), 'name' => ts('%1', array(1 => $saveButtonName)),
'isDefault' => TRUE, 'isDefault' => TRUE,
), ),
array(
'type' => 'upload',
'name' => ts('Save and New'),
'subName' => 'new',
),
array( array(
'type' => 'cancel', 'type' => 'cancel',
'name' => ts('Cancel'), 'name' => ts('Cancel'),
...@@ -286,13 +297,20 @@ class CRM_Contact_Form_CustomData extends CRM_Core_Form { ...@@ -286,13 +297,20 @@ class CRM_Contact_Form_CustomData extends CRM_Core_Form {
public function postProcess() { public function postProcess() {
// Get the form values and groupTree // Get the form values and groupTree
$params = $this->controller->exportValues($this->_name); $params = $this->controller->exportValues($this->_name);
CRM_Core_BAO_CustomValueTable::postProcess($params, CRM_Core_BAO_CustomValueTable::postProcess($params,
$this->_groupTree[$this->_groupID]['fields'], $this->_groupTree[$this->_groupID]['fields'],
'civicrm_contact', 'civicrm_contact',
$this->_tableID, $this->_tableID,
$this->_entityType $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 // reset the group contact cache for this group
CRM_Contact_BAO_GroupContactCache::remove(); CRM_Contact_BAO_GroupContactCache::remove();
} }
......
...@@ -614,13 +614,16 @@ ORDER BY civicrm_custom_group.weight, ...@@ -614,13 +614,16 @@ ORDER BY civicrm_custom_group.weight,
* *
* @return boolean does this entity have data in this custom table * @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 = " $query = "
SELECT count(id) SELECT count(id)
FROM $table FROM $table
WHERE entity_id = $entityID WHERE entity_id = $entityID
"; ";
$recordExists = CRM_Core_DAO::singleValueQuery($query); $recordExists = CRM_Core_DAO::singleValueQuery($query);
if ($getCount) {
return $recordExists;
}
return $recordExists ? TRUE : FALSE; return $recordExists ? TRUE : FALSE;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment