Issues (4868)

timesheet/inc/class.timesheet_datasource.inc.php (14 issues)

1
<?php
2
/**
3
 * TimeSheet - Projectmanager datasource
4
 *
5
 * @link http://www.egroupware.org
6
 * @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
7
 * @package timesheet
8
 * @copyright (c) 2005-16 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
9
 * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
10
 * @version $Id$
11
 */
12
use EGroupware\Api\Link;
13
use EGroupware\Api\Acl;
14
15
include_once(EGW_INCLUDE_ROOT.'/projectmanager/inc/class.datasource.inc.php');
16
17
/**
18
 * Projectmanager DataSource for the TimeSheet
19
 */
20
class timesheet_datasource extends datasource
0 ignored issues
show
The type datasource was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
21
{
22
	/**
23
	 * Constructor
24
	 */
25
	function __construct()
26
	{
27
		parent::__construct(TIMESHEET_APP);
28
29
		$this->valid = PM_REAL_START|PM_REAL_END|PM_USED_TIME|PM_USED_BUDGET|PM_USED_QUANTITY|
0 ignored issues
show
The constant PM_USED_BUDGET was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
The constant PM_REAL_END was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
The constant PM_REAL_START was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
The constant PM_USED_TIME was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug Best Practice introduced by
The property valid does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
The constant PM_USED_QUANTITY was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
30
			PM_PRICELIST_ID|PM_UNITPRICE|PM_RESOURCES|PM_DETAILS|PM_COMPLETION|PM_CAT_ID;
0 ignored issues
show
The constant PM_DETAILS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
The constant PM_CAT_ID was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
The constant PM_PRICELIST_ID was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
The constant PM_COMPLETION was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
The constant PM_RESOURCES was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
The constant PM_UNITPRICE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
31
	}
32
33
	/**
34
	 * get an entry from the underlaying app (if not given) and convert it into a datasource array
35
	 *
36
	 * @param mixed $data_id id as used in the link-class for that app, or complete entry as array
37
	 * @return array/boolean array with the data supported by that source or false on error (eg. not found, not availible)
0 ignored issues
show
Documentation Bug introduced by
The doc comment array/boolean at position 0 could not be parsed: Unknown type name 'array/boolean' at position 0 in array/boolean.
Loading history...
38
	 */
39
	function get($data_id)
40
	{
41
		// we use $GLOBALS['timesheet_bo'] as an already running instance is availible there
42
		if (!is_object($GLOBALS['timesheet_bo']))
43
		{
44
			$GLOBALS['timesheet_bo'] = new timesheet_bo();
45
		}
46
		if (!is_array($data_id))
47
		{
48
			if (!(int) $data_id || !($data = $GLOBALS['timesheet_bo']->read((int) $data_id)))
49
			{
50
				return false;
51
			}
52
		}
53
		else
54
		{
55
			$data =& $data_id;
56
		}
57
		$ds = array(
58
			'pe_title'       => $GLOBALS['timesheet_bo']->link_title($data),
59
			'pe_real_start'  => $data['ts_start'],
60
			'pe_resources'   => array($data['ts_owner']),
61
			'pe_details'     => $data['ts_description'] ? nl2br($data['ts_description']) : '',
62
			'pl_id'          => $data['pl_id'],
63
			'pe_unitprice'   => $data['ts_unitprice'],
64
			'pe_used_quantity' => $data['ts_quantity'],
65
			'pe_used_budget' => $data['ts_quantity'] * (float)$data['ts_unitprice'],
66
			'pe_completion'  => 100,
67
			'cat_id'         => $data['cat_id'],
68
		);
69
		if ($data['ts_duration'])
70
		{
71
			$ds['pe_real_end'] = $data['ts_start'] + 60*$data['ts_duration'];
72
			$ds['pe_used_time'] = $data['ts_duration'];
73
		}
74
		if ($this->debug)
75
		{
76
			echo "datasource_timesheet($data_id) data="; _debug_array($data);
77
			echo "datasource="; _debug_array($ds);
78
		}
79
		return $ds;
80
	}
81
82
	/**
83
	 * Copy method (usally copies a projectelement) returns only false to prevent copying
84
	 *
85
	 * @param array $element source project element representing an InfoLog entry, $element['pe_app_id'] = info_id
86
	 * @param int $target target project id
87
	 * @param array $extra =null data of target-project, atm not used by the infolog datasource
88
	 * @return array|boolean array(info_id,link_id) on success, false otherwise
89
	 */
90
	function copy($element,$target,$extra=null)
91
	{
92
		unset($element,$target,$extra);	// not used, but required by function signature
93
94
		return false;
95
	}
96
97
	/**
98
	 * Delete the datasource of a project element
99
	 *
100
	 * @param int $id
101
	 * @return boolean true on success, false on error
102
	 */
103
	function delete($id)
104
	{
105
		if (!is_object($GLOBALS['timesheet_bo']))
106
		{
107
			$GLOBALS['timesheet_bo'] = new timesheet_bo();
108
		}
109
		// dont delete entries which are linked to elements other than their project
110
		if (count(Link::get_links('timesheet',$id)) > 1)
111
		{
112
			return false;
113
		}
114
		return $GLOBALS['timesheet_bo']->delete($id);
115
	}
116
117
	/**
118
	 * Change the status of an entry according to the project status
119
	 *
120
	 * @param int $id
121
	 * @param string $status
122
	 * @return boolean true if status changed, false otherwise
123
	 */
124
	function change_status($id,$status)
125
	{
126
		if (!is_object($GLOBALS['timesheet_bo']))
127
		{
128
			$GLOBALS['timesheet_bo'] = new timesheet_bo();
129
		}
130
		if (($entry = $GLOBALS['timesheet_bo']->read($id)) && (
131
				$GLOBALS['timesheet_bo']->check_acl(Acl::EDIT,$entry)
132
		))
133
		{
134
			if (in_array($status, $GLOBALS['timesheet_bo']->status_labels))
135
			{
136
				$GLOBALS['timesheet_bo']->set_status($id, $status);
137
				return true;
138
			}
139
			// Restore from deleted
140
			else if ($status == 'active' && $entry['ts_status'] == timesheet_bo::DELETED_STATUS)
141
			{
142
				$GLOBALS['timesheet_bo']->set_status($id, '');
143
				return true;
144
			}
145
		}
146
		return false;
147
	}
148
}
149