ILIAS  Release_3_10_x_branch Revision 61812
 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 ".
104  "SET item_id = ".$ilDB->quote($this->getItemId()).", ".
105  "usr_id = ".$ilDB->quote($this->getUserId()).", ".
106  "planed_start = ".$ilDB->quote($this->getPlanedStartingTime()).", ".
107  "planed_end = ".$ilDB->quote($this->getPlanedEndingTime())." ";
108  $this->db->query($query);
109  }
110 
111  function delete()
112  {
113  return ilTimingPlaned::_delete($this->getItemId(),$this->getUserId());
114  }
115 
116  function _delete($a_item_id,$a_usr_id)
117  {
118  global $ilDB;
119 
120  $query = "DELETE FROM crs_timings_planed ".
121  "WHERE item_id = ".$ilDB->quote($a_item_id)." ".
122  "AND usr_id = ".$ilDB->quote($a_usr_id)." ";
123  $ilDB->query($query);
124  }
125 
126  // Static
127  function _getPlanedTimings($a_usr_id,$a_item_id)
128  {
129  global $ilDB;
130 
131  $query = "SELECT * FROM crs_timings_planed ".
132  "WHERE item_id = ".$ilDB->quote($a_item_id)." ".
133  "AND usr_id = ".$a_usr_id." ";
134  $res = $ilDB->query($query);
135  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
136  {
137  $data['planed_start'] = $row->planed_start;
138  $data['planed_end'] = $row->planed_end;
139  }
140  return $data ? $data : array();
141  }
142 
143 
144  function _getPlanedTimingsByItem($a_item_id)
145  {
146  global $ilDB;
147 
148  $query = "SELECT * FROM crs_timings_planed ".
149  "WHERE item_id = ".$ilDB->quote($a_item_id)." ";
150  $res = $ilDB->query($query);
151  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
152  {
153  $data[$row->usr_id]['start'] = $row->planed_start;
154  $data[$row->usr_id]['end'] = $row->planed_end;
155  }
156  return $data ? $data : array();
157  }
158 
159  function _deleteByItem($a_item_id)
160  {
161  global $ilDB;
162 
163  $query = "DELETE FROM crs_timings_planed ".
164  "WHERE item_id = ".$ilDB->quote($a_item_id)." ";
165  $ilDB->query($query);
166  }
167 
168  function _deleteByUser($a_usr_id)
169  {
170  global $ilDB;
171 
172  $query = "DELETE FROM crs_timings_planed ".
173  "WHERE usr_id = ".$ilDB->quote($a_usr_id)." ";
174  $ilDB->query($query);
175  }
176 
177  function __read()
178  {
179  global $ilDB;
180 
181  $query = "SELECT * FROM crs_timings_planed ".
182  "WHERE item_id = ".$ilDB->quote($this->getItemId())." ".
183  "AND usr_id = ".$ilDB->quote($this->getUserId())." ";
184  $res = $this->db->query($query);
185  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
186  {
187  $this->setPlanedStartingTime($row->planed_start);
188  $this->setPlanedEndingTime($row->planed_end);
189  }
190  return true;
191  }
192 }
193 ?>