Interim autoloaded library/classes via composer classmap, take 4. (#422)
[openemr.git] / library / classes / Note.class.php
blob758cc8eae9c346ad830532196d10d80e7d9dc658
1 <?php
4 /**
5 * class Note
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.
8 */
10 class Note extends ORDataObject{
13 * Database unique identifier
14 * @var id
16 var $id;
19 * DB unique identifier reference to some other table, this is not unique in the notes table
20 * @var int
22 var $foreign_id;
25 * Narrative comments about whatever object is represented by the foreign id this note is associated with
26 * @var string upto 255 character string
28 var $note;
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
33 * @var int
35 var $owner;
38 * Date the note was first persisted
39 * @var date
41 var $date;
44 * Timestamp of the last time the note was changed and persisted, auto maintained by DB, manually change at your own peril
45 * @var int
47 var $revision;
49 /**
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
58 $this->id = $id;
59 $this->_table = "notes";
61 $this->note = "";
62 $this->date = date("Y-m-d H:i:s");
64 if ($id != "") {
65 $this->populate();
69 /**
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 = "") {
75 $notes = array();
77 if (empty($foreign_id)) {
78 $foreign_id= "like '%'";
80 else {
81 $foreign_id= " = '" . add_escape_custom(strval($foreign_id)) . "'";
84 $d = new note();
85 $sql = "SELECT id FROM " . $d->_table . " WHERE foreign_id " .$foreign_id . " ORDER BY DATE DESC";
86 //echo $sql;
87 $result = $d->_db->Execute($sql);
89 while ($result && !$result->EOF) {
90 $notes[] = new Note($result->fields['id']);
91 $result->MoveNext();
94 return $notes;
97 /**
98 * Convenience function to generate string debug data about the object
100 function toString($html = false) {
101 $string .= "\n"
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";
109 if ($html) {
110 return nl2br($string);
112 else {
113 return $string;
117 /**#@+
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) {
122 $this->id = $id;
124 function get_id() {
125 return $this->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) {
134 $this->note = $note;
136 function get_note() {
137 return $this->note;
139 function set_date($date) {
140 $this->date = $date;
142 function get_date() {
143 return $this->date;
145 function set_owner($owner) {
146 $this->owner = $owner;
148 function get_owner() {
149 return $this->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
162 * object hierarchy.
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 ="") {
167 if (!empty($fid)) {
168 $this->foreign_id = $fid;
170 parent::persist();
173 } // end of Note