ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilTimingUser.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
13{
14 private $ref_id = 0;
15 private $usr_id = 0;
16 private $start = null;
17 private $end = null;
18
19 private $is_scheduled = false;
20
26 public function __construct($a_ref_id, $a_usr_id)
27 {
28 $this->ref_id = $a_ref_id;
29 $this->usr_id = $a_usr_id;
30
31 $this->start = new ilDateTime(0, IL_CAL_UNIX);
32 $this->end = new ilDateTime(0, IL_CAL_UNIX);
33
34 $this->read();
35 }
36
41 public function getUserId()
42 {
43 return $this->usr_id;
44 }
45
50 public function getRefId()
51 {
52 return $this->ref_id;
53 }
54
58 public function isScheduled()
59 {
61 }
62
67 public function getStart()
68 {
69 return $this->start;
70 }
71
76 public function getEnd()
77 {
78 return $this->end;
79 }
80
84 public function create()
85 {
86 global $DIC;
87
88 $ilDB = $DIC->database();
89
90 if ($this->isScheduled()) {
91 return $this->update();
92 }
93
94 $query = 'INSERT INTO crs_timings_user (ref_id, usr_id, sstart, ssend ) VALUES ( ' .
95 $ilDB->quote($this->getRefId(), 'integer') . ', ' .
96 $ilDB->quote($this->getUserId(), 'integer') . ', ' .
97 $ilDB->quote($this->getStart()->get(IL_CAL_UNIX, 'integer')) . ', ' .
98 $ilDB->quote($this->getEnd()->get(IL_CAL_UNIX, 'integer')) . ' ' .
99 ')';
100 $ilDB->manipulate($query);
101
102 $this->is_scheduled = true;
103 }
104
109 public function update()
110 {
111 global $DIC;
112
113 $ilDB = $DIC->database();
114
115 if (!$this->isScheduled()) {
116 return $this->create();
117 }
118
119 $query = 'UPDATE crs_timings_user ' .
120 'SET sstart = ' . $ilDB->quote($this->getStart()->get(IL_CAL_UNIX, 'integer')) . ', ' .
121 'ssend = ' . $ilDB->quote($this->getEnd()->get(IL_CAL_UNIX, 'integer')) . ' ' .
122 'WHERE ref_id = ' . $ilDB->quote($this->getRefId(), 'integer') . ' ' .
123 'AND usr_id = ' . $ilDB->quote($this->getUserId(), 'integer');
124 $ilDB->manipulate($query);
125 }
126
131 public function delete()
132 {
133 global $DIC;
134
135 $ilDB = $DIC->database();
136
137 $query = 'DELETE FROM crs_timings_user ' . ' ' .
138 'WHERE ref_id = ' . $ilDB->quote($this->getRefId(), 'integer') . ' ' .
139 'AND usr_id = ' . $ilDB->quote($this->getUserId(), 'integer');
140 $ilDB->manipulate($query);
141
142 $this->is_scheduled = false;
143 }
144
145
146
150 public function read()
151 {
152 global $DIC;
153
154 $ilDB = $DIC->database();
155
156 $query = 'SELECT * FROM crs_timings_user ' .
157 'WHERE ref_id = ' . $ilDB->quote($this->getRefId(), 'integer') . ' ' .
158 'AND usr_id = ' . $ilDB->quote($this->getUserId(), 'integer');
159 $res = $ilDB->query($query);
160 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
161 $this->is_scheduled = true;
162 $this->start = new ilDateTime($row->sstart, IL_CAL_UNIX);
163 $this->end = new ilDateTime($row->ssend, IL_CAL_UNIX);
164 }
165 return $this->isScheduled();
166 }
167}
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
@classDescription Date and time handling
TableGUI class for timings administration.
getUserId()
get user id
update()
Update @global type $ilDB.
getRefId()
Get ref_id.
read()
Read from db.
isScheduled()
Check if an entry exists for user.
getStart()
Use to set start date.
getEnd()
Use to set date.
create()
Create new entry.
__construct($a_ref_id, $a_usr_id)
Constructor.
$row
$query
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
global $ilDB