3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2018
35 * This class generates form components for custom data
37 * It delegates the work to lower level subclasses and integrates the changes
38 * back in. It also uses a lot of functionality with the CRM API's, so any change
39 * made here could potentially affect the API etc. Be careful, be aware, use unit tests.
41 class CRM_Case_Form_CustomData
extends CRM_Core_Form
{
44 * The entity id, used when editing/creating custom data
51 * Entity sub type of the table id.
55 protected $_subTypeID;
58 * Pre processing work done here.
60 * gets session variables for table name, id of entity in table, type of entity and stores them.
62 public function preProcess() {
63 $this->_groupID
= CRM_Utils_Request
::retrieve('groupID', 'Positive', $this, TRUE);
64 $this->_entityID
= CRM_Utils_Request
::retrieve('entityID', 'Positive', $this, TRUE);
65 $this->_subTypeID
= CRM_Utils_Request
::retrieve('subType', 'Positive', $this, TRUE);
66 $this->_contactID
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this, TRUE);
68 $groupTree = CRM_Core_BAO_CustomGroup
::getTree('Case',
74 // simplified formatted groupTree
75 $groupTree = CRM_Core_BAO_CustomGroup
::formatGroupTree($groupTree, 1, $this);
76 // Array contains only one item
77 foreach ($groupTree as $groupValues) {
78 $this->_customTitle
= $groupValues['title'];
79 CRM_Utils_System
::setTitle(ts('Edit %1', array(1 => $groupValues['title'])));
82 $this->_defaults
= array();
83 CRM_Core_BAO_CustomGroup
::setDefaults($groupTree, $this->_defaults
);
84 $this->setDefaults($this->_defaults
);
86 CRM_Core_BAO_CustomGroup
::buildQuickForm($this, $groupTree);
88 //need to assign custom data type and subtype to the template
89 $this->assign('entityID', $this->_entityID
);
90 $this->assign('groupID', $this->_groupID
);
91 $this->assign('subType', $this->_subTypeID
);
92 $this->assign('contactID', $this->_contactID
);
96 * Build the form object.
98 public function buildQuickForm() {
99 // make this form an upload since we dont know if the custom data injected dynamically
100 // is of type file etc
101 $this->addButtons(array(
104 'name' => ts('Save'),
109 'name' => ts('Cancel'),
116 * Process the user submitted custom data values.
118 public function postProcess() {
119 $params = $this->controller
->exportValues($this->_name
);
121 $transaction = new CRM_Core_Transaction();
123 CRM_Core_BAO_CustomValueTable
::postProcess($params,
129 $session = CRM_Core_Session
::singleton();
130 $session->pushUserContext(CRM_Utils_System
::url('civicrm/contact/view/case', "reset=1&id={$this->_entityID}&cid={$this->_contactID}&action=view"));
132 $session = CRM_Core_Session
::singleton();
133 $activityTypeID = CRM_Core_PseudoConstant
::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Change Custom Data');
134 $activityParams = array(
135 'activity_type_id' => $activityTypeID,
136 'source_contact_id' => $session->get('userID'),
138 'subject' => $this->_customTitle
. " : change data",
139 'status_id' => CRM_Core_PseudoConstant
::getKey('CRM_Activity_BAO_Activity', 'activity_status_id', 'Completed'),
140 'target_contact_id' => $this->_contactID
,
141 'details' => json_encode($this->_defaults
),
142 'activity_date_time' => date('YmdHis'),
144 $activity = CRM_Activity_BAO_Activity
::create($activityParams);
147 'activity_id' => $activity->id
,
148 'case_id' => $this->_entityID
,
150 CRM_Case_BAO_Case
::processCaseActivity($caseParams);
152 $transaction->commit();