|
1
|
|
|
<?php |
|
2
|
1 |
|
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
3
|
|
|
/********************************************************************************* |
|
4
|
|
|
* SugarCRM Community Edition is a customer relationship management program developed by |
|
5
|
|
|
* SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc. |
|
6
|
|
|
|
|
7
|
|
|
* SuiteCRM is an extension to SugarCRM Community Edition developed by Salesagility Ltd. |
|
8
|
|
|
* Copyright (C) 2011 - 2014 Salesagility Ltd. |
|
9
|
|
|
* |
|
10
|
|
|
* This program is free software; you can redistribute it and/or modify it under |
|
11
|
|
|
* the terms of the GNU Affero General Public License version 3 as published by the |
|
12
|
|
|
* Free Software Foundation with the addition of the following permission added |
|
13
|
|
|
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK |
|
14
|
|
|
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY |
|
15
|
|
|
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS. |
|
16
|
|
|
* |
|
17
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT |
|
18
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
19
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more |
|
20
|
|
|
* details. |
|
21
|
|
|
* |
|
22
|
|
|
* You should have received a copy of the GNU Affero General Public License along with |
|
23
|
|
|
* this program; if not, see http://www.gnu.org/licenses or write to the Free |
|
24
|
|
|
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
25
|
|
|
* 02110-1301 USA. |
|
26
|
|
|
* |
|
27
|
|
|
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road, |
|
28
|
|
|
* SW2-130, Cupertino, CA 95014, USA. or at email address [email protected]. |
|
29
|
|
|
* |
|
30
|
|
|
* The interactive user interfaces in modified source and object code versions |
|
31
|
|
|
* of this program must display Appropriate Legal Notices, as required under |
|
32
|
|
|
* Section 5 of the GNU Affero General Public License version 3. |
|
33
|
|
|
* |
|
34
|
|
|
* In accordance with Section 7(b) of the GNU Affero General Public License version 3, |
|
35
|
|
|
* these Appropriate Legal Notices must retain the display of the "Powered by |
|
36
|
|
|
* SugarCRM" logo and "Supercharged by SuiteCRM" logo. If the display of the logos is not |
|
37
|
|
|
* reasonably feasible for technical reasons, the Appropriate Legal Notices must |
|
38
|
|
|
* display the words "Powered by SugarCRM" and "Supercharged by SuiteCRM". |
|
39
|
|
|
********************************************************************************/ |
|
40
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
class Project extends SugarBean { |
|
43
|
|
|
// database table columns |
|
44
|
|
|
var $id; |
|
45
|
|
|
var $date_entered; |
|
46
|
|
|
var $date_modified; |
|
47
|
|
|
var $assigned_user_id; |
|
48
|
|
|
var $modified_user_id; |
|
49
|
|
|
var $created_by; |
|
50
|
|
|
var $name; |
|
51
|
|
|
var $description; |
|
52
|
|
|
var $deleted; |
|
53
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
// related information |
|
56
|
|
|
var $assigned_user_name; |
|
57
|
|
|
var $modified_by_name; |
|
58
|
|
|
var $created_by_name; |
|
59
|
|
|
|
|
60
|
|
|
var $account_id; |
|
61
|
|
|
var $contact_id; |
|
62
|
|
|
var $opportunity_id; |
|
63
|
|
|
var $email_id; |
|
64
|
|
|
var $estimated_start_date; |
|
65
|
|
|
|
|
66
|
|
|
// calculated information |
|
67
|
|
|
var $total_estimated_effort; |
|
68
|
|
|
var $total_actual_effort; |
|
69
|
|
|
|
|
70
|
|
|
var $object_name = 'Project'; |
|
71
|
|
|
var $module_dir = 'Project'; |
|
72
|
|
|
var $new_schema = true; |
|
73
|
|
|
var $table_name = 'project'; |
|
74
|
|
|
|
|
75
|
|
|
// This is used to retrieve related fields from form posts. |
|
76
|
|
|
var $additional_column_fields = array( |
|
77
|
|
|
'account_id', |
|
78
|
|
|
'contact_id', |
|
79
|
|
|
'opportunity_id', |
|
80
|
|
|
); |
|
81
|
|
|
|
|
82
|
|
|
var $relationship_fields = array( |
|
83
|
|
|
'account_id' => 'accounts', |
|
84
|
|
|
'contact_id'=>'contacts', |
|
85
|
|
|
'opportunity_id'=>'opportunities', |
|
86
|
|
|
'email_id' => 'emails', |
|
87
|
|
|
); |
|
88
|
|
|
|
|
89
|
|
|
////////////////////////////////////////////////////////////////// |
|
90
|
|
|
// METHODS |
|
91
|
|
|
////////////////////////////////////////////////////////////////// |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* |
|
95
|
|
|
*/ |
|
96
|
25 |
|
public function __construct() |
|
97
|
|
|
{ |
|
98
|
25 |
|
parent::__construct(); |
|
99
|
25 |
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* @deprecated deprecated since version 7.6, PHP4 Style Constructors are deprecated and will be remove in 7.8, please update your code, use __construct instead |
|
103
|
|
|
*/ |
|
104
|
|
|
public function Project(){ |
|
105
|
|
|
$deprecatedMessage = 'PHP4 Style Constructors are deprecated and will be remove in 7.8, please update your code'; |
|
106
|
|
|
if(isset($GLOBALS['log'])) { |
|
107
|
|
|
$GLOBALS['log']->deprecated($deprecatedMessage); |
|
108
|
|
|
} |
|
109
|
|
|
else { |
|
110
|
|
|
trigger_error($deprecatedMessage, E_USER_DEPRECATED); |
|
111
|
|
|
} |
|
112
|
|
|
self::__construct(); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* overriding the base class function to do a join with users table |
|
118
|
|
|
*/ |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* |
|
122
|
|
|
*/ |
|
123
|
1 |
|
function fill_in_additional_detail_fields() |
|
124
|
|
|
{ |
|
125
|
1 |
|
parent::fill_in_additional_detail_fields(); |
|
126
|
|
|
|
|
127
|
1 |
|
$this->assigned_user_name = get_assigned_user_name($this->assigned_user_id); |
|
128
|
|
|
//$this->total_estimated_effort = $this->_get_total_estimated_effort($this->id); |
|
129
|
|
|
//$this->total_actual_effort = $this->_get_total_actual_effort($this->id); |
|
130
|
1 |
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* |
|
134
|
|
|
*/ |
|
135
|
1 |
|
function fill_in_additional_list_fields() |
|
136
|
|
|
{ |
|
137
|
1 |
|
parent::fill_in_additional_list_fields(); |
|
138
|
1 |
|
$this->assigned_user_name = get_assigned_user_name($this->assigned_user_id); |
|
139
|
|
|
//$this->total_estimated_effort = $this->_get_total_estimated_effort($this->id); |
|
140
|
|
|
//$this->total_actual_effort = $this->_get_total_actual_effort($this->id); |
|
141
|
1 |
|
} |
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* Save changes that have been made to a relationship. |
|
145
|
|
|
* |
|
146
|
|
|
* @param $is_update true if this save is an update. |
|
147
|
|
|
*/ |
|
148
|
1 |
|
function save_relationship_changes($is_update, $exclude=array()) |
|
149
|
|
|
{ |
|
150
|
1 |
|
parent::save_relationship_changes($is_update, $exclude); |
|
151
|
1 |
|
$new_rel_id = false; |
|
152
|
1 |
|
$new_rel_link = false; |
|
153
|
|
|
//this allows us to dynamically relate modules without adding it to the relationship_fields array |
|
154
|
1 |
|
if(!empty($_REQUEST['relate_id']) && !in_array($_REQUEST['relate_to'], $exclude) && $_REQUEST['relate_id'] != $this->id){ |
|
155
|
1 |
|
$new_rel_id = $_REQUEST['relate_id']; |
|
156
|
1 |
|
$new_rel_relname = $_REQUEST['relate_to']; |
|
157
|
1 |
|
if(!empty($this->in_workflow) && !empty($this->not_use_rel_in_req)) { |
|
158
|
|
|
$new_rel_id = $this->new_rel_id; |
|
159
|
|
|
$new_rel_relname = $this->new_rel_relname; |
|
160
|
|
|
} |
|
161
|
1 |
|
$new_rel_link = $new_rel_relname; |
|
162
|
|
|
//Try to find the link in this bean based on the relationship |
|
163
|
1 |
|
foreach ( $this->field_defs as $key => $def ) { |
|
164
|
1 |
|
if (isset($def['type']) && $def['type'] == 'link' |
|
165
|
1 |
|
&& isset($def['relationship']) && $def['relationship'] == $new_rel_relname) { |
|
166
|
1 |
|
$new_rel_link = $key; |
|
167
|
|
|
} |
|
168
|
|
|
} |
|
169
|
1 |
|
if ($new_rel_link == 'contacts') { |
|
170
|
1 |
|
$accountId = $this->db->getOne('SELECT account_id FROM accounts_contacts WHERE contact_id=' . $this->db->quoted($new_rel_id)); |
|
171
|
1 |
|
if ($accountId !== false) { |
|
172
|
|
|
if($this->load_relationship('accounts')){ |
|
173
|
|
|
$this->accounts->add($accountId); |
|
174
|
|
|
} |
|
175
|
|
|
} |
|
176
|
|
|
} |
|
177
|
|
|
} |
|
178
|
1 |
|
} |
|
179
|
|
|
/** |
|
180
|
|
|
* |
|
181
|
|
|
*/ |
|
182
|
|
|
function _get_total_estimated_effort($project_id) |
|
183
|
|
|
{ |
|
184
|
|
|
$return_value = ''; |
|
185
|
|
|
|
|
186
|
|
|
$query = 'SELECT SUM('.$this->db->convert('estimated_effort', "IFNULL", 0).') total_estimated_effort'; |
|
187
|
|
|
$query.= ' FROM project_task'; |
|
188
|
|
|
$query.= " WHERE parent_id='{$project_id}' AND deleted=0"; |
|
189
|
|
|
|
|
190
|
|
|
$result = $this->db->query($query,true," Error filling in additional detail fields: "); |
|
191
|
|
|
$row = $this->db->fetchByAssoc($result); |
|
192
|
|
|
if($row != null) |
|
193
|
|
|
{ |
|
194
|
|
|
$return_value = $row['total_estimated_effort']; |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
return $return_value; |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
/** |
|
201
|
|
|
* |
|
202
|
|
|
*/ |
|
203
|
|
|
function _get_total_actual_effort($project_id) |
|
204
|
|
|
{ |
|
205
|
|
|
$return_value = ''; |
|
206
|
|
|
|
|
207
|
|
|
$query = 'SELECT SUM('.$this->db->convert('actual_effort', "IFNULL", 0).') total_actual_effort'; |
|
208
|
|
|
$query.= ' FROM project_task'; |
|
209
|
|
|
$query.= " WHERE parent_id='{$project_id}' AND deleted=0"; |
|
210
|
|
|
|
|
211
|
|
|
$result = $this->db->query($query,true," Error filling in additional detail fields: "); |
|
212
|
|
|
$row = $this->db->fetchByAssoc($result); |
|
213
|
|
|
if($row != null) |
|
214
|
|
|
{ |
|
215
|
|
|
$return_value = $row['total_actual_effort']; |
|
216
|
|
|
} |
|
217
|
|
|
|
|
218
|
|
|
return $return_value; |
|
219
|
|
|
} |
|
220
|
|
|
|
|
221
|
|
|
/** |
|
222
|
|
|
* |
|
223
|
|
|
*/ |
|
224
|
1 |
|
function get_summary_text() |
|
225
|
|
|
{ |
|
226
|
1 |
|
return $this->name; |
|
227
|
|
|
} |
|
228
|
|
|
|
|
229
|
|
|
/** |
|
230
|
|
|
* |
|
231
|
|
|
*/ |
|
232
|
1 |
|
function build_generic_where_clause ($the_query_string) |
|
233
|
|
|
{ |
|
234
|
1 |
|
$where_clauses = array(); |
|
235
|
1 |
|
$the_query_string = $GLOBALS['db']->quote($the_query_string); |
|
236
|
1 |
|
array_push($where_clauses, "project.name LIKE '%$the_query_string%'"); |
|
237
|
|
|
|
|
238
|
1 |
|
$the_where = ''; |
|
239
|
1 |
|
foreach($where_clauses as $clause) |
|
240
|
|
|
{ |
|
241
|
1 |
|
if($the_where != '') $the_where .= " OR "; |
|
242
|
1 |
|
$the_where .= $clause; |
|
243
|
|
|
} |
|
244
|
|
|
|
|
245
|
1 |
|
return $the_where; |
|
246
|
|
|
} |
|
247
|
|
|
|
|
248
|
|
|
function get_list_view_data() |
|
249
|
|
|
{ |
|
250
|
|
|
$field_list = $this->get_list_view_array(); |
|
251
|
|
|
$field_list['USER_NAME'] = empty($this->user_name) ? '' : $this->user_name; |
|
252
|
|
|
$field_list['ASSIGNED_USER_NAME'] = $this->assigned_user_name; |
|
253
|
|
|
return $field_list; |
|
254
|
|
|
} |
|
255
|
25 |
|
function bean_implements($interface){ |
|
256
|
|
|
switch($interface){ |
|
257
|
25 |
|
case 'ACL':return true; |
|
|
|
|
|
|
258
|
|
|
} |
|
259
|
1 |
|
return false; |
|
260
|
|
|
} |
|
261
|
|
|
|
|
262
|
1 |
|
function create_export_query($order_by, $where, $relate_link_join='') |
|
263
|
|
|
{ |
|
264
|
1 |
|
$custom_join = $this->getCustomJoin(true, true, $where); |
|
265
|
1 |
|
$custom_join['join'] .= $relate_link_join; |
|
266
|
|
|
$query = "SELECT |
|
267
|
|
|
project.*, |
|
268
|
1 |
|
users.user_name as assigned_user_name "; |
|
269
|
1 |
|
$query .= $custom_join['select']; |
|
270
|
1 |
|
$query .= " FROM project "; |
|
271
|
|
|
|
|
272
|
1 |
|
$query .= $custom_join['join']; |
|
273
|
|
|
$query .= " LEFT JOIN users |
|
274
|
1 |
|
ON project.assigned_user_id=users.id "; |
|
275
|
|
|
|
|
276
|
1 |
|
$where_auto = " project.deleted=0 "; |
|
277
|
|
|
|
|
278
|
1 |
|
if($where != "") |
|
279
|
1 |
|
$query .= "where ($where) AND ".$where_auto; |
|
280
|
|
|
else |
|
281
|
1 |
|
$query .= "where ".$where_auto; |
|
282
|
|
|
|
|
283
|
1 |
|
if(!empty($order_by)){ |
|
284
|
|
|
//check to see if order by variable already has table name by looking for dot "." |
|
285
|
1 |
|
$table_defined_already = strpos($order_by, "."); |
|
286
|
|
|
|
|
287
|
1 |
|
if($table_defined_already === false){ |
|
288
|
|
|
//table not defined yet, define accounts to avoid "ambigous column" SQL error |
|
289
|
|
|
$query .= " ORDER BY $order_by"; |
|
290
|
|
|
}else{ |
|
291
|
|
|
//table already defined, just add it to end of query |
|
292
|
1 |
|
$query .= " ORDER BY $order_by"; |
|
293
|
|
|
} |
|
294
|
|
|
} |
|
295
|
1 |
|
return $query; |
|
296
|
|
|
} |
|
297
|
1 |
|
function getAllProjectTasks(){ |
|
298
|
1 |
|
$projectTasks = array(); |
|
299
|
|
|
|
|
300
|
1 |
|
$query = "SELECT * FROM project_task WHERE project_id = '" . $this->id. "' AND deleted = 0 ORDER BY project_task_id"; |
|
301
|
1 |
|
$result = $this->db->query($query,true,"Error retrieving project tasks"); |
|
302
|
1 |
|
$row = $this->db->fetchByAssoc($result); |
|
303
|
|
|
|
|
304
|
1 |
|
while ($row != null){ |
|
305
|
|
|
$projectTaskBean = new ProjectTask(); |
|
306
|
|
|
$projectTaskBean->id = $row['id']; |
|
307
|
|
|
$projectTaskBean->retrieve(); |
|
308
|
|
|
array_push($projectTasks, $projectTaskBean); |
|
309
|
|
|
|
|
310
|
|
|
$row = $this->db->fetchByAssoc($result); |
|
311
|
|
|
} |
|
312
|
|
|
|
|
313
|
1 |
|
return $projectTasks; |
|
314
|
|
|
} |
|
315
|
|
|
} |
|
316
|
|
|
?> |
|
317
|
|
|
|
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.