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
14 * Database unique identifier
20 * DB unique identifier reference to some other table, this is not unique in the notes table
26 * Narrative comments about whatever object is represented by the foreign id this note is associated with
27 * @var string upto 255 character string
32 * Foreign key identifier of who initially persisited the note,
33 * potentially ownership could be changed but that would be up to an external non-document object process
39 * Date the note was first persisted
45 * Timestamp of the last time the note was changed and persisted, auto maintained by DB, manually change at your own peril
51 * Constructor sets all Note attributes to their default value
52 * @param int $id optional existing id of a specific note, if omitted a "blank" note is created
54 function __construct($id = "")
56 //call the parent constructor so we have a _db to work with
57 parent
::__construct();
59 //shore up the most basic ORDataObject bits
61 $this->_table
= "notes";
64 $this->date
= date("Y-m-d H:i:s");
72 * Convenience function to get an array of many document objects
73 * For really large numbers of documents there is a way more efficient way to do this by overwriting the populate method
74 * @param int $foreign_id optional id use to limit array on to a specific relation, otherwise every document object is returned
76 public static function notes_factory($foreign_id = "")
80 if (empty($foreign_id)) {
81 $foreign_id= "like '%'";
83 $foreign_id= " = '" . add_escape_custom(strval($foreign_id)) . "'";
87 $sql = "SELECT id FROM " . $d->_table
. " WHERE foreign_id " .$foreign_id . " ORDER BY DATE DESC";
89 $result = $d->_db
->Execute($sql);
91 while ($result && !$result->EOF
) {
92 $notes[] = new Note($result->fields
['id']);
100 * Convenience function to generate string debug data about the object
102 function toString($html = false)
105 . "ID: " . $this->id
."\n"
106 . "FID: " . $this->foreign_id
."\n"
107 . "note: " . $this->note
. "\n"
108 . "date: " . $this->date
. "\n"
109 . "owner: " . $this->owner
. "\n"
110 . "revision: " . $this->revision
. "\n";
113 return nl2br($string);
120 * Getter/Setter methods used by reflection to affect object in persist/poulate operations
121 * @param mixed new value for given attribute
131 function set_foreign_id($fid)
133 $this->foreign_id
= $fid;
135 function get_foreign_id()
137 return $this->foreign_id
;
139 function set_note($note)
147 function set_date($date)
155 function set_owner($owner)
157 $this->owner
= $owner;
164 * No getter for revision because it is updated automatically by the DB.
166 function set_revision($revision)
168 $this->revision
= $revision;
172 * Overridden function to store current object state in the db.
173 * This overide is to allow for a "just in time" foreign id, often this is needed
174 * when the object is never directly exposed and is handled as part of a larger
176 * @param int $fid foreign id that should be used so that this note can be related (joined) on it later
179 function persist($fid = "")
182 $this->foreign_id
= $fid;