3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
37 * This class generates form components for custom data
39 * It delegates the work to lower level subclasses and integrates the changes
40 * back in. It also uses a lot of functionality with the CRM API's, so any change
41 * made here could potentially affect the API etc. Be careful, be aware, use unit tests.
44 class CRM_Case_Form_CustomData
extends CRM_Core_Form
{
47 * The entity id, used when editing/creating custom data
54 * The custom data type
61 * entity sub type of the table id
66 protected $_subTypeID;
69 * pre processing work done here.
71 * gets session variables for table name, id of entity in table, type of entity and stores them.
80 function preProcess() {
81 $this->_groupID
= CRM_Utils_Request
::retrieve('groupID', 'Positive', $this, TRUE);
82 $this->_entityID
= CRM_Utils_Request
::retrieve('entityID', 'Positive', $this, TRUE);
83 $this->_subTypeID
= CRM_Utils_Request
::retrieve('subType', 'Positive', $this, TRUE);
84 $this->_contactID
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this, TRUE);
86 $groupTree = &CRM_Core_BAO_CustomGroup
::getTree('Case',
92 // simplified formatted groupTree
93 $groupTree = CRM_Core_BAO_CustomGroup
::formatGroupTree($groupTree, 1, $this);
94 foreach ($groupTree as $groupValues) {
95 $this->_customTitle
= $groupValues['title'];
98 $this->_defaults
= array();
99 CRM_Core_BAO_CustomGroup
::setDefaults($groupTree, $this->_defaults
);
100 $this->setDefaults($this->_defaults
);
102 CRM_Core_BAO_CustomGroup
::buildQuickForm($this, $groupTree);
104 //need to assign custom data type and subtype to the template
105 $this->assign('entityID', $this->_entityID
);
106 $this->assign('groupID', $this->_groupID
);
107 $this->assign('subType', $this->_subTypeID
);
108 $this->assign('contactID', $this->_contactID
);
112 * Function to actually build the form
117 public function buildQuickForm() {
118 // make this form an upload since we dont know if the custom data injected dynamically
119 // is of type file etc
120 $this->addButtons(array(
123 'name' => ts('Save'),
128 'name' => ts('Cancel'),
135 * Process the user submitted custom data values.
141 public function postProcess() {
142 $params = $this->controller
->exportValues($this->_name
);
145 $transaction = new CRM_Core_Transaction();
147 CRM_Core_BAO_CustomValueTable
::postProcess($params,
154 $session = CRM_Core_Session
::singleton();
155 $session->pushUserContext(CRM_Utils_System
::url('civicrm/contact/view/case', "reset=1&id={$this->_entityID}&cid={$this->_contactID}&action=view"));
157 $session = CRM_Core_Session
::singleton();
158 $activityTypeID = CRM_Core_OptionGroup
::getValue('activity_type', 'Change Custom Data', 'name');
159 $activityParams = array(
160 'activity_type_id' => $activityTypeID,
161 'source_contact_id' => $session->get('userID'),
163 'subject' => $this->_customTitle
. " : change data",
164 'status_id' => CRM_Core_OptionGroup
::getValue('activity_status',
168 'target_contact_id' => $this->_contactID
,
169 'details' => json_encode($this->_defaults
),
170 'activity_date_time' => date('YmdHis'),
172 $activity = CRM_Activity_BAO_Activity
::create($activityParams);
175 'activity_id' => $activity->id
,
176 'case_id' => $this->_entityID
,
178 CRM_Case_BAO_Case
::processCaseActivity($caseParams);
180 $transaction->commit();