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