6 * This class offers functionality to store sequential comments/notes about an external object or anything with a unique id.
7 * It is not intended that once a note is save it can be editied or changed.
10 class Note
extends ORDataObject
{
13 * Database unique identifier
19 * DB unique identifier reference to some other table, this is not unique in the notes table
25 * Narrative comments about whatever object is represented by the foreign id this note is associated with
26 * @var string upto 255 character string
31 * Foreign key identifier of who initially persisited the note,
32 * potentially ownership could be changed but that would be up to an external non-document object process
38 * Date the note was first persisted
44 * Timestamp of the last time the note was changed and persisted, auto maintained by DB, manually change at your own peril
50 * Constructor sets all Note attributes to their default value
51 * @param int $id optional existing id of a specific note, if omitted a "blank" note is created
53 function __construct($id = "") {
54 //call the parent constructor so we have a _db to work with
55 parent
::__construct();
57 //shore up the most basic ORDataObject bits
59 $this->_table
= "notes";
62 $this->date
= date("Y-m-d H:i:s");
70 * Convenience function to get an array of many document objects
71 * For really large numbers of documents there is a way more efficient way to do this by overwriting the populate method
72 * @param int $foreign_id optional id use to limit array on to a specific relation, otherwise every document object is returned
74 function notes_factory($foreign_id = "") {
77 if (empty($foreign_id)) {
78 $foreign_id= "like '%'";
81 $foreign_id= " = '" . add_escape_custom(strval($foreign_id)) . "'";
85 $sql = "SELECT id FROM " . $d->_table
. " WHERE foreign_id " .$foreign_id . " ORDER BY DATE DESC";
87 $result = $d->_db
->Execute($sql);
89 while ($result && !$result->EOF
) {
90 $notes[] = new Note($result->fields
['id']);
98 * Convenience function to generate string debug data about the object
100 function toString($html = false) {
102 . "ID: " . $this->id
."\n"
103 . "FID: " . $this->foreign_id
."\n"
104 . "note: " . $this->note
. "\n"
105 . "date: " . $this->date
. "\n"
106 . "owner: " . $this->owner
. "\n"
107 . "revision: " . $this->revision
. "\n";
110 return nl2br($string);
118 * Getter/Setter methods used by reflection to affect object in persist/poulate operations
119 * @param mixed new value for given attribute
121 function set_id($id) {
127 function set_foreign_id($fid) {
128 $this->foreign_id
= $fid;
130 function get_foreign_id() {
131 return $this->foreign_id
;
133 function set_note($note) {
136 function get_note() {
139 function set_date($date) {
142 function get_date() {
145 function set_owner($owner) {
146 $this->owner
= $owner;
148 function get_owner() {
152 * No getter for revision because it is updated automatically by the DB.
154 function set_revision($revision) {
155 $this->revision
= $revision;
159 * Overridden function to store current object state in the db.
160 * This overide is to allow for a "just in time" foreign id, often this is needed
161 * when the object is never directly exposed and is handled as part of a larger
163 * @param int $fid foreign id that should be used so that this note can be related (joined) on it later
166 function persist($fid ="") {
168 $this->foreign_id
= $fid;