Example #1
0
 /**
  * called when action is browse.
  */
 public function browse()
 {
     $note = new CRM_Core_DAO_Note();
     $note->entity_table = 'civicrm_contact';
     $note->entity_id = $this->_contactId;
     $note->orderBy('modified_date desc');
     //CRM-4418, handling edit and delete separately.
     $permissions = array($this->_permission);
     if ($this->_permission == CRM_Core_Permission::EDIT) {
         //previously delete was subset of edit
         //so for consistency lets grant delete also.
         $permissions[] = CRM_Core_Permission::DELETE;
     }
     $mask = CRM_Core_Action::mask($permissions);
     $values = array();
     $links = self::links();
     $action = array_sum(array_keys($links)) & $mask;
     $note->find();
     while ($note->fetch()) {
         if (!CRM_Core_BAO_Note::getNotePrivacyHidden($note)) {
             CRM_Core_DAO::storeValues($note, $values[$note->id]);
             $values[$note->id]['action'] = CRM_Core_Action::formLink($links, $action, array('id' => $note->id, 'cid' => $this->_contactId), ts('more'), FALSE, 'note.selector.row', 'Note', $note->id);
             $contact = new CRM_Contact_DAO_Contact();
             $contact->id = $note->contact_id;
             $contact->find();
             $contact->fetch();
             $values[$note->id]['createdBy'] = $contact->display_name;
             $values[$note->id]['comment_count'] = CRM_Core_BAO_Note::getChildCount($note->id);
             // paper icon view for attachments part
             $paperIconAttachmentInfo = CRM_Core_BAO_File::paperIconAttachment('civicrm_note', $note->id);
             $values[$note->id]['attachment'] = $paperIconAttachmentInfo;
         }
     }
     $this->assign('notes', $values);
     $commentLinks = self::commentLinks();
     $action = array_sum(array_keys($commentLinks)) & $mask;
     $commentAction = CRM_Core_Action::formLink($commentLinks, $action, array('id' => $note->id, 'pid' => $note->entity_id, 'cid' => $note->entity_id), ts('more'), FALSE, 'note.comment.action', 'Note', $note->id);
     $this->assign('commentAction', $commentAction);
     $this->ajaxResponse['tabCount'] = CRM_Contact_BAO_Contact::getCountComponent('note', $this->_contactId);
 }
Example #2
0
 /**
  * Recursive function to get all descendent notes of the note with given ID.
  *
  * @param int $parentId
  *   ID of the note to start from.
  * @param int $maxDepth
  *   Maximum number of levels to descend into the tree; if not given, will include all descendents.
  * @param bool $snippet
  *   If TRUE, returned values will be pre-formatted for display in a table of notes.
  * @param array $tree
  *   (Reference) Variable to store all found descendents.
  * @param int $depth
  *   Depth of current iteration within the descendent tree (used for comparison against maxDepth).
  *
  * @return array
  *   Nested associative array beginning with direct children of given note.
  */
 private static function buildNoteTree($parentId, $maxDepth = 0, $snippet = FALSE, &$tree = array(), $depth = 0)
 {
     if ($maxDepth && $depth > $maxDepth) {
         return FALSE;
     }
     // get direct children of given parentId note
     $note = new CRM_Core_DAO_Note();
     $note->entity_table = 'civicrm_note';
     $note->entity_id = $parentId;
     $note->orderBy('modified_date asc');
     $note->find();
     while ($note->fetch()) {
         // foreach child, call this function, unless the child is private/hidden
         if (!self::getNotePrivacyHidden($note)) {
             CRM_Core_DAO::storeValues($note, $tree[$note->id]);
             // get name of user that created this note
             $contact = new CRM_Contact_DAO_Contact();
             $createdById = $note->contact_id;
             $contact->id = $createdById;
             $contact->find();
             $contact->fetch();
             $tree[$note->id]['createdBy'] = $contact->display_name;
             $tree[$note->id]['createdById'] = $createdById;
             $tree[$note->id]['modified_date'] = CRM_Utils_Date::customFormat($tree[$note->id]['modified_date']);
             // paper icon view for attachments part
             $paperIconAttachmentInfo = CRM_Core_BAO_File::paperIconAttachment('civicrm_note', $note->id);
             $tree[$note->id]['attachment'] = $paperIconAttachmentInfo ? implode('', $paperIconAttachmentInfo) : '';
             if ($snippet) {
                 $tree[$note->id]['note'] = nl2br($tree[$note->id]['note']);
                 $tree[$note->id]['note'] = smarty_modifier_mb_truncate($tree[$note->id]['note'], 80, '...', TRUE);
                 CRM_Utils_Date::customFormat($tree[$note->id]['modified_date']);
             }
             self::buildNoteTree($note->id, $maxDepth, $snippet, $tree[$note->id]['child'], $depth + 1);
         }
     }
     return $tree;
 }
Example #3
0
 /**
  * Recursive function to get all descendent notes of the note with given ID
  * @param int $parentId ID of the note to start from
  * @param int $maxDepth Maximum number of levels to descend into the tree; if not given, will include all descendents.
  * @param bool $snippet If TRUE, returned values will be pre-formatted for display in a table of notes.
  * @param array $tree (Reference) Variable to store all found descendents
  * @param int $depth Depth of current iteration within the descendent tree (used for comparison against maxDepth)
  * @return array Nested associative array beginning with direct children of given note.
  */
 private static function buildNoteTree($parentId, $maxDepth = 0, $snippet = FALSE, &$tree = array(), $depth = 0)
 {
     if ($maxDepth && $depth > $maxDepth) {
         return;
     }
     // get direct children of given parentId note
     $note = new CRM_Core_DAO_Note();
     $note->entity_table = 'civicrm_note';
     $note->entity_id = $parentId;
     $note->orderBy('modified_date asc');
     $note->find();
     while ($note->fetch()) {
         // foreach child, call this function, unless the child is private/hidden
         if (!self::getNotePrivacyHidden($note)) {
             CRM_Core_DAO::storeValues($note, $tree[$note->id]);
             // get name of user that created this note
             require_once 'CRM/Contact/DAO/Contact.php';
             require_once 'CRM/Core/Smarty/plugins/modifier.mb_truncate.php';
             $contact = new CRM_Contact_DAO_Contact();
             $createdById = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Note', $parentId, 'entity_id');
             $contact->id = $createdById;
             $contact->find();
             $contact->fetch();
             $tree[$note->id]['createdBy'] = $contact->display_name;
             $tree[$note->id]['createdById'] = $createdById;
             $tree[$note->id]['modified_date'] = CRM_Utils_Date::customFormat($tree[$note->id]['modified_date']);
             if ($snippet) {
                 $tree[$note->id]['note'] = nl2br($tree[$note->id]['note']);
                 $tree[$note->id]['note'] = smarty_modifier_mb_truncate($tree[$note->id]['note'], 80, '...', TRUE);
                 CRM_Utils_Date::customFormat($tree[$note->id]['modified_date']);
             }
             self::buildNoteTree($note->id, $maxDepth, $snippet, $tree[$note->id]['child'], $depth + 1);
         }
     }
     return $tree;
 }