Highway to PSR2
[openemr.git] / library / classes / Note.class.php
blob69931ec76d04149143e7cfc956ccc939def49a63
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
14 * Database unique identifier
15 * @var id
17 var $id;
20 * DB unique identifier reference to some other table, this is not unique in the notes table
21 * @var int
23 var $foreign_id;
26 * Narrative comments about whatever object is represented by the foreign id this note is associated with
27 * @var string upto 255 character string
29 var $note;
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
34 * @var int
36 var $owner;
39 * Date the note was first persisted
40 * @var date
42 var $date;
45 * Timestamp of the last time the note was changed and persisted, auto maintained by DB, manually change at your own peril
46 * @var int
48 var $revision;
50 /**
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
60 $this->id = $id;
61 $this->_table = "notes";
63 $this->note = "";
64 $this->date = date("Y-m-d H:i:s");
66 if ($id != "") {
67 $this->populate();
71 /**
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 function notes_factory($foreign_id = "")
78 $notes = array();
80 if (empty($foreign_id)) {
81 $foreign_id= "like '%'";
82 } else {
83 $foreign_id= " = '" . add_escape_custom(strval($foreign_id)) . "'";
86 $d = new note();
87 $sql = "SELECT id FROM " . $d->_table . " WHERE foreign_id " .$foreign_id . " ORDER BY DATE DESC";
88 //echo $sql;
89 $result = $d->_db->Execute($sql);
91 while ($result && !$result->EOF) {
92 $notes[] = new Note($result->fields['id']);
93 $result->MoveNext();
96 return $notes;
99 /**
100 * Convenience function to generate string debug data about the object
102 function toString($html = false)
104 $string .= "\n"
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";
112 if ($html) {
113 return nl2br($string);
114 } else {
115 return $string;
119 /**#@+
120 * Getter/Setter methods used by reflection to affect object in persist/poulate operations
121 * @param mixed new value for given attribute
123 function set_id($id)
125 $this->id = $id;
127 function get_id()
129 return $this->id;
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)
141 $this->note = $note;
143 function get_note()
145 return $this->note;
147 function set_date($date)
149 $this->date = $date;
151 function get_date()
153 return $this->date;
155 function set_owner($owner)
157 $this->owner = $owner;
159 function get_owner()
161 return $this->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
175 * object hierarchy.
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 = "")
181 if (!empty($fid)) {
182 $this->foreign_id = $fid;
185 parent::persist();
187 } // end of Note