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 = "")
82 if (empty($foreign_id)) {
83 $foreign_id_sql = " like '%'";
85 $foreign_id_sql = " = ?";
86 $sqlArray[] = strval($foreign_id);
90 $sql = "SELECT id FROM " . escape_table_name($d->_table
) . " WHERE foreign_id " . $foreign_id_sql . " ORDER BY DATE DESC";
92 $result = $d->_db
->Execute($sql, $sqlArray);
94 while ($result && !$result->EOF
) {
95 $notes[] = new Note($result->fields
['id']);
103 * Convenience function to generate string debug data about the object
105 function toString($html = false)
108 . "ID: " . $this->id
."\n"
109 . "FID: " . $this->foreign_id
."\n"
110 . "note: " . $this->note
. "\n"
111 . "date: " . $this->date
. "\n"
112 . "owner: " . $this->owner
. "\n"
113 . "revision: " . $this->revision
. "\n";
116 return nl2br($string);
123 * Getter/Setter methods used by reflection to affect object in persist/poulate operations
124 * @param mixed new value for given attribute
134 function set_foreign_id($fid)
136 $this->foreign_id
= $fid;
138 function get_foreign_id()
140 return $this->foreign_id
;
142 function set_note($note)
150 function set_date($date)
158 function set_owner($owner)
160 $this->owner
= $owner;
167 * No getter for revision because it is updated automatically by the DB.
169 function set_revision($revision)
171 $this->revision
= $revision;
175 * Overridden function to store current object state in the db.
176 * This overide is to allow for a "just in time" foreign id, often this is needed
177 * when the object is never directly exposed and is handled as part of a larger
179 * @param int $fid foreign id that should be used so that this note can be related (joined) on it later
182 function persist($fid = "")
185 $this->foreign_id
= $fid;