ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilTimingPlaned.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 
35 {
36  var $ilErr;
37  var $ilDB;
38  var $lng;
39 
40  function ilTimingPlaned($item_id,$a_usr_id)
41  {
42  global $ilErr,$ilDB,$lng,$tree;
43 
44  $this->ilErr =& $ilErr;
45  $this->db =& $ilDB;
46  $this->lng =& $lng;
47 
48  $this->item_id = $item_id;
49  $this->user_id = $a_usr_id;
50 
51  $this->__read();
52  }
53 
54  function getUserId()
55  {
56  return $this->user_id;
57  }
58  function getItemId()
59  {
60  return $this->item_id;
61  }
62 
64  {
65  return $this->start;
66  }
67  function setPlanedStartingTime($a_time)
68  {
69  $this->start = $a_time;
70  }
72  {
73  return $this->end;
74  }
75  function setPlanedEndingTime($a_end)
76  {
77  $this->end = $a_end;
78  }
79 
80  function validate()
81  {
82  include_once 'Modules/Course/classes/class.ilCourseItems.php';
83  $item_data = ilCourseItems::_getItem($this->getItemId());
84 
85  if($this->getPlanedEndingTime() > $item_data['latest_end'])
86  {
87  return false;
88  }
89  return true;
90  }
91 
92  function update()
93  {
94  ilTimingPlaned::_delete($this->getItemId(),$this->getUserId());
95  $this->create();
96  return true;
97  }
98 
99  function create()
100  {
101  global $ilDB;
102 
103  $query = "INSERT INTO crs_timings_planed (item_id,usr_id,planed_start,planed_end) ".
104  "VALUES( ".
105  $ilDB->quote($this->getItemId() ,'integer').", ".
106  $ilDB->quote($this->getUserId() ,'integer').", ".
107  $ilDB->quote($this->getPlanedStartingTime() ,'integer').", ".
108  $ilDB->quote($this->getPlanedEndingTime() ,'integer')." ".
109  ")";
110  $res = $ilDB->manipulate($query);
111  }
112 
113  function delete()
114  {
115  return ilTimingPlaned::_delete($this->getItemId(),$this->getUserId());
116  }
117 
118  function _delete($a_item_id,$a_usr_id)
119  {
120  global $ilDB;
121 
122  $query = "DELETE FROM crs_timings_planed ".
123  "WHERE item_id = ".$ilDB->quote($a_item_id ,'integer')." ".
124  "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ";
125  $res = $ilDB->manipulate($query);
126  }
127 
128  // Static
129  function _getPlanedTimings($a_usr_id,$a_item_id)
130  {
131  global $ilDB;
132 
133  $query = "SELECT * FROM crs_timings_planed ".
134  "WHERE item_id = ".$ilDB->quote($a_item_id ,'integer')." ".
135  "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ";
136  $res = $ilDB->query($query);
137  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
138  {
139  $data['planed_start'] = $row->planed_start;
140  $data['planed_end'] = $row->planed_end;
141  }
142  return $data ? $data : array();
143  }
144 
145 
146  function _getPlanedTimingsByItem($a_item_id)
147  {
148  global $ilDB;
149 
150  $query = "SELECT * FROM crs_timings_planed ".
151  "WHERE item_id = ".$ilDB->quote($a_item_id ,'integer')." ";
152  $res = $ilDB->query($query);
153  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
154  {
155  $data[$row->usr_id]['start'] = $row->planed_start;
156  $data[$row->usr_id]['end'] = $row->planed_end;
157  }
158  return $data ? $data : array();
159  }
160 
161  function _deleteByItem($a_item_id)
162  {
163  global $ilDB;
164 
165  $query = "DELETE FROM crs_timings_planed ".
166  "WHERE item_id = ".$ilDB->quote($a_item_id ,'integer')." ";
167  $res = $ilDB->manipulate($query);
168  }
169 
170  function _deleteByUser($a_usr_id)
171  {
172  global $ilDB;
173 
174  $query = "DELETE FROM crs_timings_planed ".
175  "WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ";
176  $res = $ilDB->manipulate($query);
177  }
178 
179  function __read()
180  {
181  global $ilDB;
182 
183  $query = "SELECT * FROM crs_timings_planed ".
184  "WHERE item_id = ".$ilDB->quote($this->getItemId() ,'integer')." ".
185  "AND usr_id = ".$ilDB->quote($this->getUserId() ,'integer')." ";
186  $res = $this->db->query($query);
187  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
188  {
189  $this->setPlanedStartingTime($row->planed_start);
190  $this->setPlanedEndingTime($row->planed_end);
191  }
192  return true;
193  }
194 }
195 ?>