Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | */ |
17 | ||
18 | /** | |
5a409b50 | 19 | * Parent class for inline contact forms. |
6a488035 TO |
20 | */ |
21 | abstract class CRM_Contact_Form_Inline extends CRM_Core_Form { | |
22 | ||
23 | /** | |
24 | * Id of the contact that is being edited | |
69078420 | 25 | * @var int |
6a488035 TO |
26 | */ |
27 | public $_contactId; | |
28 | ||
29 | /** | |
30 | * Type of contact being edited | |
69078420 | 31 | * @var string |
6a488035 TO |
32 | */ |
33 | public $_contactType; | |
34 | ||
35 | /** | |
36 | * Sub type of contact being edited | |
69078420 | 37 | * @var string |
6a488035 TO |
38 | */ |
39 | public $_contactSubType; | |
40 | ||
b4b53245 TM |
41 | /** |
42 | * Explicitly declare the form context. | |
43 | */ | |
44 | public function getDefaultContext() { | |
45 | return 'create'; | |
46 | } | |
47 | ||
48 | /** | |
49 | * Explicitly declare the entity api name. | |
50 | */ | |
51 | public function getDefaultEntity() { | |
52 | return 'Contact'; | |
53 | } | |
54 | ||
6a488035 TO |
55 | /** |
56 | * Common preprocess: fetch contact ID and contact type | |
57 | */ | |
58 | public function preProcess() { | |
1be22cfb | 59 | $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE); |
6a488035 TO |
60 | $this->assign('contactId', $this->_contactId); |
61 | ||
62 | // get contact type and subtype | |
63 | if (empty($this->_contactType)) { | |
64 | $contactTypeInfo = CRM_Contact_BAO_Contact::getContactTypes($this->_contactId); | |
65 | $this->_contactType = $contactTypeInfo[0]; | |
66 | ||
67 | // check if subtype is set | |
68 | if (isset($contactTypeInfo[1])) { | |
69 | // unset contact type which is 0th element | |
70 | unset($contactTypeInfo[0]); | |
71 | $this->_contactSubType = $contactTypeInfo; | |
72 | } | |
73 | } | |
74 | ||
75 | $this->assign('contactType', $this->_contactType); | |
84276082 CW |
76 | |
77 | $this->setAction(CRM_Core_Action::UPDATE); | |
6a488035 TO |
78 | } |
79 | ||
80 | /** | |
fe482240 | 81 | * Common form elements. |
6a488035 TO |
82 | */ |
83 | public function buildQuickForm() { | |
84 | CRM_Contact_Form_Inline_Lock::buildQuickForm($this, $this->_contactId); | |
85 | ||
be2fb01f CW |
86 | $buttons = [ |
87 | [ | |
6a488035 TO |
88 | 'type' => 'upload', |
89 | 'name' => ts('Save'), | |
90 | 'isDefault' => TRUE, | |
be2fb01f CW |
91 | ], |
92 | [ | |
6a488035 TO |
93 | 'type' => 'cancel', |
94 | 'name' => ts('Cancel'), | |
be2fb01f CW |
95 | ], |
96 | ]; | |
6a488035 TO |
97 | $this->addButtons($buttons); |
98 | } | |
99 | ||
100 | /** | |
fe482240 | 101 | * Override default cancel action. |
6a488035 TO |
102 | */ |
103 | public function cancelAction() { | |
be2fb01f | 104 | $response = ['status' => 'cancel']; |
ecdef330 | 105 | CRM_Utils_JSON::output($response); |
6a488035 TO |
106 | } |
107 | ||
108 | /** | |
fe482240 | 109 | * Set defaults for the form. |
6a488035 TO |
110 | * |
111 | * @return array | |
6a488035 TO |
112 | */ |
113 | public function setDefaultValues() { | |
be2fb01f | 114 | $defaults = $params = []; |
6a488035 TO |
115 | $params['id'] = $this->_contactId; |
116 | ||
117 | CRM_Contact_BAO_Contact::getValues($params, $defaults); | |
118 | ||
119 | return $defaults; | |
120 | } | |
121 | ||
122 | /** | |
fe482240 | 123 | * Add entry to log table. |
6a488035 TO |
124 | */ |
125 | protected function log() { | |
126 | CRM_Core_BAO_Log::register($this->_contactId, | |
127 | 'civicrm_contact', | |
128 | $this->_contactId | |
129 | ); | |
130 | } | |
131 | ||
132 | /** | |
fe482240 | 133 | * Common function for all inline contact edit forms. |
6a488035 | 134 | * |
5a409b50 | 135 | * Prepares ajaxResponse |
6a488035 | 136 | */ |
03a7ec8f | 137 | protected function response() { |
b4efde7a CW |
138 | $this->ajaxResponse = array_merge( |
139 | self::renderFooter($this->_contactId), | |
140 | $this->ajaxResponse, | |
141 | CRM_Contact_Form_Inline_Lock::getResponse($this->_contactId) | |
142 | ); | |
143 | // Note: Post hooks will be called by CRM_Core_Form::mainProcess | |
144 | } | |
145 | ||
146 | /** | |
fe482240 EM |
147 | * Render change log footer markup for a contact and supply count. |
148 | * | |
b4efde7a CW |
149 | * Needed for refreshing the contact summary screen |
150 | * | |
151 | * @param int $cid | |
152 | * @param bool $includeCount | |
153 | * @return array | |
154 | */ | |
fe482240 EM |
155 | public static function renderFooter($cid, $includeCount = TRUE) { |
156 | // Load change log footer from template. | |
6a488035 | 157 | $smarty = CRM_Core_Smarty::singleton(); |
b4efde7a CW |
158 | $smarty->assign('contactId', $cid); |
159 | $smarty->assign('external_identifier', CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $cid, 'external_identifier')); | |
160 | $smarty->assign('lastModified', CRM_Core_BAO_Log::lastModified($cid, 'civicrm_contact')); | |
6a488035 TO |
161 | $viewOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, |
162 | 'contact_view_options', TRUE | |
163 | ); | |
164 | $smarty->assign('changeLog', $viewOptions['log']); | |
be2fb01f | 165 | $ret = ['markup' => $smarty->fetch('CRM/common/contactFooter.tpl')]; |
b4efde7a CW |
166 | if ($includeCount) { |
167 | $ret['count'] = CRM_Contact_BAO_Contact::getCountComponent('log', $cid); | |
168 | } | |
be2fb01f | 169 | return ['changeLog' => $ret]; |
6a488035 | 170 | } |
96025800 | 171 | |
6a488035 | 172 | } |