• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

Services/Notes/classes/class.ilNote.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2005 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
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 
00044 class ilNote
00045 {
00046         
00050         function ilNote($a_id = 0)
00051         {
00052                 if ($a_id > 0)
00053                 {
00054                         $this->id = $a_id;
00055                         $this->read();
00056                 }
00057         }
00058         
00064         function setId($a_id)
00065         {
00066                 $this->id = $a_id;
00067         }
00068 
00074         function getId()
00075         {
00076                 return $this->id;
00077         }
00078         
00089         function setObject($a_obj_type, $a_rep_obj_id, $a_obj_id = 0)
00090         {               
00091                 $this->rep_obj_id = $a_rep_obj_id;
00092                 $this->obj_id = $a_obj_id;
00093                 $this->obj_type = $a_obj_type;
00094         }
00095         
00096         function getObject()
00097         {
00098                 return array("rep_obj_id" => $this->rep_obj_id,
00099                         "obj_id" => $this->obj_id,
00100                         "obj_type" => $this->obj_type);
00101         }
00102         
00103         
00109         function setType($a_type)
00110         {
00111                 $this->type = $a_type;
00112         }
00113 
00119         function getType()
00120         {
00121                 return $this->type;
00122         }
00123 
00129         function setAuthor($a_user_id)
00130         {
00131                 $this->author = $a_user_id;
00132         }
00133 
00139         function getAuthor()
00140         {
00141                 return $this->author;
00142         }
00143         
00149         function setText($a_text)
00150         {
00151                 $this->text = $a_text;
00152         }
00153 
00159         function getText()
00160         {
00161                 return $this->text;
00162         }
00163 
00169         function setSubject($a_subject)
00170         {
00171                 $this->subject = $a_subject;
00172         }
00173 
00179         function getSubject()
00180         {
00181                 return $this->subject;
00182         }
00183         
00189         function setCreationDate($a_date)
00190         {
00191                 $this->creation_date = $a_date;
00192         }
00193 
00199         function getCreationDate()
00200         {
00201                 return $this->creation_date;
00202         }
00203         
00209         function setUpdateDate($a_date)
00210         {
00211                 $this->update_date = $a_date;
00212         }
00213 
00219         function getUpdateDate()
00220         {
00221                 return $this->update_date;
00222         }
00223         
00230         function setLabel($a_label)
00231         {
00232                 return $this->label = $a_label;
00233         }
00234         
00241         function getLabel()
00242         {
00243                 return $this->label;
00244         }
00245         
00246         function create()
00247         {
00248                 global $ilDB;
00249                 
00250                 $q = "INSERT INTO note (rep_obj_id, obj_id, obj_type, type,".
00251                         "author, text, subject, label, creation_date) VALUES (".
00252                         $ilDB->quote($this->rep_obj_id).",".
00253                         $ilDB->quote($this->obj_id).",".
00254                         $ilDB->quote($this->obj_type).",".
00255                         $ilDB->quote($this->type).",".
00256                         $ilDB->quote($this->author).",".
00257                         $ilDB->quote($this->text).",".
00258                         $ilDB->quote($this->subject).",".
00259                         $ilDB->quote($this->label).",".
00260                         "now())";
00261                 $ilDB->query($q);
00262                 
00263                 $this->id = $ilDB->getLastInsertId();
00264                 $this->creation_date = ilNote::_lookupCreationDate($this->getId());
00265         }
00266 
00267         function update()
00268         {
00269                 global $ilDB;
00270                 
00271                 $q = "UPDATE note SET ".
00272                         "rep_obj_id = ".$ilDB->quote($this->rep_obj_id).",".
00273                         "obj_id = ".$ilDB->quote($this->obj_id).",".
00274                         "obj_type = ".$ilDB->quote($this->obj_type).",".
00275                         "type = ".$ilDB->quote($this->type).",".
00276                         "author = ".$ilDB->quote($this->author).",".
00277                         "text = ".$ilDB->quote($this->text).",".
00278                         "subject = ".$ilDB->quote($this->subject).",".
00279                         "update_date = now(),".
00280                         "label = ".$ilDB->quote($this->label).
00281                         "WHERE id =".$ilDB->quote($this->getId());
00282 
00283                 $ilDB->query($q);
00284                 
00285                 $this->update_date = ilNote::_lookupUpdateDate($this->getId());
00286         }
00287 
00288         function read()
00289         {
00290                 global $ilDB;
00291                 
00292                 $q = "SELECT * FROM note WHERE id = ".
00293                         $ilDB->quote($this->getId());
00294                 $set = $ilDB->query($q);
00295                 $note_rec = $set->fetchRow(DB_FETCHMODE_ASSOC);
00296                 $this->setAllData($note_rec);
00297         }
00298         
00302         function delete()
00303         {
00304                 global $ilDB;
00305                 
00306                 $q = "DELETE FROM note WHERE id = ".
00307                         $ilDB->quote($this->getId());
00308                 $ilDB->query($q);
00309         }
00310         
00314         function setAllData($a_note_rec)
00315         {
00316                 $this->setId($a_note_rec["id"]);
00317                 $this->setObject($a_note_rec["obj_type"], $a_note_rec["rep_obj_id"], $a_note_rec["obj_id"]);
00318                 $this->setType($a_note_rec["type"]);
00319                 $this->setAuthor($a_note_rec["author"]);
00320                 $this->setText($a_note_rec["text"]);
00321                 $this->setSubject($a_note_rec["subject"]);
00322                 $this->setLabel($a_note_rec["label"]);
00323                 $this->setCreationDate($a_note_rec["creation_date"]);
00324                 $this->setUpdateDate($a_note_rec["update_date"]);
00325         }
00326         
00330         function _lookupCreationDate($a_id)
00331         {
00332                 global $ilDB;
00333                 
00334                 $q = "SELECT * FROM note WHERE id = ".
00335                         $ilDB->quote($this->getId());
00336                 $set = $ilDB->query($q);
00337                 $note_rec = $set->fetchRow(DB_FETCHMODE_ASSOC);
00338 
00339                 return $note_rec["creation_date"];
00340         }
00341 
00345         function _lookupUpdateDate($a_id)
00346         {
00347                 global $ilDB;
00348                 
00349                 $q = "SELECT * FROM note WHERE id = ".
00350                         $ilDB->quote($this->getId());
00351                 $set = $ilDB->query($q);
00352                 $note_rec = $set->fetchRow(DB_FETCHMODE_ASSOC);
00353 
00354                 return $note_rec["update_date"];
00355         }
00356         
00360         function _getNotesOfObject($a_rep_obj_id, $a_obj_id, $a_obj_type,
00361                 $a_type = IL_NOTE_PRIVATE, $a_incl_sub = false, $a_filter = "",
00362                 $a_all_public = "y")
00363         {
00364                 global $ilDB, $ilUser;
00365                 
00366                 $author_where = ($a_type == IL_NOTE_PRIVATE || $a_all_public == "n")
00367                         ? " AND author = ".$ilDB->quote($ilUser->getId())
00368                         : "";
00369 
00370                 $sub_where = (!$a_incl_sub)
00371                         ? " AND obj_id = ".$ilDB->quote($a_obj_id).
00372                           " AND obj_type = ".$ilDB->quote($a_obj_type)
00373                         : "";
00374                 
00375                 $q = "SELECT * FROM note WHERE ".
00376                         " rep_obj_id = ".$ilDB->quote($a_rep_obj_id).
00377                         $sub_where.
00378                         " AND type = ".$ilDB->quote($a_type).
00379                         $author_where.
00380                         " ORDER BY creation_date DESC";
00381 
00382                 $ilDB->quote($q);
00383                 $set = $ilDB->query($q);
00384                 $notes = array();
00385                 while($note_rec = $set->fetchRow(DB_FETCHMODE_ASSOC))
00386                 {
00387                         if ($a_filter != "")
00388                         {
00389                                 if (!is_array($a_filter))
00390                                 {
00391                                         $a_filter = array($a_filter);
00392                                 }
00393                                 if (!in_array($note_rec["id"], $a_filter))
00394                                 {
00395                                         continue;
00396                                 }
00397                         }
00398                         $cnt = count($notes);
00399                         $notes[$cnt] = new ilNote();
00400                         $notes[$cnt]->setAllData($note_rec);
00401                 }
00402                 
00403                 return $notes;
00404         }
00405 
00409         function _getLastNotesOfUser()
00410         {
00411                 global $ilDB, $ilUser;
00412                 
00413                 $q = "SELECT * FROM note WHERE ".
00414                         " type = ".$ilDB->quote(IL_NOTE_PRIVATE).
00415                         " AND author = ".$ilDB->quote($ilUser->getId()).
00416                         " ORDER BY creation_date DESC LIMIT 10";
00417 
00418                 $ilDB->quote($q);
00419                 $set = $ilDB->query($q);
00420                 $notes = array();
00421                 while($note_rec = $set->fetchRow(DB_FETCHMODE_ASSOC))
00422                 {
00423                         $cnt = count($notes);
00424                         $notes[$cnt] = new ilNote();
00425                         $notes[$cnt]->setAllData($note_rec);
00426                 }
00427                 
00428                 return $notes;
00429         }
00430         
00434         function _getRelatedObjectsOfUser()
00435         {
00436                 global $ilDB, $ilUser;
00437                 
00438                 $q = "SELECT DISTINCT rep_obj_id FROM note WHERE ".
00439                         " type = ".$ilDB->quote(IL_NOTE_PRIVATE).
00440                         " AND author = ".$ilDB->quote($ilUser->getId()).
00441                         " ORDER BY rep_obj_id";
00442 
00443                 $ilDB->quote($q);
00444                 $set = $ilDB->query($q);
00445                 $reps = array();
00446                 while($rep_rec = $set->fetchRow(DB_FETCHMODE_ASSOC))
00447                 {
00448                         $reps[] = array("rep_obj_id" => $rep_rec["rep_obj_id"]);
00449                 }
00450                 
00451                 return $reps;
00452         }
00453 
00454 }
00455 ?>

Generated on Fri Dec 13 2013 13:52:12 for ILIAS Release_3_7_x_branch .rev 46817 by  doxygen 1.7.1