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
19 * Main page for viewing Notes.
21 class CRM_Contact_Page_View_Note
extends CRM_Core_Page
{
24 * The action links for notes that we need to display for the browse screen
28 public static $_links = NULL;
31 * The action links for comments that we need to display for the browse screen
35 public static $_commentLinks = NULL;
38 * Notes found running the browse function
44 * View details of a note.
46 public function view() {
47 $note = new CRM_Core_DAO_Note();
48 $note->id
= $this->_id
;
49 if ($note->find(TRUE)) {
51 CRM_Core_DAO
::storeValues($note, $this->values
);
52 $this->values
['privacy'] = CRM_Core_PseudoConstant
::getLabel('CRM_Core_BAO_Note', 'privacy', $this->values
['privacy']);
53 $this->assign('note', $this->values
);
56 $comments = CRM_Core_BAO_Note
::getNoteTree($this->values
['id'], 1);
57 if (!empty($comments)) {
58 $this->assign('comments', $comments);
61 // add attachments part
62 $currentAttachmentInfo = CRM_Core_BAO_File
::getEntityFile('civicrm_note', $this->_id
);
63 $this->assign('currentAttachmentInfo', $currentAttachmentInfo);
68 * called when action is browse.
70 public function browse() {
71 $note = new CRM_Core_DAO_Note();
72 $note->entity_table
= 'civicrm_contact';
73 $note->entity_id
= $this->_contactId
;
75 $note->orderBy('modified_date desc');
77 //CRM-4418, handling edit and delete separately.
78 $permissions = [$this->_permission
];
79 if ($this->_permission
== CRM_Core_Permission
::EDIT
) {
80 //previously delete was subset of edit
81 //so for consistency lets grant delete also.
82 $permissions[] = CRM_Core_Permission
::DELETE
;
84 $mask = CRM_Core_Action
::mask($permissions);
86 $this->assign('canAddNotes', CRM_Core_Permission
::check('add contact notes'));
88 $links = self
::links();
89 $action = array_sum(array_keys($links)) & $mask;
92 while ($note->fetch()) {
93 if (!CRM_Core_BAO_Note
::getNotePrivacyHidden($note)) {
94 CRM_Core_DAO
::storeValues($note, $this->values
[$note->id
]);
96 $this->values
[$note->id
]['action'] = CRM_Core_Action
::formLink($links,
100 'cid' => $this->_contactId
,
108 if (!empty($note->contact_id
)) {
109 $contact = new CRM_Contact_DAO_Contact();
110 $contact->id
= $note->contact_id
;
113 $this->values
[$note->id
]['createdBy'] = $contact->display_name
;
115 $this->values
[$note->id
]['comment_count'] = CRM_Core_BAO_Note
::getChildCount($note->id
);
117 // paper icon view for attachments part
118 $paperIconAttachmentInfo = CRM_Core_BAO_File
::paperIconAttachment('civicrm_note', $note->id
);
119 $this->values
[$note->id
]['attachment'] = $paperIconAttachmentInfo;
122 $this->assign('notes', $this->values
);
124 $commentLinks = self
::commentLinks();
126 $action = array_sum(array_keys($commentLinks)) & $mask;
128 $commentAction = CRM_Core_Action
::formLink($commentLinks,
132 'pid' => $note->entity_id
,
133 'cid' => $note->entity_id
,
137 'note.comment.action',
141 $this->assign('commentAction', $commentAction);
143 $this->ajaxResponse
['tabCount'] = CRM_Contact_BAO_Contact
::getCountComponent('note', $this->_contactId
);
147 * called when action is update or new.
149 public function edit() {
150 $controller = new CRM_Core_Controller_Simple('CRM_Note_Form_Note', ts('Contact Notes'), $this->_action
);
151 $controller->setEmbedded(TRUE);
153 // set the userContext stack
154 $session = CRM_Core_Session
::singleton();
155 $url = CRM_Utils_System
::url('civicrm/contact/view',
156 'action=browse&selectedChild=note&cid=' . $this->_contactId
158 $session->pushUserContext($url);
160 if (CRM_Utils_Request
::retrieve('confirmed', 'Boolean')) {
161 CRM_Core_BAO_Note
::del($this->_id
);
162 CRM_Utils_System
::redirect($url);
165 $controller->reset();
166 $controller->set('entityTable', 'civicrm_contact');
167 $controller->set('entityId', $this->_contactId
);
168 $controller->set('id', $this->_id
);
170 $controller->process();
174 public function preProcess() {
175 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
177 if ($this->_id
&& CRM_Core_BAO_Note
::getNotePrivacyHidden($this->_id
)) {
178 CRM_Core_Error
::statusBounce(ts('You do not have access to this note.'));
181 $this->_contactId
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this, TRUE);
182 $this->assign('contactId', $this->_contactId
);
184 // check logged in url permission
185 CRM_Contact_Page_View
::checkUserPermission($this);
187 $displayName = CRM_Contact_BAO_Contact
::displayName($this->_contactId
);
188 CRM_Utils_System
::setTitle(ts('Notes for') . ' ' . $displayName);
190 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'browse');
191 $this->assign('action', $this->_action
);
195 * the main function that is called when the page loads,
196 * it decides the which action has to be taken for the page.
200 public function run() {
203 if ($this->_action
& CRM_Core_Action
::VIEW
) {
206 elseif ($this->_action
& CRM_Core_Action
::ADD
) {
208 $this->_permission
!= CRM_Core_Permission
::EDIT
&&
209 !CRM_Core_Permission
::check('add contact notes')
211 CRM_Core_Error
::statusBounce(ts('You do not have access to add notes.'));
216 elseif ($this->_action
& CRM_Core_Action
::UPDATE
) {
217 if ($this->_permission
!= CRM_Core_Permission
::EDIT
) {
218 CRM_Core_Error
::statusBounce(ts('You do not have access to edit this note.'));
223 elseif ($this->_action
& CRM_Core_Action
::DELETE
) {
224 if ($this->_permission
!= CRM_Core_Permission
::EDIT
) {
225 CRM_Core_Error
::statusBounce(ts('You do not have access to delete this note.'));
227 // we use the edit screen the confirm the delete
232 return parent
::run();
236 * Delete the note object from the db.
238 public function delete() {
239 CRM_Core_BAO_Note
::del($this->_id
);
246 * (reference) of action links
248 public static function &links() {
249 if (!(self
::$_links)) {
250 $deleteExtra = ts('Are you sure you want to delete this note?');
253 CRM_Core_Action
::VIEW
=> [
254 'name' => ts('View'),
255 'url' => 'civicrm/contact/view/note',
256 'qs' => 'action=view&reset=1&cid=%%cid%%&id=%%id%%&selectedChild=note',
257 'title' => ts('View Note'),
259 CRM_Core_Action
::UPDATE
=> [
260 'name' => ts('Edit'),
261 'url' => 'civicrm/contact/view/note',
262 'qs' => 'action=update&reset=1&cid=%%cid%%&id=%%id%%&selectedChild=note',
263 'title' => ts('Edit Note'),
265 CRM_Core_Action
::ADD
=> [
266 'name' => ts('Comment'),
267 'url' => 'civicrm/contact/view/note',
268 'qs' => 'action=add&reset=1&cid=%%cid%%&parentId=%%id%%&selectedChild=note',
269 'title' => ts('Add Comment'),
271 CRM_Core_Action
::DELETE
=> [
272 'name' => ts('Delete'),
273 'url' => 'civicrm/contact/view/note',
274 'qs' => 'action=delete&reset=1&cid=%%cid%%&id=%%id%%&selectedChild=note',
275 'title' => ts('Delete Note'),
279 return self
::$_links;
283 * Get action links for comments.
286 * (reference) of action links
288 public static function &commentLinks() {
289 if (!(self
::$_commentLinks)) {
290 self
::$_commentLinks = [
291 CRM_Core_Action
::VIEW
=> [
292 'name' => ts('View'),
293 'url' => 'civicrm/contact/view/note',
294 'qs' => 'action=view&reset=1&cid=%%cid%%&id={id}&selectedChild=note',
295 'title' => ts('View Comment'),
297 CRM_Core_Action
::UPDATE
=> [
298 'name' => ts('Edit'),
299 'url' => 'civicrm/contact/view/note',
300 'qs' => 'action=update&reset=1&cid=%%cid%%&id={id}&parentId=%%pid%%&selectedChild=note',
301 'title' => ts('Edit Comment'),
303 CRM_Core_Action
::DELETE
=> [
304 'name' => ts('Delete'),
305 'url' => 'civicrm/contact/view/note',
306 'qs' => 'action=delete&reset=1&cid=%%cid%%&id={id}&selectedChild=note',
307 'title' => ts('Delete Comment'),
311 return self
::$_commentLinks;