3 require_once(dirname(__FILE__
) . "/ORDataObject.class.php");
7 * This class offers functionality to store sequential comments/notes about an external object or anything with a unique id.
8 * It is not intended that once a note is save it can be editied or changed.
11 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 Note($id = "") {
55 //call the parent constructor so we have a _db to work with
56 parent
::ORDataObject();
58 //shore up the most basic ORDataObject bits
60 $this->_table
= "notes";
63 $this->date
= date("Y-m-d H:i:s");
71 * Convenience function to get an array of many document objects
72 * For really large numbers of documents there is a way more efficient way to do this by overwriting the populate method
73 * @param int $foreign_id optional id use to limit array on to a specific relation, otherwise every document object is returned
75 function notes_factory($foreign_id = "") {
78 if (empty($foreign_id)) {
79 $foreign_id= "like '%'";
82 $foreign_id= " = '" . mysql_real_escape_string(strval($foreign_id)) . "'";
86 $sql = "SELECT id FROM " . $d->_table
. " WHERE foreign_id " .$foreign_id . " ORDER BY DATE DESC";
88 $result = $d->_db
->Execute($sql);
90 while ($result && !$result->EOF
) {
91 $notes[] = new Note($result->fields
['id']);
99 * Convenience function to generate string debug data about the object
101 function toString($html = false) {
103 . "ID: " . $this->id
."\n"
104 . "FID: " . $this->foreign_id
."\n"
105 . "note: " . $this->note
. "\n"
106 . "date: " . $this->date
. "\n"
107 . "owner: " . $this->owner
. "\n"
108 . "revision: " . $this->revision
. "\n";
111 return nl2br($string);
119 * Getter/Setter methods used by reflection to affect object in persist/poulate operations
120 * @param mixed new value for given attribute
122 function set_id($id) {
128 function set_foreign_id($fid) {
129 $this->foreign_id
= $fid;
131 function get_foreign_id() {
132 return $this->foreign_id
;
134 function set_note($note) {
137 function get_note() {
140 function set_date($date) {
143 function get_date() {
146 function set_owner($owner) {
147 $this->owner
= $owner;
149 function get_owner() {
153 * No getter for revision because it is updated automatically by the DB.
155 function set_revision($revision) {
156 $this->revision
= $revision;
160 * Overridden function to store current object state in the db.
161 * This overide is to allow for a "just in time" foreign id, often this is needed
162 * when the object is never directly exposed and is handled as part of a larger
164 * @param int $fid foreign id that should be used so that this note can be related (joined) on it later
167 function persist($fid ="") {
169 $this->foreign_id
= $fid;