Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00035 class ilLPEventCollections
00036 {
00037 var $db = null;
00038
00039 var $obj_id = null;
00040 var $items = array();
00041
00042 function ilLPEventCollections($a_obj_id)
00043 {
00044 global $ilObjDataCache,$ilDB;
00045
00046 $this->db =& $ilDB;
00047
00048 $this->obj_id = $a_obj_id;
00049
00050 $this->__read();
00051 }
00052
00053 function getObjId()
00054 {
00055 return (int) $this->obj_id;
00056 }
00057
00058 function getItems()
00059 {
00060 return $this->items;
00061 }
00062
00063 function isAssigned($a_obj_id)
00064 {
00065 return (bool) in_array($a_obj_id,$this->items);
00066 }
00067
00068 function add($item_id)
00069 {
00070 if($this->isAssigned($item_id))
00071 {
00072 return false;
00073 }
00074
00075 $query = "INSERT INTO ut_lp_event_collections ".
00076 "SET obj_id = '".$this->obj_id."', ".
00077 "item_id = '".(int) $item_id."'";
00078 $this->db->query($query);
00079
00080 $this->__read();
00081
00082 return true;
00083 }
00084
00085 function delete($item_id)
00086 {
00087 $query = "DELETE FROM ut_lp_event_collections ".
00088 "WHERE item_id = '".$item_id."' ".
00089 "AND obj_id = '".$this->obj_id."'";
00090 $this->db->query($query);
00091
00092 $this->__read();
00093
00094 return true;
00095 }
00096
00097
00098 function _deleteAll($a_obj_id)
00099 {
00100 global $ilDB;
00101
00102 $query = "DELETE FROM ut_lp_collections ".
00103 "WHERE obj_id = '".$a_obj_id."'";
00104 $ilDB->query($query);
00105
00106 return true;
00107 }
00108
00109 function _getItems($a_obj_id)
00110 {
00111 include_once 'course/classes/Event/class.ilEvent.php';
00112
00113 global $ilObjDataCache;
00114 global $ilDB;
00115
00116 $query = "SELECT * FROM ut_lp_event_collections WHERE obj_id = '".(int) $a_obj_id."'";
00117 $res = $ilDB->query($query);
00118 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00119 {
00120 if(!ilEvent::_exists($row->item_id))
00121 {
00122 $query = "DELETE FROM ut_lp_event_collections ".
00123 "WHERE obj_id = '".$a_obj_id."' ".
00124 "AND item_id = '".$row->item_id."'";
00125 $ilDB->query($query);
00126 continue;
00127 }
00128 $items[] = $row->item_id;
00129 }
00130 return $items ? $items : array();
00131 }
00132
00133
00134 function __read()
00135 {
00136 include_once 'course/classes/Event/class.ilEvent.php';
00137
00138 global $ilObjDataCache;
00139
00140 $query = "SELECT * FROM ut_lp_event_collections WHERE obj_id = '".$this->db->quote($this->obj_id)."'";
00141 $res = $this->db->query($query);
00142 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00143 {
00144 if(!ilEvent::_exists($row->item_id))
00145 {
00146 $query = "DELETE FROM ut_lp_event_collections ".
00147 "WHERE obj_id = '".$a_obj_id."' ".
00148 "AND item_id = '".$row->item_id."'";
00149 $this->db->query($query);
00150 continue;
00151 }
00152 $this->items[] = $row->item_id;
00153 }
00154
00155 }
00156 }
00157 ?>