Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
06b69b18 | 4 | | CiviCRM version 4.5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
06b69b18 | 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * This class generates form components for custom data | |
38 | * | |
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. | |
42 | * | |
43 | */ | |
44 | class CRM_Case_Form_CustomData extends CRM_Core_Form { | |
45 | ||
46 | /** | |
47 | * The entity id, used when editing/creating custom data | |
48 | * | |
49 | * @var int | |
50 | */ | |
51 | protected $_entityID; | |
52 | ||
53 | /** | |
54 | * The custom data type | |
55 | * | |
56 | * @var int | |
57 | */ | |
58 | protected $_cdType; | |
59 | ||
60 | /** | |
61 | * entity sub type of the table id | |
62 | * | |
63 | * @var string | |
64 | * @access protected | |
65 | */ | |
66 | protected $_subTypeID; | |
67 | ||
68 | /** | |
69 | * pre processing work done here. | |
70 | * | |
71 | * gets session variables for table name, id of entity in table, type of entity and stores them. | |
72 | * | |
73 | * @param | |
74 | * | |
75 | * @return void | |
76 | * | |
77 | * @access public | |
78 | * | |
79 | */ | |
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); | |
85 | ||
86 | $groupTree = &CRM_Core_BAO_CustomGroup::getTree('Case', | |
87 | $this, | |
88 | $this->_entityID, | |
89 | $this->_groupID, | |
90 | $this->_subTypeID | |
91 | ); | |
92 | // simplified formatted groupTree | |
93 | $groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, $this); | |
e08129f7 | 94 | // Array contains only one item |
6a488035 TO |
95 | foreach ($groupTree as $groupValues) { |
96 | $this->_customTitle = $groupValues['title']; | |
e08129f7 | 97 | CRM_Utils_System::setTitle(ts('Edit %1', array(1 => $groupValues['title']))); |
6a488035 TO |
98 | } |
99 | ||
100 | $this->_defaults = array(); | |
101 | CRM_Core_BAO_CustomGroup::setDefaults($groupTree, $this->_defaults); | |
102 | $this->setDefaults($this->_defaults); | |
103 | ||
7b226831 | 104 | CRM_Core_BAO_CustomGroup::buildQuickForm($this, $groupTree); |
6a488035 TO |
105 | |
106 | //need to assign custom data type and subtype to the template | |
107 | $this->assign('entityID', $this->_entityID); | |
108 | $this->assign('groupID', $this->_groupID); | |
109 | $this->assign('subType', $this->_subTypeID); | |
110 | $this->assign('contactID', $this->_contactID); | |
111 | } | |
112 | ||
113 | /** | |
114 | * Function to actually build the form | |
115 | * | |
116 | * @return void | |
117 | * @access public | |
118 | */ | |
119 | public function buildQuickForm() { | |
120 | // make this form an upload since we dont know if the custom data injected dynamically | |
121 | // is of type file etc | |
122 | $this->addButtons(array( | |
123 | array( | |
124 | 'type' => 'upload', | |
125 | 'name' => ts('Save'), | |
126 | 'isDefault' => TRUE, | |
127 | ), | |
128 | array( | |
129 | 'type' => 'cancel', | |
130 | 'name' => ts('Cancel'), | |
131 | ), | |
132 | ) | |
133 | ); | |
134 | } | |
135 | ||
136 | /** | |
137 | * Process the user submitted custom data values. | |
138 | * | |
139 | * @access public | |
140 | * | |
141 | * @return void | |
142 | */ | |
143 | public function postProcess() { | |
144 | $params = $this->controller->exportValues($this->_name); | |
145 | $fields = array(); | |
146 | ||
147 | $transaction = new CRM_Core_Transaction(); | |
148 | ||
149 | CRM_Core_BAO_CustomValueTable::postProcess($params, | |
150 | $fields, | |
151 | 'civicrm_case', | |
152 | $this->_entityID, | |
153 | 'Case' | |
154 | ); | |
155 | ||
156 | $session = CRM_Core_Session::singleton(); | |
157 | $session->pushUserContext(CRM_Utils_System::url('civicrm/contact/view/case', "reset=1&id={$this->_entityID}&cid={$this->_contactID}&action=view")); | |
158 | ||
159 | $session = CRM_Core_Session::singleton(); | |
160 | $activityTypeID = CRM_Core_OptionGroup::getValue('activity_type', 'Change Custom Data', 'name'); | |
161 | $activityParams = array( | |
162 | 'activity_type_id' => $activityTypeID, | |
163 | 'source_contact_id' => $session->get('userID'), | |
164 | 'is_auto' => TRUE, | |
165 | 'subject' => $this->_customTitle . " : change data", | |
166 | 'status_id' => CRM_Core_OptionGroup::getValue('activity_status', | |
167 | 'Completed', | |
168 | 'name' | |
169 | ), | |
170 | 'target_contact_id' => $this->_contactID, | |
171 | 'details' => json_encode($this->_defaults), | |
172 | 'activity_date_time' => date('YmdHis'), | |
173 | ); | |
174 | $activity = CRM_Activity_BAO_Activity::create($activityParams); | |
175 | ||
176 | $caseParams = array( | |
177 | 'activity_id' => $activity->id, | |
178 | 'case_id' => $this->_entityID, | |
179 | ); | |
180 | CRM_Case_BAO_Case::processCaseActivity($caseParams); | |
181 | ||
182 | $transaction->commit(); | |
183 | } | |
184 | } | |
185 |