_groupID = CRM_Utils_Request::retrieve('groupID', 'Positive', $this, TRUE); $this->_entityID = CRM_Utils_Request::retrieve('entityID', 'Positive', $this, TRUE); $this->_subTypeID = CRM_Utils_Request::retrieve('subType', 'Positive', $this, TRUE); $this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE); $groupTree = CRM_Core_BAO_CustomGroup::getTree('Case', $this, $this->_entityID, $this->_groupID, $this->_subTypeID ); // simplified formatted groupTree $groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, $this); // Array contains only one item foreach ($groupTree as $groupValues) { $this->_customTitle = $groupValues['title']; CRM_Utils_System::setTitle(ts('Edit %1', array(1 => $groupValues['title']))); } $this->_defaults = array(); CRM_Core_BAO_CustomGroup::setDefaults($groupTree, $this->_defaults); $this->setDefaults($this->_defaults); CRM_Core_BAO_CustomGroup::buildQuickForm($this, $groupTree); //need to assign custom data type and subtype to the template $this->assign('entityID', $this->_entityID); $this->assign('groupID', $this->_groupID); $this->assign('subType', $this->_subTypeID); $this->assign('contactID', $this->_contactID); } /** * Build the form object. * * @return void */ public function buildQuickForm() { // make this form an upload since we dont know if the custom data injected dynamically // is of type file etc $this->addButtons(array( array( 'type' => 'upload', 'name' => ts('Save'), 'isDefault' => TRUE, ), array( 'type' => 'cancel', 'name' => ts('Cancel'), ), ) ); } /** * Process the user submitted custom data values. * * * @return void */ public function postProcess() { $params = $this->controller->exportValues($this->_name); $fields = array(); $transaction = new CRM_Core_Transaction(); CRM_Core_BAO_CustomValueTable::postProcess($params, $fields, 'civicrm_case', $this->_entityID, 'Case' ); $session = CRM_Core_Session::singleton(); $session->pushUserContext(CRM_Utils_System::url('civicrm/contact/view/case', "reset=1&id={$this->_entityID}&cid={$this->_contactID}&action=view")); $session = CRM_Core_Session::singleton(); $activityTypeID = CRM_Core_OptionGroup::getValue('activity_type', 'Change Custom Data', 'name'); $activityParams = array( 'activity_type_id' => $activityTypeID, 'source_contact_id' => $session->get('userID'), 'is_auto' => TRUE, 'subject' => $this->_customTitle . " : change data", 'status_id' => CRM_Core_OptionGroup::getValue('activity_status', 'Completed', 'name' ), 'target_contact_id' => $this->_contactID, 'details' => json_encode($this->_defaults), 'activity_date_time' => date('YmdHis'), ); $activity = CRM_Activity_BAO_Activity::create($activityParams); $caseParams = array( 'activity_id' => $activity->id, 'case_id' => $this->_entityID, ); CRM_Case_BAO_Case::processCaseActivity($caseParams); $transaction->commit(); } }