X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FContact%2FForm%2FCustomData.php;h=f2f49e53605b872d318b5c4ab58c10e012e9713d;hb=57550a570f4f538d3cc40939b678d9122156973c;hp=f7931ef13e3a01088f9af10dd0fa7226a923c365;hpb=73be989745ea968ffa538d5679bce4303bbf5306;p=civicrm-core.git diff --git a/CRM/Contact/Form/CustomData.php b/CRM/Contact/Form/CustomData.php index f7931ef13e..f2f49e5360 100644 --- a/CRM/Contact/Form/CustomData.php +++ b/CRM/Contact/Form/CustomData.php @@ -1,9 +1,9 @@ _cdType = CRM_Utils_Array::value('type', $_GET); - $this->assign('cdType', FALSE); - if ($this->_cdType) { - $this->assign('cdType', TRUE); - return CRM_Custom_Form_CustomData::preProcess($this); - } + $this->_multiRecordDisplay = CRM_Utils_Request::retrieve('multiRecordDisplay', 'String', $this); + if ($this->_cdType || $this->_multiRecordDisplay == 'single') { + if ($this->_cdType) { + $this->assign('cdType', TRUE); + } + // NOTE : group id is not stored in session from within CRM_Custom_Form_CustomData::preProcess func + // this is due to some condition inside it which restricts it from saving in session + // so doing this for multi record edit action + CRM_Custom_Form_CustomData::preProcess($this); + 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); + $mode = CRM_Utils_Request::retrieve('mode', 'String', CRM_Core_DAO::$_nullObject, FALSE, NULL, 'GET'); + $mode = ucfirst($mode); + CRM_Utils_System::setTitle(ts('%1 %2 Record', array(1 => $mode, 2 => $groupTitle))); + + if (!empty($_POST['hidden_custom'])) { + $this->assign('postedInfo', TRUE); + } + } + return; + } $this->_groupID = CRM_Utils_Request::retrieve('groupID', 'Positive', $this, TRUE); $this->_tableID = CRM_Utils_Request::retrieve('tableId', 'Positive', $this, TRUE); @@ -149,7 +177,35 @@ class CRM_Contact_Form_CustomData extends CRM_Core_Form { * @access public */ public function buildQuickForm() { - if ($this->_cdType) { + if ($this->_cdType || $this->_multiRecordDisplay == 'single') { + // buttons display for multi-valued fields to perform independednt actions + if ($this->_multiRecordDisplay) { + $isMultiple = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', + $this->_groupID, + 'is_multiple' + ); + if ($isMultiple) { + $this->assign('multiRecordDisplay', $this->_multiRecordDisplay); + $saveButtonName = $this->_copyValueId ? 'Save a Copy': 'Save'; + $this->addButtons(array( + array( + 'type' => 'upload', + 'name' => ts('%1', array(1 => $saveButtonName)), + 'isDefault' => TRUE, + ), + array( + 'type' => 'upload', + 'name' => ts('Save and New'), + 'subName' => 'new', + ), + array( + 'type' => 'cancel', + 'name' => ts('Cancel'), + ), + ) + ); + } + } return CRM_Custom_Form_CustomData::buildQuickForm($this); } @@ -181,8 +237,29 @@ class CRM_Contact_Form_CustomData extends CRM_Core_Form { * @return array the default array reference */ function setDefaultValues() { - if ($this->_cdType) { - $customDefaultValue = CRM_Custom_Form_CustomData::setDefaultValues($this); + if ($this->_cdType || $this->_multiRecordDisplay == 'single') { + if ($this->_copyValueId) { + // cached tree is fetched + $groupTree = &CRM_Core_BAO_CustomGroup::getTree($this->_type, + $this, + $this->_entityId, + $this->_groupID + ); + $valueIdDefaults = array(); + $groupTreeValueId = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, $this->_copyValueId, $this); + CRM_Core_BAO_CustomGroup::setDefaults($groupTreeValueId, $valueIdDefaults, FALSE, FALSE, $this->get('action')); + $tableId = $groupTreeValueId[$this->_groupID]['table_id']; + foreach ($valueIdDefaults as $valueIdElementName => $value) { + // build defaults for COPY action for new record saving + $valueIdElementNamePieces = explode('_', $valueIdElementName); + $valueIdElementNamePieces[2] = "-{$this->_groupCount}"; + $elementName = implode('_', $valueIdElementNamePieces); + $customDefaultValue[$elementName] = $value; + } + } + else { + $customDefaultValue = CRM_Custom_Form_CustomData::setDefaultValues($this); + } return $customDefaultValue; } @@ -220,15 +297,21 @@ 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(); } -} - +} \ No newline at end of file