Clean up docblock
[civicrm-core.git] / CRM / Contact / Form / Inline.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
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
31 * @copyright CiviCRM LLC (c) 2004-2017
32 */
33
34 /**
35 * Parent class for inline contact forms.
36 */
37 abstract class CRM_Contact_Form_Inline extends CRM_Core_Form {
38
39 /**
40 * Id of the contact that is being edited
41 */
42 public $_contactId;
43
44 /**
45 * Type of contact being edited
46 */
47 public $_contactType;
48
49 /**
50 * Sub type of contact being edited
51 */
52 public $_contactSubType;
53
54 /**
55 * Explicitly declare the form context.
56 */
57 public function getDefaultContext() {
58 return 'create';
59 }
60
61 /**
62 * Explicitly declare the entity api name.
63 */
64 public function getDefaultEntity() {
65 return 'Contact';
66 }
67
68 /**
69 * Common preprocess: fetch contact ID and contact type
70 */
71 public function preProcess() {
72 $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE, NULL, $_REQUEST);
73 $this->assign('contactId', $this->_contactId);
74
75 // get contact type and subtype
76 if (empty($this->_contactType)) {
77 $contactTypeInfo = CRM_Contact_BAO_Contact::getContactTypes($this->_contactId);
78 $this->_contactType = $contactTypeInfo[0];
79
80 // check if subtype is set
81 if (isset($contactTypeInfo[1])) {
82 // unset contact type which is 0th element
83 unset($contactTypeInfo[0]);
84 $this->_contactSubType = $contactTypeInfo;
85 }
86 }
87
88 $this->assign('contactType', $this->_contactType);
89
90 $this->setAction(CRM_Core_Action::UPDATE);
91 }
92
93 /**
94 * Common form elements.
95 */
96 public function buildQuickForm() {
97 CRM_Contact_Form_Inline_Lock::buildQuickForm($this, $this->_contactId);
98
99 $buttons = array(
100 array(
101 'type' => 'upload',
102 'name' => ts('Save'),
103 'isDefault' => TRUE,
104 ),
105 array(
106 'type' => 'cancel',
107 'name' => ts('Cancel'),
108 ),
109 );
110 $this->addButtons($buttons);
111 }
112
113 /**
114 * Override default cancel action.
115 */
116 public function cancelAction() {
117 $response = array('status' => 'cancel');
118 CRM_Utils_JSON::output($response);
119 }
120
121 /**
122 * Set defaults for the form.
123 *
124 * @return array
125 */
126 public function setDefaultValues() {
127 $defaults = $params = array();
128 $params['id'] = $this->_contactId;
129
130 CRM_Contact_BAO_Contact::getValues($params, $defaults);
131
132 return $defaults;
133 }
134
135 /**
136 * Add entry to log table.
137 */
138 protected function log() {
139 CRM_Core_BAO_Log::register($this->_contactId,
140 'civicrm_contact',
141 $this->_contactId
142 );
143 }
144
145 /**
146 * Common function for all inline contact edit forms.
147 *
148 * Prepares ajaxResponse
149 */
150 protected function response() {
151 $this->ajaxResponse = array_merge(
152 self::renderFooter($this->_contactId),
153 $this->ajaxResponse,
154 CRM_Contact_Form_Inline_Lock::getResponse($this->_contactId)
155 );
156 // Note: Post hooks will be called by CRM_Core_Form::mainProcess
157 }
158
159 /**
160 * Render change log footer markup for a contact and supply count.
161 *
162 * Needed for refreshing the contact summary screen
163 *
164 * @param int $cid
165 * @param bool $includeCount
166 * @return array
167 */
168 public static function renderFooter($cid, $includeCount = TRUE) {
169 // Load change log footer from template.
170 $smarty = CRM_Core_Smarty::singleton();
171 $smarty->assign('contactId', $cid);
172 $smarty->assign('external_identifier', CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $cid, 'external_identifier'));
173 $smarty->assign('lastModified', CRM_Core_BAO_Log::lastModified($cid, 'civicrm_contact'));
174 $viewOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
175 'contact_view_options', TRUE
176 );
177 $smarty->assign('changeLog', $viewOptions['log']);
178 $ret = array('markup' => $smarty->fetch('CRM/common/contactFooter.tpl'));
179 if ($includeCount) {
180 $ret['count'] = CRM_Contact_BAO_Contact::getCountComponent('log', $cid);
181 }
182 return array('changeLog' => $ret);
183 }
184
185 }