Ideas: NS Web Blog
Valuable tips on maximizing your web presence. Enrich your mind here.

One of our clients recently asked for some customization of the Notes features for Contacts. It happens that these features may also be useful for other objects that use Notes, but at the moment we are primarily interested in getting this working for Contacts.
In the CiviCRM forum, I had a short exchange with Lobo about the two primary improvements we're looking at:
With Lobo's helpful input, we've come up with a target that lays the foundation for some improvements in all uses of notes, but starting out by only exposing these features for Contact notes. Here's a summary of what we're looking at, targeting inclusion in CiviCRM 3.3.
We'd love to get some feedback from other CiviCRM users and developers, so please comment below if you have any input.
This idea is fairly straightforward: mark a note as "Private" and it will, by default, be only visible to you, the note author. For the note author, this adds a "Private?" check-box to the note editing form; only the note author can mark the note as private.
Module developers are able to override the default privacy rules using hook_civicrm_notePrivacy():
/** * Custom logic to hide private notes * * @param array $note (reference) Associative array of values from * civicrm_note for the given note. */ function civitest_civicrm_notePrivacy (&$note) { /* CiviCRM will check for existence of $note['notePrivacy_hidden']. * If this value is not set, CiviCRM will show or display the note * based on the default, which is to display private notes only to * the note author. * If this value is set, CiviCRM will hide the note if the value is * TRUE, and display the note if the value is FALSE. */ if ($note['is_private']) { if ($my_business_rules_say_so) { $note['notePrivacy_hidden'] = TRUE; } else { $note['notePrivacy_hidden'] = FALSE; } }
Note comments are simply notes having a parent_id of another note. Technically, this would allow for comment threads many layers deep, but at this point we're only planning to deal with the first layer, supporting only comments directly attached to a note, not comments attached to comments.
To support this, we add a couple of new actions to each row in the "browse notes" table, as seen for example in the Notes tab under civicrm/contact/view. The new items are "Comment" and "View Comments", as seen here:

The "Comment" action opens up the Note form in add/update mode, assigning the correct parent_id to tie the comment to the parent note. Since a comment will inherit the parent note's subject, this note add/update form does not expose the "Subject" field. In its place it displays the static text: "Re: $subject", where $subject is the parent note's subject.

The "View Comments" action uses AJAX to call the new API function civicrm_note_getTree(), which fetches all descendants of the given note, in tree form, up to a given maximum depth. In this case we set a maximum depth of 1 because we're not supporting multi-level threaded comments here.
Comments fetched via this action are then inserted into the table in rows directly below the note row. This action also replaces itself with the "Hide Comments" action, which can be used to remove those comment rows from the table and once again expose the "View Comments" action.

You'll see in the above image that, although notes are sorted in descending order by date, comments are always sorted ascending by date. The idea here is that, while top-level notes are not necessarily related chronologically to each other, comments are directly related to their parent note and logically flow in a chronological order.
Adding these rows does raise some question about the proper behavior of the sorting controls at the top of each column. Ideally, the comments would be sorted as a block with their parent note. We're currently playing with the jQuery DataTables plugin (which powers the sorting functionality) to see how close we can get to that. Presently the comment rows are simply removed when the table is re-sorted.
Finally, note comments are displayed below the note on the "View Note" page.

That's it. This adds note privacy and non-threaded note comments to Contact notes, and leaves room for adding similar features in places where notes are used.
Please let us hear your comments below.
Add a comment