3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
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-2017
35 * Parent class for inline contact forms.
37 abstract class CRM_Contact_Form_Inline
extends CRM_Core_Form
{
40 * Id of the contact that is being edited
45 * Type of contact being edited
50 * Sub type of contact being edited
52 public $_contactSubType;
55 * Explicitly declare the form context.
57 public function getDefaultContext() {
62 * Explicitly declare the entity api name.
64 public function getDefaultEntity() {
69 * Common preprocess: fetch contact ID and contact type
71 public function preProcess() {
72 $this->_contactId
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this, TRUE, NULL, $_REQUEST);
73 $this->assign('contactId', $this->_contactId
);
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];
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;
88 $this->assign('contactType', $this->_contactType
);
90 $this->setAction(CRM_Core_Action
::UPDATE
);
94 * Common form elements.
96 public function buildQuickForm() {
97 CRM_Contact_Form_Inline_Lock
::buildQuickForm($this, $this->_contactId
);
102 'name' => ts('Save'),
107 'name' => ts('Cancel'),
110 $this->addButtons($buttons);
114 * Override default cancel action.
116 public function cancelAction() {
117 $response = array('status' => 'cancel');
118 CRM_Utils_JSON
::output($response);
122 * Set defaults for the form.
126 public function setDefaultValues() {
127 $defaults = $params = array();
128 $params['id'] = $this->_contactId
;
130 CRM_Contact_BAO_Contact
::getValues($params, $defaults);
136 * Add entry to log table.
138 protected function log() {
139 CRM_Core_BAO_Log
::register($this->_contactId
,
146 * Common function for all inline contact edit forms.
148 * Prepares ajaxResponse
150 protected function response() {
151 $this->ajaxResponse
= array_merge(
152 self
::renderFooter($this->_contactId
),
154 CRM_Contact_Form_Inline_Lock
::getResponse($this->_contactId
)
156 // Note: Post hooks will be called by CRM_Core_Form::mainProcess
160 * Render change log footer markup for a contact and supply count.
162 * Needed for refreshing the contact summary screen
165 * @param bool $includeCount
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
177 $smarty->assign('changeLog', $viewOptions['log']);
178 $ret = array('markup' => $smarty->fetch('CRM/common/contactFooter.tpl'));
180 $ret['count'] = CRM_Contact_BAO_Contact
::getCountComponent('log', $cid);
182 return array('changeLog' => $ret);