3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
21 * This class generates form components generic to note
23 * It delegates the work to lower level subclasses and integrates the changes
24 * back in. It also uses a lot of functionality with the CRM API's, so any change
25 * made here could potentially affect the API etc. Be careful, be aware, use unit tests.
28 class CRM_Note_Form_Note
extends CRM_Core_Form
{
31 * The table name, used when editing/creating a note
35 protected $_entityTable;
38 * The table id, used when editing/creating a note
45 * The note id, used when editing the note
52 * The parent note id, used when adding a comment to a note
58 public function preProcess() {
59 $this->_entityTable
= $this->get('entityTable');
60 $this->_entityId
= $this->get('entityId');
61 $this->_id
= $this->get('id');
62 $this->_parentId
= CRM_Utils_Array
::value('parentId', $_GET, 0);
63 if ($this->_parentId
) {
64 $this->assign('parentId', $this->_parentId
);
67 if ($this->_id
&& CRM_Core_BAO_Note
::getNotePrivacyHidden($this->_id
)) {
68 CRM_Core_Error
::statusBounce(ts('You do not have access to this note.'));
70 $this->setPageTitle($this->_parentId ?
ts('Comment') : ts('Note'));
74 * Set default values for the form. Note that in edit/view mode
75 * the default values are retrieved from the database
80 public function setDefaultValues() {
83 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
84 if (isset($this->_id
)) {
85 $params['id'] = $this->_id
;
86 CRM_Core_DAO
::commonRetrieve('CRM_Core_DAO_Note', $params, $defaults);
88 if ($defaults['entity_table'] == 'civicrm_note') {
89 $defaults['parent_id'] = $defaults['entity_id'];
92 elseif ($this->_action
& CRM_Core_Action
::ADD
&& $this->_parentId
) {
93 $defaults['parent_id'] = $this->_parentId
;
94 $defaults['subject'] = 'Re: ' . CRM_Core_BAO_Note
::getNoteSubject($this->_parentId
);
100 * Explicitly declare the entity api name.
102 public function getDefaultEntity() {
107 * Explicitly declare the form context.
109 public function getDefaultContext() {
114 * Build the form object.
118 public function buildQuickForm() {
119 if ($this->_action
& CRM_Core_Action
::DELETE
) {
123 'name' => ts('Delete'),
128 'name' => ts('Cancel'),
134 $this->addField('subject');
135 $this->addField('note', [], TRUE);
136 $this->addField('privacy');
137 $this->add('hidden', 'parent_id');
139 // add attachments part
140 CRM_Core_BAO_File
::buildAttachment($this, 'civicrm_note', $this->_id
, NULL, TRUE);
145 'name' => ts('Save'),
150 'name' => ts('Cancel'),
160 public function postProcess() {
161 // store the submitted values in an array
162 $params = $this->controller
->exportValues($this->_name
);
164 $session = CRM_Core_Session
::singleton();
165 $params['contact_id'] = $session->get('userID');
167 if ($params['parent_id']) {
168 $params['entity_table'] = 'civicrm_note';
169 $params['entity_id'] = $params['parent_id'];
172 $params['entity_table'] = $this->_entityTable
;
173 $params['entity_id'] = $this->_entityId
;
176 if ($this->_action
& CRM_Core_Action
::DELETE
) {
177 CRM_Core_BAO_Note
::del($this->_id
);
181 $params['id'] = NULL;
182 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
183 $params['id'] = $this->_id
;
186 // add attachments as needed
187 CRM_Core_BAO_File
::formatAttachment($params, $params, 'civicrm_note', $params['id']);
190 $note = CRM_Core_BAO_Note
::add($params, $ids);
192 CRM_Core_Session
::setStatus(ts('Your Note has been saved.'), ts('Saved'), 'success');