Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
timesheet
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
web2project
timesheet
Commits
3f6e6356
Commit
3f6e6356
authored
Jan 22, 2014
by
Jean-Paul Saman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update and cleanup timesheet.class.php
parent
78011656
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
135 additions
and
86 deletions
+135
-86
timesheet.class.php
timesheet.class.php
+135
-86
No files found.
timesheet.class.php
View file @
3f6e6356
<?php
/*
* Copyright (C) 2007-20
08
, M2X
* Copyright (C) 2007-20
14
, M2X
*
* Authors: Jean-Paul Saman
*
...
...
@@ -19,76 +19,82 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
// use the dPFramework to have easy database operations (store, delete etc.) by using its ObjectOrientedDesign
// therefore we have to create a child class for the module timesheet
// a class named (like this) in the form: module/module.class.php is automatically loaded by the dPFramework
/**
* @package
dotP
roject
* @package
web2p
roject
* @subpackage modules
* @version $Revision:
1
.0 $
* @version $Revision:
2
.0 $
*/
// include the powerful parent class that we want to extend for timesheet
// use the dPFramework for easy inclusion of this class here
require_once
(
$AppUI
->
getSystemClass
(
'dp'
)
);
if
(
!
defined
(
'W2P_BASE_DIR'
))
{
die
(
'You should not access this file directly.'
);
}
/**
* The Timesheet Class
*/
class
CTimesheet
extends
CDp
Object
{
class
CTimesheet
extends
w2p_Core_Base
Object
{
// link variables to the timesheet object (according to the existing columns in the database table timesheet)
//use null for a new object, so the database automatically assigns an unique id by 'not null'-functionality
var
$timesheet_id
=
null
;
var
$timesheet_period
=
null
;
var
$timesheet_status
=
0
;
var
$timesheet_date
=
null
;
var
$timesheet_creator
=
null
;
var
$timesheet_worked
=
null
;
public
$timesheet_id
=
null
;
public
$timesheet_period
=
null
;
public
$timesheet_status
=
0
;
public
$timesheet_date
=
null
;
public
$timesheet_creator
=
null
;
public
$timesheet_worked
=
null
;
// the constructor of the CTimesheet class, always combined with the table name and the unique key of the table
function
CTimeshee
t
()
{
$this
->
CDpObject
(
'timesheet'
,
'timesheet_id'
);
public
function
__construc
t
()
{
parent
::
__construct
(
'timesheet'
,
'timesheet_id'
);
$this
->
timesheet_id
=
$_POST
[
"timesheet_id"
];
}
function
check
()
{
if
(
$this
->
timesheet_id
==
"0"
)
{
$this
->
init
();
public
function
isValid
()
{
$baseErrorMsg
=
get_class
(
$this
)
.
'::store-check failed -'
;
if
(
$this
->
timesheet_id
==
0
)
{
$this
->
_error
[
'timesheet_id'
]
=
$baseErrorMsg
.
'timesheet id not set'
;
}
return
NULL
;
return
(
count
(
$this
->
_error
))
?
false
:
true
;
}
public
function
loadFull
()
{
// loadFull information for this timesheet
}
function
init
()
{
$q
=
new
DB
Query
();
protected
function
init
()
{
$q
=
$this
->
_get
Query
();
$q
->
addTable
(
'timesheet'
);
$q
->
addInsert
(
'timesheet_period,timesheet_status,timesheet_date,timesheet_creator,timesheet_worked'
,
$_POST
[
'timesheet_period'
]
.
','
.
$_POST
[
'timesheet_status'
]
.
','
.
$_POST
[
'timesheet_date'
]
.
','
.
$_POST
[
'timesheet_creator'
]
.
','
.
$_POST
[
'timesheet_worked'
],
true
);
if
(
!
$q
->
exec
())
{
return
dberror
();
if
(
!
(
$q
->
exec
()))
{
$this
->
_error
[
'init-timesheet'
]
=
db_error
();
return
false
;
}
// TODO: move this to a postCreate hook
$this
->
timesheet_id
=
db_insert_id
();
return
true
;
}
function
project_purge
()
protected
function
project_purge
()
{
$q
=
new
DB
Query
();
$q
=
$this
->
_get
Query
();
$q
->
setDelete
(
'timesheet_project'
);
$q
->
addWhere
(
'timesheet_id = '
.
$this
->
timesheet_id
);
if
(
!
$q
->
exec
())
return
db_error
();
$q
->
addWhere
(
'timesheet_id = '
.
$this
->
timesheet_id
);
if
(
!
(
$q
->
exec
()))
{
$this
->
_error
[
'project-purge-timesheet'
]
=
db_error
();
return
false
;
}
return
true
;
}
function
project_store
()
protected
function
project_store
()
{
// Get the current timesheet period
$period
=
new
CDate
(
);
$period
->
setDate
(
$_POST
[
'timesheet_period'
],
DATE_FORMAT_UNIXTIME
);
$period
=
new
w2p_UtilitiesDate
(
$_POST
[
'timesheet_period'
]
);
//
$period->setDate($_POST['timesheet_period'],DATE_FORMAT_UNIXTIME);
$q
=
new
DB
Query
();
$q
=
$this
->
_get
Query
();
$q
->
addQuery
(
'project_id'
);
$q
->
addQuery
(
'project_name'
);
$q
->
addQuery
(
'project_status'
);
...
...
@@ -96,7 +102,7 @@ class CTimesheet extends CDpObject {
$q
->
addOrder
(
'project_name ASC'
);
$projects
=
$q
->
LoadList
();
foreach
(
$projects
as
$row
)
{
$t
=
new
DBQuery
;
$t
=
$this
->
_getQuery
()
;
$t
->
addQuery
(
'task_id'
);
$t
->
addQuery
(
'task_name'
);
$t
->
addQuery
(
'task_owner'
);
...
...
@@ -126,7 +132,7 @@ class CTimesheet extends CDpObject {
foreach
(
$log
as
$logitem
)
{
if
(
intval
(
$logitem
[
'task_log_date'
]))
{
$taskDate
=
new
C
Date
(
$logitem
[
'task_log_date'
]);
$taskDate
=
new
w2p_Utilities_
Date
(
$logitem
[
'task_log_date'
]);
if
(
$period
->
GetMonth
()
==
$taskDate
->
GetMonth
())
{
$amount
=
$amount
+
$logitem
[
"task_log_hours"
];
}
...
...
@@ -134,83 +140,126 @@ class CTimesheet extends CDpObject {
}
}
}
$sheet
=
new
DB
Query
();
$sheet
=
$this
->
_get
Query
();
$sheet
->
addTable
(
'timesheet_project'
);
$sheet
->
addInsert
(
'timesheet_id,timesheet_project,timesheet_project_amount'
,
$this
->
timesheet_id
.
','
.
$row
[
"project_id"
]
.
','
.
$amount
,
true
);
if
(
!
$sheet
->
exec
())
{
return
db_error
();
if
(
!
(
$q
->
exec
()))
{
$this
->
_error
[
'project-purge-timesheet'
]
=
db_error
();
return
false
;
}
}
return
true
;
}
function
store
()
{
if
(
$this
->
timesheet_id
!=
0
)
{
$this
->
_action
=
'updated'
;
$q
=
new
DBQuery
();
public
function
store
(
$unused
=
null
)
{
$this
->
clearErrors
();
if
(
$this
->
timesheet_id
!=
0
&&
$this
->
canEdit
())
{
$this
->
_action
=
'updated'
;
// FIXME: still needed??
$q
=
$this
->
_getQuery
();
$q
->
addTable
(
'timesheet'
);
$q
->
addUpdate
(
'timesheet_worked'
,
$this
->
timesheet_worked
);
$q
->
addWhere
(
'timesheet_id = '
.
$this
->
timesheet_id
);
if
(
!
$q
->
exec
())
{
return
db_error
();
if
(
!
(
$q
->
exec
()))
{
$this
->
_error
[
'update-timesheet'
]
=
db_error
();
return
false
;
}
return
true
;
}
else
{
$q
=
new
DBQuery
;
else
if
(
$this
->
canCreate
())
{
$q
=
$this
->
_getQuery
()
;
$q
->
addTable
(
'timesheet'
);
$q
->
addInsert
(
'timesheet_period,timesheet_status,timesheet_date,timesheet_creator,timesheet_worked'
,
$this
->
timesheet_period
.
','
.
$this
->
timesheet_status
.
','
.
$this
->
timesheet_date
.
','
.
$this
->
timesheet_creator
.
','
.
$this
->
timesheet_worked
,
true
);
if
(
!
$q
->
exec
())
return
db_error
();
if
(
!
(
$q
->
exec
()))
{
$this
->
_error
[
'store-timesheet'
]
=
db_error
();
return
false
;
}
return
true
;
}
return
false
;
}
// overload the delete method of the parent class for adaptation for timesheet's needs
function
delete
()
{
$q
=
new
DBQuery
();
$q
->
setDelete
(
'timesheet_project'
);
$q
->
addWhere
(
'timesheet_id = '
.
$this
->
timesheet_id
);
if
(
!
$q
->
exec
())
{
return
db_error
();
public
function
delete
(
$unused
=
null
)
{
$this
->
clearErrors
();
if
(
$this
->
canDelete
())
{
$q
=
$this
->
_getQuery
();
$q
->
setDelete
(
'timesheet_project'
);
$q
->
addWhere
(
'timesheet_id = '
.
$this
->
timesheet_id
);
if
(
!
(
$q
->
exec
()))
{
$this
->
_error
[
'delete-timesheet-project'
]
=
db_error
();
return
false
;
}
$q
->
clear
();
$q
->
setDelete
(
'timesheet'
);
$q
->
addWhere
(
'timesheet_id = '
.
$this
->
timesheet_id
);
if
(
!
(
$q
->
exec
()))
{
$this
->
_error
[
'delete-timesheet'
]
=
db_error
();
return
false
;
}
return
true
;
}
$q
->
clear
();
$q
->
setDelete
(
'timesheet'
);
$q
->
addWhere
(
'timesheet_id = '
.
$this
->
timesheet_id
);
if
(
!
$q
->
exec
())
{
return
db_error
();
}
else
{
return
NULL
;
return
false
;
}
public
function
change_status
()
{
$this
->
clearErrors
();
if
(
$this
->
canEdit
())
{
$this
->
_action
=
'updated'
;
$q
=
$this
->
_getQuery
();
$q
->
addTable
(
'timesheet'
);
$q
->
addUpdate
(
'timesheet_status'
,
$this
->
timesheet_status
);
$q
->
addWhere
(
'timesheet_id = '
.
$this
->
timesheet_id
);
if
(
!
(
$q
->
exec
()))
{
$this
->
_error
[
'change-status-timesheet'
]
=
db_error
();
return
false
;
}
return
true
;
}
return
false
;
}
function
change_status
()
{
$msg
=
$this
->
check
();
$this
->
_action
=
'updated'
;
$q
=
new
DBQuery
();
$q
->
addTable
(
'timesheet'
);
$q
->
addUpdate
(
'timesheet_status'
,
$this
->
timesheet_status
);
$q
->
addWhere
(
'timesheet_id = '
.
$this
->
timesheet_id
);
if
(
!
$q
->
exec
())
{
return
db_error
();
public
function
change_period
(
$period
)
{
$result
=
false
;
$this
->
clearErrors
();
if
(
$this
->
canEdit
())
{
$this
->
_action
=
'updated'
;
$q
=
$this
->
_getQuery
();
$q
->
addTable
(
'timesheet'
);
$q
->
addUpdate
(
'timesheet_period'
,
$period
);
$q
->
addWhere
(
'timesheet_id = '
.
$this
->
timesheet_id
);
if
(
!
(
$q
->
exec
()))
{
$this
->
_error
[
'change-period-timesheet'
]
=
db_error
();
return
$result
;
}
$result
=
true
;
$purge_result
=
$this
->
project_purge
();
$store_result
=
$this
->
project_store
();
$result
=
$result
&&
$purge_result
&&
$store_result
;
}
return
$result
;
}
function
change_period
(
$period
)
{
$msg
=
$this
->
check
();
$this
->
_action
=
'updated'
;
$q
=
new
DBQuery
();
$q
->
addTable
(
'timesheet'
);
$q
->
addUpdate
(
'timesheet_period'
,
$period
);
$q
->
addWhere
(
'timesheet_id = '
.
$this
->
timesheet_id
);
public
function
get_config
()
{
// Read values from table
$config
=
null
;
$q
=
$this
->
_getQuery
();
$q
->
addQuery
(
'*'
);
$q
->
addTable
(
'timesheet_config'
);
if
(
!
$q
->
exec
())
{
return
db_error
();
$AppUI
->
setMsg
(
db_error
(),
UI_MSG_ERROR
);
return
$config
;
}
$this
->
project_purge
();
$this
->
project_store
();
while
(
$row
=
$q
->
fetchRow
())
{
$config
[
$row
[
'timesheet_config'
]]
=
$row
[
'timesheet_value'
];
}
$q
->
clear
();
return
$config
;
}
}
?>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment