3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
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-2016
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)) {
62 CRM_Core_DAO
::storeValues($note, $values);
63 $values['privacy'] = CRM_Core_PseudoConstant
::getLabel('CRM_Core_BAO_Note', 'privacy', $values['privacy']);
64 $this->assign('note', $values);
67 $comments = CRM_Core_BAO_Note
::getNoteTree($values['id'], 1);
68 if (!empty($comments)) {
69 $this->assign('comments', $comments);
72 // add attachments part
73 $currentAttachmentInfo = CRM_Core_BAO_File
::getEntityFile('civicrm_note', $this->_id
);
74 $this->assign('currentAttachmentInfo', $currentAttachmentInfo);
79 * called when action is browse.
81 public function browse() {
82 $note = new CRM_Core_DAO_Note();
83 $note->entity_table
= 'civicrm_contact';
84 $note->entity_id
= $this->_contactId
;
86 $note->orderBy('modified_date desc');
88 //CRM-4418, handling edit and delete separately.
89 $permissions = array($this->_permission
);
90 if ($this->_permission
== CRM_Core_Permission
::EDIT
) {
91 //previously delete was subset of edit
92 //so for consistency lets grant delete also.
93 $permissions[] = CRM_Core_Permission
::DELETE
;
95 $mask = CRM_Core_Action
::mask($permissions);
98 $links = self
::links();
99 $action = array_sum(array_keys($links)) & $mask;
102 while ($note->fetch()) {
103 if (!CRM_Core_BAO_Note
::getNotePrivacyHidden($note)) {
104 CRM_Core_DAO
::storeValues($note, $values[$note->id
]);
106 $values[$note->id
]['action'] = CRM_Core_Action
::formLink($links,
110 'cid' => $this->_contactId
,
118 $contact = new CRM_Contact_DAO_Contact();
119 $contact->id
= $note->contact_id
;
122 $values[$note->id
]['createdBy'] = $contact->display_name
;
123 $values[$note->id
]['comment_count'] = CRM_Core_BAO_Note
::getChildCount($note->id
);
125 // paper icon view for attachments part
126 $paperIconAttachmentInfo = CRM_Core_BAO_File
::paperIconAttachment('civicrm_note', $note->id
);
127 $values[$note->id
]['attachment'] = $paperIconAttachmentInfo;
131 $this->assign('notes', $values);
133 $commentLinks = self
::commentLinks();
135 $action = array_sum(array_keys($commentLinks)) & $mask;
137 $commentAction = CRM_Core_Action
::formLink($commentLinks,
141 'pid' => $note->entity_id
,
142 'cid' => $note->entity_id
,
146 'note.comment.action',
150 $this->assign('commentAction', $commentAction);
152 $this->ajaxResponse
['tabCount'] = CRM_Contact_BAO_Contact
::getCountComponent('note', $this->_contactId
);
156 * called when action is update or new.
158 public function edit() {
159 $controller = new CRM_Core_Controller_Simple('CRM_Note_Form_Note', ts('Contact Notes'), $this->_action
);
160 $controller->setEmbedded(TRUE);
162 // set the userContext stack
163 $session = CRM_Core_Session
::singleton();
164 $url = CRM_Utils_System
::url('civicrm/contact/view',
165 'action=browse&selectedChild=note&cid=' . $this->_contactId
167 $session->pushUserContext($url);
169 if (CRM_Utils_Request
::retrieve('confirmed', 'Boolean')) {
170 CRM_Core_BAO_Note
::del($this->_id
);
171 CRM_Utils_System
::redirect($url);
174 $controller->reset();
175 $controller->set('entityTable', 'civicrm_contact');
176 $controller->set('entityId', $this->_contactId
);
177 $controller->set('id', $this->_id
);
179 $controller->process();
183 public function preProcess() {
184 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
186 if ($this->_id
&& CRM_Core_BAO_Note
::getNotePrivacyHidden($this->_id
)) {
187 CRM_Core_Error
::statusBounce(ts('You do not have access to this note.'));
190 $this->_contactId
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this, TRUE);
191 $this->assign('contactId', $this->_contactId
);
193 // check logged in url permission
194 CRM_Contact_Page_View
::checkUserPermission($this);
196 $displayName = CRM_Contact_BAO_Contact
::displayName($this->_contactId
);
197 CRM_Utils_System
::setTitle(ts('Notes for') . ' ' . $displayName);
199 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'browse');
200 $this->assign('action', $this->_action
);
204 * the main function that is called when the page loads,
205 * it decides the which action has to be taken for the page.
209 public function run() {
212 if ($this->_action
& CRM_Core_Action
::VIEW
) {
215 elseif ($this->_action
& (CRM_Core_Action
::UPDATE | CRM_Core_Action
::ADD
)) {
218 elseif ($this->_action
& CRM_Core_Action
::DELETE
) {
219 // we use the edit screen the confirm the delete
224 return parent
::run();
228 * Delete the note object from the db.
230 public function delete() {
231 CRM_Core_BAO_Note
::del($this->_id
);
238 * (reference) of action links
240 public static function &links() {
241 if (!(self
::$_links)) {
242 $deleteExtra = ts('Are you sure you want to delete this note?');
244 self
::$_links = array(
245 CRM_Core_Action
::VIEW
=> array(
246 'name' => ts('View'),
247 'url' => 'civicrm/contact/view/note',
248 'qs' => 'action=view&reset=1&cid=%%cid%%&id=%%id%%&selectedChild=note',
249 'title' => ts('View Note'),
251 CRM_Core_Action
::UPDATE
=> array(
252 'name' => ts('Edit'),
253 'url' => 'civicrm/contact/view/note',
254 'qs' => 'action=update&reset=1&cid=%%cid%%&id=%%id%%&selectedChild=note',
255 'title' => ts('Edit Note'),
257 CRM_Core_Action
::ADD
=> array(
258 'name' => ts('Comment'),
259 'url' => 'civicrm/contact/view/note',
260 'qs' => 'action=add&reset=1&cid=%%cid%%&parentId=%%id%%&selectedChild=note',
261 'title' => ts('Add Comment'),
263 CRM_Core_Action
::DELETE
=> array(
264 'name' => ts('Delete'),
265 'url' => 'civicrm/contact/view/note',
266 'qs' => 'action=delete&reset=1&cid=%%cid%%&id=%%id%%&selectedChild=note',
267 'title' => ts('Delete Note'),
271 return self
::$_links;
275 * Get action links for comments.
278 * (reference) of action links
280 public static function &commentLinks() {
281 if (!(self
::$_commentLinks)) {
282 self
::$_commentLinks = array(
283 CRM_Core_Action
::VIEW
=> array(
284 'name' => ts('View'),
285 'url' => 'civicrm/contact/view/note',
286 'qs' => 'action=view&reset=1&cid=%%cid%%&id={id}&selectedChild=note',
287 'title' => ts('View Comment'),
289 CRM_Core_Action
::UPDATE
=> array(
290 'name' => ts('Edit'),
291 'url' => 'civicrm/contact/view/note',
292 'qs' => 'action=update&reset=1&cid=%%cid%%&id={id}&parentId=%%pid%%&selectedChild=note',
293 'title' => ts('Edit Comment'),
295 CRM_Core_Action
::DELETE
=> array(
296 'name' => ts('Delete'),
297 'url' => 'civicrm/contact/view/note',
298 'qs' => 'action=delete&reset=1&cid=%%cid%%&id={id}&selectedChild=note',
299 'title' => ts('Delete Comment'),
303 return self
::$_commentLinks;