3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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-2015
35 * Main page for viewing Notes.
37 class CRM_Contact_Page_View_Note
extends CRM_Core_Page
{
40 * The action links for notes that we need to display for the browse screen
44 static $_links = NULL;
47 * The action links for comments that we need to display for the browse screen
51 static $_commentLinks = NULL;
54 * View details of a note.
56 public function view() {
57 $note = new CRM_Core_DAO_Note();
58 $note->id
= $this->_id
;
59 if ($note->find(TRUE)) {
61 CRM_Core_DAO
::storeValues($note, $values);
62 $values['privacy'] = CRM_Core_OptionGroup
::optionLabel('note_privacy', $values['privacy']);
63 $this->assign('note', $values);
66 $comments = CRM_Core_BAO_Note
::getNoteTree($values['id'], 1);
67 if (!empty($comments)) {
68 $this->assign('comments', $comments);
71 // add attachments part
72 $currentAttachmentInfo = CRM_Core_BAO_File
::getEntityFile('civicrm_note', $this->_id
);
73 $this->assign('currentAttachmentInfo', $currentAttachmentInfo);
78 * called when action is browse.
80 public function browse() {
81 $note = new CRM_Core_DAO_Note();
82 $note->entity_table
= 'civicrm_contact';
83 $note->entity_id
= $this->_contactId
;
85 $note->orderBy('modified_date desc');
87 //CRM-4418, handling edit and delete separately.
88 $permissions = array($this->_permission
);
89 if ($this->_permission
== CRM_Core_Permission
::EDIT
) {
90 //previously delete was subset of edit
91 //so for consistency lets grant delete also.
92 $permissions[] = CRM_Core_Permission
::DELETE
;
94 $mask = CRM_Core_Action
::mask($permissions);
97 $links = self
::links();
98 $action = array_sum(array_keys($links)) & $mask;
101 while ($note->fetch()) {
102 if (!CRM_Core_BAO_Note
::getNotePrivacyHidden($note)) {
103 CRM_Core_DAO
::storeValues($note, $values[$note->id
]);
105 $values[$note->id
]['action'] = CRM_Core_Action
::formLink($links,
109 'cid' => $this->_contactId
,
117 $contact = new CRM_Contact_DAO_Contact();
118 $contact->id
= $note->contact_id
;
121 $values[$note->id
]['createdBy'] = $contact->display_name
;
122 $values[$note->id
]['comment_count'] = CRM_Core_BAO_Note
::getChildCount($note->id
);
124 // paper icon view for attachments part
125 $paperIconAttachmentInfo = CRM_Core_BAO_File
::paperIconAttachment('civicrm_note', $note->id
);
126 $values[$note->id
]['attachment'] = $paperIconAttachmentInfo;
130 $this->assign('notes', $values);
132 $commentLinks = self
::commentLinks();
134 $action = array_sum(array_keys($commentLinks)) & $mask;
136 $commentAction = CRM_Core_Action
::formLink($commentLinks,
140 'pid' => $note->entity_id
,
141 'cid' => $note->entity_id
,
145 'note.comment.action',
149 $this->assign('commentAction', $commentAction);
151 $this->ajaxResponse
['tabCount'] = CRM_Contact_BAO_Contact
::getCountComponent('note', $this->_contactId
);
155 * called when action is update or new.
157 public function edit() {
158 $controller = new CRM_Core_Controller_Simple('CRM_Note_Form_Note', ts('Contact Notes'), $this->_action
);
159 $controller->setEmbedded(TRUE);
161 // set the userContext stack
162 $session = CRM_Core_Session
::singleton();
163 $url = CRM_Utils_System
::url('civicrm/contact/view',
164 'action=browse&selectedChild=note&cid=' . $this->_contactId
166 $session->pushUserContext($url);
168 if (CRM_Utils_Request
::retrieve('confirmed', 'Boolean',
169 CRM_Core_DAO
::$_nullObject
172 CRM_Core_BAO_Note
::del($this->_id
);
173 CRM_Utils_System
::redirect($url);
176 $controller->reset();
177 $controller->set('entityTable', 'civicrm_contact');
178 $controller->set('entityId', $this->_contactId
);
179 $controller->set('id', $this->_id
);
181 $controller->process();
185 public function preProcess() {
186 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
188 if ($this->_id
&& CRM_Core_BAO_Note
::getNotePrivacyHidden($this->_id
)) {
189 CRM_Core_Error
::statusBounce(ts('You do not have access to this note.'));
192 $this->_contactId
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this, TRUE);
193 $this->assign('contactId', $this->_contactId
);
195 // check logged in url permission
196 CRM_Contact_Page_View
::checkUserPermission($this);
198 $displayName = CRM_Contact_BAO_Contact
::displayName($this->_contactId
);
199 CRM_Utils_System
::setTitle(ts('Notes for') . ' ' . $displayName);
201 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'browse');
202 $this->assign('action', $this->_action
);
206 * the main function that is called when the page loads,
207 * it decides the which action has to be taken for the page.
211 public function run() {
214 if ($this->_action
& CRM_Core_Action
::VIEW
) {
217 elseif ($this->_action
& (CRM_Core_Action
::UPDATE | CRM_Core_Action
::ADD
)) {
220 elseif ($this->_action
& CRM_Core_Action
::DELETE
) {
221 // we use the edit screen the confirm the delete
226 return parent
::run();
230 * Delete the note object from the db.
232 public function delete() {
233 CRM_Core_BAO_Note
::del($this->_id
);
240 * (reference) of action links
242 public static function &links() {
243 if (!(self
::$_links)) {
244 $deleteExtra = ts('Are you sure you want to delete this note?');
246 self
::$_links = array(
247 CRM_Core_Action
::VIEW
=> array(
248 'name' => ts('View'),
249 'url' => 'civicrm/contact/view/note',
250 'qs' => 'action=view&reset=1&cid=%%cid%%&id=%%id%%&selectedChild=note',
251 'title' => ts('View Note'),
253 CRM_Core_Action
::UPDATE
=> array(
254 'name' => ts('Edit'),
255 'url' => 'civicrm/contact/view/note',
256 'qs' => 'action=update&reset=1&cid=%%cid%%&id=%%id%%&selectedChild=note',
257 'title' => ts('Edit Note'),
259 CRM_Core_Action
::ADD
=> array(
260 'name' => ts('Comment'),
261 'url' => 'civicrm/contact/view/note',
262 'qs' => 'action=add&reset=1&cid=%%cid%%&parentId=%%id%%&selectedChild=note',
263 'title' => ts('Add Comment'),
265 CRM_Core_Action
::DELETE
=> array(
266 'name' => ts('Delete'),
267 'url' => 'civicrm/contact/view/note',
268 'qs' => 'action=delete&reset=1&cid=%%cid%%&id=%%id%%&selectedChild=note',
269 'title' => ts('Delete Note'),
273 return self
::$_links;
277 * Get action links for comments.
280 * (reference) of action links
282 public static function &commentLinks() {
283 if (!(self
::$_commentLinks)) {
284 self
::$_commentLinks = array(
285 CRM_Core_Action
::VIEW
=> array(
286 'name' => ts('View'),
287 'url' => 'civicrm/contact/view/note',
288 'qs' => 'action=view&reset=1&cid=%%cid%%&id={id}&selectedChild=note',
289 'title' => ts('View Comment'),
291 CRM_Core_Action
::UPDATE
=> array(
292 'name' => ts('Edit'),
293 'url' => 'civicrm/contact/view/note',
294 'qs' => 'action=update&reset=1&cid=%%cid%%&id={id}&parentId=%%pid%%&selectedChild=note',
295 'title' => ts('Edit Comment'),
297 CRM_Core_Action
::DELETE
=> array(
298 'name' => ts('Delete'),
299 'url' => 'civicrm/contact/view/note',
300 'qs' => 'action=delete&reset=1&cid=%%cid%%&id={id}&selectedChild=note',
301 'title' => ts('Delete Comment'),
305 return self
::$_commentLinks;