Source for file projecttime.class.php

Documentation is available at projecttime.class.php


1 <?php
2 /**
3 *
4 * @version $Id: workday.class.php,v 1.6 2003/09/24 16:21:48 cybot_tm Exp $
5 * @category phpTimeSheet
6 * @package phpTimeSheet
7 */
8
9 /**
10 * reflects one row in table Project_Times
11 *
12 * one row is identified by project_id, worker_id and date
13 *
14 * @version $Id: workday.class.php,v 1.6 2003/09/24 16:21:48 cybot_tm Exp $
15 * @category phpTimeSheet
16 * @package phpTimeSheet
17 * @uses Date
18 * @uses Time
19 */
20 class ProjectTime
21 {
22 /**
23 * @var int project_id
24 * @access protected
25 * @since 1.0
26 */
27 var $project_id;
28
29 /**
30 * @var int worker_id
31 * @access protected
32 * @since 1.0
33 */
34 var $worker_id;
35
36 /**
37 * @var int company_id
38 * @access protected
39 * @since 1.0
40 */
41 var $company_id;
42
43 /**
44 * @var object Date date of day
45 * @since 1.0
46 */
47 var $date;
48
49 /**
50 * @var object Time spent time for this project
51 * @since 1.0
52 */
53 var $time;
54
55 /**
56 *
57 * @uses SetDate()
58 * @uses SetWorkerId()
59 * @uses SetProjectId()
60 * @uses Date
61 * @param object Date
62 * @see Date::Set() for allowed var-type of param date
63 * @param int project_id
64 * @param int worker_id
65 * @return bool success
66 */
67 function ProjectTime($date, $project_id, $worker_id)
68 {
69 $this->SetDate($date);
70 $this->SetWorkerId($worker_id);
71 $this->SetProjectId($project_id);
72
73 return true;
74 }
75
76 /**
77 * @uses $date
78 * @return object Date
79 */
80 function GetDate() { return $this->date; }
81
82 /**
83 * @uses $worker_id
84 * @return int worker_id
85 */
86 function GetWorkerId() { return $this->worker_id; }
87
88 /**
89 * @uses $project_id
90 * @return int project_id
91 */
92 function GetProjectId() { return $this->project_id; }
93
94 /**
95 * @uses $company_id
96 * @return int company_id
97 */
98 function GetCompanyId() { return $this->company_id; }
99
100 /**
101 * Sets current date
102 *
103 * @uses $date
104 * @param mixed date object date or string
105 * @see Date::Set() for allowed var-type of param date
106 * @return bool success
107 * @uses Date
108 */
109 function SetDate($date = null)
110 {
111 if ( null === $date )
112 {
113 $date = time();
114 }
115 $this->date = new Date($date);
116
117 return true;
118 }
119
120 /**
121 * Sets time taken for project
122 *
123 * @uses $time
124 * @param mixed time object time or string
125 * @see Time::Set() for allowed var-type of param date
126 * @return bool success
127 * @uses Time
128 */
129 function SetTime($time = null)
130 {
131 if ( null === $time )
132 {
133 $time = date('H:i');
134 }
135 $this->time = new Time($time);
136
137 return true;
138 }
139
140 /**
141 * Sets worker_id
142 *
143 * @param int worker_id
144 * @return bool success
145 * @uses $worker_id
146 */
147 function SetWorkerId($worker_id)
148 {
149 $this->worker_id = (int) $worker_id;
150 return true;
151 }
152
153 /**
154 * Sets project_id
155 *
156 * @param int project_id
157 * @return bool success
158 * @uses $project_id
159 */
160 function SetProjectId($project_id)
161 {
162 $this->project_id = (int) $project_id;
163 return true;
164 }
165
166 /**
167 * Sets company_id
168 *
169 * @param int company_id
170 * @return bool success
171 * @uses $company_id
172 */
173 function SetCompanyId($company_id)
174 {
175 $this->company_id = (int) $company_id;
176 return true;
177 }
178
179 /**
180 * Loads Object from Database
181 *
182 * @return bool success
183 * @uses GetWorkerId()
184 * @uses GetProjectId()
185 * @uses SetCompanyId()
186 * @uses SetTime()
187 * @uses $date
188 * @uses Date
189 * @uses Date::Get()
190 * @uses PTS_TBL_PROJECT_TIME
191 * @uses __FILE__
192 * @uses __LINE__
193 * @uses __CLASS__
194 * @uses __FUNCTION__
195 * @uses mysql_query()
196 * @uses mysql_fetch_assoc()
197 * @uses mysql_error()
198 */
199 function Load()
200 {
201 $sql = '
202 SELECT *
203 FROM `' . PTS_TBL_PROJECT_TIME . '`
204 WHERE `day` = "' . $this->date->Get() . '"
205 AND `worker` = ' . $this->GetWorkerId() . '
206 AND `project` = ' . $this->GetProjectId() . '
207 LIMIT 1';
208
209 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
210
211 $row = mysql_fetch_assoc($result);
212
213 $this->SetCompanyId($row['company']);
214 $this->SetTime($row['time']);
215
216 return true;
217 }
218
219 /**
220 * Saves Object to Database
221 *
222 * @return bool success
223 * @uses GetWorkerId()
224 * @uses GetProjectId()
225 * @uses GetCompanyId()
226 * @uses $time
227 * @uses $date
228 * @uses Date
229 * @uses Date::Get()
230 * @uses Time
231 * @uses Time::Get()
232 * @uses PTS_TBL_PROJECT_TIME
233 * @uses __FILE__
234 * @uses __LINE__
235 * @uses __CLASS__
236 * @uses __FUNCTION__
237 * @uses mysql_query()
238 * @uses mysql_error()
239 */
240 function Save()
241 {
242 $sql = '
243 REPLACE `' . PTS_TBL_PROJECT_TIME . '`
244 SET `day` = "' . $this->date->Get() . '",
245 `worker` = ' . $this->GetWorkerId() . ',
246 `project` = ' . $this->GetProjectId() . ',
247 `company` = ' . $this->GetCompanyId() . ',
248 `time` = "' . $this->time->Get() . '"';
249
250 $result = mysql_query($sql) or die('<pre>' . __FILE__ . ': ' . __LINE__ . "\n" . __CLASS__ . '::' . __FUNCTION__ . "\n" . $sql . "\n" . mysql_error());
251
252 return true;
253 }
254 }
255 ?>

Documentation generated on Fri, 26 Sep 2003 15:39:54 +0200 by phpDocumentor 1.2.2