00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 define("IL_NOTE_PRIVATE", 1);
00025 define("IL_NOTE_PUBLIC", 2);
00026
00027 define("IL_NOTE_UNLABELED", 0);
00028 define("IL_NOTE_IMPORTANT", 1);
00029 define("IL_NOTE_QUESTION", 2);
00030 define("IL_NOTE_PRO", 3);
00031 define("IL_NOTE_CONTRA", 4);
00032
00040 class ilNote
00041 {
00042
00046 function ilNote($a_id = 0)
00047 {
00048 if ($a_id > 0)
00049 {
00050 $this->id = $a_id;
00051 $this->read();
00052 }
00053 }
00054
00060 function setId($a_id)
00061 {
00062 $this->id = $a_id;
00063 }
00064
00070 function getId()
00071 {
00072 return $this->id;
00073 }
00074
00085 function setObject($a_obj_type, $a_rep_obj_id, $a_obj_id = 0)
00086 {
00087 $this->rep_obj_id = $a_rep_obj_id;
00088 $this->obj_id = $a_obj_id;
00089 $this->obj_type = $a_obj_type;
00090 }
00091
00092 function getObject()
00093 {
00094 return array("rep_obj_id" => $this->rep_obj_id,
00095 "obj_id" => $this->obj_id,
00096 "obj_type" => $this->obj_type);
00097 }
00098
00099
00105 function setType($a_type)
00106 {
00107 $this->type = $a_type;
00108 }
00109
00115 function getType()
00116 {
00117 return $this->type;
00118 }
00119
00125 function setAuthor($a_user_id)
00126 {
00127 $this->author = $a_user_id;
00128 }
00129
00135 function getAuthor()
00136 {
00137 return $this->author;
00138 }
00139
00145 function setText($a_text)
00146 {
00147 $this->text = $a_text;
00148 }
00149
00155 function getText()
00156 {
00157 return $this->text;
00158 }
00159
00165 function setSubject($a_subject)
00166 {
00167 $this->subject = $a_subject;
00168 }
00169
00175 function getSubject()
00176 {
00177 return $this->subject;
00178 }
00179
00185 function setCreationDate($a_date)
00186 {
00187 $this->creation_date = $a_date;
00188 }
00189
00195 function getCreationDate()
00196 {
00197 return $this->creation_date;
00198 }
00199
00205 function setUpdateDate($a_date)
00206 {
00207 $this->update_date = $a_date;
00208 }
00209
00215 function getUpdateDate()
00216 {
00217 return $this->update_date;
00218 }
00219
00226 function setLabel($a_label)
00227 {
00228 return $this->label = $a_label;
00229 }
00230
00237 function getLabel()
00238 {
00239 return $this->label;
00240 }
00241
00242 function create()
00243 {
00244 global $ilDB;
00245
00246 $q = "INSERT INTO note (rep_obj_id, obj_id, obj_type, type,".
00247 "author, text, subject, label, creation_date) VALUES (".
00248 $ilDB->quote($this->rep_obj_id).",".
00249 $ilDB->quote($this->obj_id).",".
00250 $ilDB->quote($this->obj_type).",".
00251 $ilDB->quote($this->type).",".
00252 $ilDB->quote($this->author).",".
00253 $ilDB->quote($this->text).",".
00254 $ilDB->quote($this->subject).",".
00255 $ilDB->quote($this->label).",".
00256 "now())";
00257 $ilDB->query($q);
00258
00259 $this->id = $ilDB->getLastInsertId();
00260 $this->creation_date = ilNote::_lookupCreationDate($this->getId());
00261 }
00262
00263 function update()
00264 {
00265 global $ilDB;
00266
00267 $q = "UPDATE note SET ".
00268 "rep_obj_id = ".$ilDB->quote($this->rep_obj_id).",".
00269 "obj_id = ".$ilDB->quote($this->obj_id).",".
00270 "obj_type = ".$ilDB->quote($this->obj_type).",".
00271 "type = ".$ilDB->quote($this->type).",".
00272 "author = ".$ilDB->quote($this->author).",".
00273 "text = ".$ilDB->quote($this->text).",".
00274 "subject = ".$ilDB->quote($this->subject).",".
00275 "update_date = now(),".
00276 "label = ".$ilDB->quote($this->label).
00277 "WHERE id =".$ilDB->quote($this->getId());
00278
00279 $ilDB->query($q);
00280
00281 $this->update_date = ilNote::_lookupUpdateDate($this->getId());
00282 }
00283
00284 function read()
00285 {
00286 global $ilDB;
00287
00288 $q = "SELECT * FROM note WHERE id = ".
00289 $ilDB->quote($this->getId());
00290 $set = $ilDB->query($q);
00291 $note_rec = $set->fetchRow(DB_FETCHMODE_ASSOC);
00292 $this->setAllData($note_rec);
00293 }
00294
00298 function delete()
00299 {
00300 global $ilDB;
00301
00302 $q = "DELETE FROM note WHERE id = ".
00303 $ilDB->quote($this->getId());
00304 $ilDB->query($q);
00305 }
00306
00310 function setAllData($a_note_rec)
00311 {
00312 $this->setId($a_note_rec["id"]);
00313 $this->setObject($a_note_rec["obj_type"], $a_note_rec["rep_obj_id"], $a_note_rec["obj_id"]);
00314 $this->setType($a_note_rec["type"]);
00315 $this->setAuthor($a_note_rec["author"]);
00316 $this->setText($a_note_rec["text"]);
00317 $this->setSubject($a_note_rec["subject"]);
00318 $this->setLabel($a_note_rec["label"]);
00319 $this->setCreationDate($a_note_rec["creation_date"]);
00320 $this->setUpdateDate($a_note_rec["update_date"]);
00321 }
00322
00326 function _lookupCreationDate($a_id)
00327 {
00328 global $ilDB;
00329
00330 $q = "SELECT * FROM note WHERE id = ".
00331 $ilDB->quote($this->getId());
00332 $set = $ilDB->query($q);
00333 $note_rec = $set->fetchRow(DB_FETCHMODE_ASSOC);
00334
00335 return $note_rec["creation_date"];
00336 }
00337
00341 function _lookupUpdateDate($a_id)
00342 {
00343 global $ilDB;
00344
00345 $q = "SELECT * FROM note WHERE id = ".
00346 $ilDB->quote($this->getId());
00347 $set = $ilDB->query($q);
00348 $note_rec = $set->fetchRow(DB_FETCHMODE_ASSOC);
00349
00350 return $note_rec["update_date"];
00351 }
00352
00356 function _getNotesOfObject($a_rep_obj_id, $a_obj_id, $a_obj_type,
00357 $a_type = IL_NOTE_PRIVATE, $a_incl_sub = false, $a_filter = "",
00358 $a_all_public = "y")
00359 {
00360 global $ilDB, $ilUser;
00361
00362 $author_where = ($a_type == IL_NOTE_PRIVATE || $a_all_public == "n")
00363 ? " AND author = ".$ilDB->quote($ilUser->getId())
00364 : "";
00365
00366 $sub_where = (!$a_incl_sub)
00367 ? " AND obj_id = ".$ilDB->quote($a_obj_id).
00368 " AND obj_type = ".$ilDB->quote($a_obj_type)
00369 : "";
00370
00371 $q = "SELECT * FROM note WHERE ".
00372 " rep_obj_id = ".$ilDB->quote($a_rep_obj_id).
00373 $sub_where.
00374 " AND type = ".$ilDB->quote($a_type).
00375 $author_where.
00376 " ORDER BY creation_date DESC";
00377
00378 $ilDB->quote($q);
00379 $set = $ilDB->query($q);
00380 $notes = array();
00381 while($note_rec = $set->fetchRow(DB_FETCHMODE_ASSOC))
00382 {
00383 if ($a_filter != "")
00384 {
00385 if (!is_array($a_filter))
00386 {
00387 $a_filter = array($a_filter);
00388 }
00389 if (!in_array($note_rec["id"], $a_filter))
00390 {
00391 continue;
00392 }
00393 }
00394 $cnt = count($notes);
00395 $notes[$cnt] = new ilNote();
00396 $notes[$cnt]->setAllData($note_rec);
00397 }
00398
00399 return $notes;
00400 }
00401
00405 function _getLastNotesOfUser()
00406 {
00407 global $ilDB, $ilUser;
00408
00409 $q = "SELECT * FROM note WHERE ".
00410 " type = ".$ilDB->quote(IL_NOTE_PRIVATE).
00411 " AND author = ".$ilDB->quote($ilUser->getId()).
00412 " ORDER BY creation_date DESC LIMIT 10";
00413
00414 $ilDB->quote($q);
00415 $set = $ilDB->query($q);
00416 $notes = array();
00417 while($note_rec = $set->fetchRow(DB_FETCHMODE_ASSOC))
00418 {
00419 $cnt = count($notes);
00420 $notes[$cnt] = new ilNote();
00421 $notes[$cnt]->setAllData($note_rec);
00422 }
00423
00424 return $notes;
00425 }
00426
00430 function _getRelatedObjectsOfUser()
00431 {
00432 global $ilDB, $ilUser;
00433
00434 $q = "SELECT DISTINCT rep_obj_id FROM note WHERE ".
00435 " type = ".$ilDB->quote(IL_NOTE_PRIVATE).
00436 " AND author = ".$ilDB->quote($ilUser->getId()).
00437 " ORDER BY rep_obj_id";
00438
00439 $ilDB->quote($q);
00440 $set = $ilDB->query($q);
00441 $reps = array();
00442 while($rep_rec = $set->fetchRow(DB_FETCHMODE_ASSOC))
00443 {
00444 $reps[] = array("rep_obj_id" => $rep_rec["rep_obj_id"]);
00445 }
00446
00447 return $reps;
00448 }
00449
00450 }
00451 ?>