some portal work
[openemr.git] / library / classes / Note.class.php
bloba89d140629d90c83e6e72b4e6d0afe5399927a70
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 public static function notes_factory($foreign_id = "")
78 $notes = array();
80 $sqlArray = array();
82 if (empty($foreign_id)) {
83 $foreign_id_sql = " like '%'";
84 } else {
85 $foreign_id_sql = " = ?";
86 $sqlArray[] = strval($foreign_id);
89 $d = new note();
90 $sql = "SELECT id FROM " . escape_table_name($d->_table) . " WHERE foreign_id " . $foreign_id_sql . " ORDER BY DATE DESC";
91 //echo $sql;
92 $result = $d->_db->Execute($sql, $sqlArray);
94 while ($result && !$result->EOF) {
95 $notes[] = new Note($result->fields['id']);
96 $result->MoveNext();
99 return $notes;
103 * Convenience function to generate string debug data about the object
105 function toString($html = false)
107 $string .= "\n"
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";
115 if ($html) {
116 return nl2br($string);
117 } else {
118 return $string;
122 /**#@+
123 * Getter/Setter methods used by reflection to affect object in persist/poulate operations
124 * @param mixed new value for given attribute
126 function set_id($id)
128 $this->id = $id;
130 function get_id()
132 return $this->id;
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)
144 $this->note = $note;
146 function get_note()
148 return $this->note;
150 function set_date($date)
152 $this->date = $date;
154 function get_date()
156 return $this->date;
158 function set_owner($owner)
160 $this->owner = $owner;
162 function get_owner()
164 return $this->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
178 * object hierarchy.
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 = "")
184 if (!empty($fid)) {
185 $this->foreign_id = $fid;
188 parent::persist();
190 } // end of Note