]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/ProjectTask/ProjectTask.php
Release 6.2.0
[Github/sugarcrm.git] / modules / ProjectTask / ProjectTask.php
1 <?php
2 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-2011 SugarCRM Inc.
6  * 
7  * This program is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU Affero General Public License version 3 as published by the
9  * Free Software Foundation with the addition of the following permission added
10  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13  * 
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
17  * details.
18  * 
19  * You should have received a copy of the GNU Affero General Public License along with
20  * this program; if not, see http://www.gnu.org/licenses or write to the Free
21  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22  * 02110-1301 USA.
23  * 
24  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26  * 
27  * The interactive user interfaces in modified source and object code versions
28  * of this program must display Appropriate Legal Notices, as required under
29  * Section 5 of the GNU Affero General Public License version 3.
30  * 
31  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32  * these Appropriate Legal Notices must retain the display of the "Powered by
33  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34  * technical reasons, the Appropriate Legal Notices must display the words
35  * "Powered by SugarCRM".
36  ********************************************************************************/
37
38
39
40
41
42
43
44
45
46
47
48
49
50 class ProjectTask extends SugarBean {
51         // database table columns
52         var $id;
53         var $date_entered;
54         var $date_modified;
55         //var $assigned_user_id;
56         //var $modified_user_id;
57         //var $created_by;
58         var $name;
59     var $description;
60     var $project_id;
61     var $project_task_id;
62     var $date_start;
63     var $date_finish;
64     var $duration;
65     var $duration_unit;
66     var $percent_complete;
67     var $parent_task_id;
68     var $predecessors;
69     var $priority;
70
71         // related information
72         var $assigned_user_name;
73         var $parent_name;
74         var $depends_on_name;
75         var $email_id;
76
77         var $table_name = 'project_task';
78         var $object_name = 'ProjectTask';
79         var $module_dir = 'ProjectTask';
80
81         var $field_name_map;
82         var $new_schema = true;
83
84         var $relationship_fields = array(
85                 'email_id' => 'emails',
86         );
87
88         //////////////////////////////////////////////////////////////////
89         // METHODS
90         //////////////////////////////////////////////////////////////////
91
92         /*
93          *
94          */
95         function ProjectTask($init=true)
96         {
97                 parent::SugarBean();
98                 if ($init) {
99                         // default value for a clean instantiation
100                         $this->utilization = 100;
101         
102                         global $current_user;
103                         if(empty($current_user))
104                         {
105                                 $this->assigned_user_id = 1;
106                                 $admin_user = new User();
107                                 $admin_user->retrieve($this->assigned_user_id);
108                                 $this->assigned_user_name = $admin_user->user_name;
109                         }
110                         else
111                         {
112                                 $this->assigned_user_id = $current_user->id;
113                                 $this->assigned_user_name = $current_user->user_name;
114                         }
115                         
116                 }
117         }
118         
119         function save($check_notify = FALSE){
120                 $id = parent::save($check_notify);
121         return $id;
122         }
123         
124         /**
125          * overriding the base class function to do a join with users table
126          */
127
128         /*
129          *
130          */
131    function fill_in_additional_detail_fields()
132    {
133       $this->assigned_user_name = get_assigned_user_name($this->assigned_user_id);
134       $this->project_name = $this->_get_project_name($this->project_id);
135                 /*
136         $this->depends_on_name = $this->_get_depends_on_name($this->depends_on_id);
137                 if(empty($this->depends_on_name))
138                 {
139                         $this->depends_on_id = '';
140                 }
141                 $this->parent_name = $this->_get_parent_name($this->parent_id);
142                 if(empty($this->parent_name))
143                 {
144                         $this->parent_id = '';
145                 }
146         */
147    }
148
149         /*
150          *
151          */
152    function fill_in_additional_list_fields()
153    {
154       $this->assigned_user_name = get_assigned_user_name($this->assigned_user_id);
155       //$this->parent_name = $this->_get_parent_name($this->parent_id);
156       $this->project_name = $this->_get_project_name($this->project_id);
157    }
158
159         /*
160          *
161          */
162         function get_summary_text()
163         {
164                 return $this->name;
165         }
166
167         /*
168          *
169          */
170         function _get_depends_on_name($depends_on_id)
171         {
172                 $return_value = '';
173
174                 $query  = "SELECT name, assigned_user_id FROM {$this->table_name} WHERE id='{$depends_on_id}'";
175                 $result = $this->db->query($query,true," Error filling in additional detail fields: ");
176                 $row = $this->db->fetchByAssoc($result);
177                 if($row != null)
178                 {
179                         $this->depends_on_name_owner = $row['assigned_user_id'];
180                         $this->depends_on_name_mod = 'ProjectTask';
181                         $return_value = $row['name'];
182                 }
183
184                 return $return_value;
185         }
186
187     function _get_project_name($project_id)
188     {
189         $return_value = '';
190
191         $query  = "SELECT name, assigned_user_id FROM project WHERE id='{$project_id}'";
192         $result = $this->db->query($query,true," Error filling in additional detail fields: ");
193         $row = $this->db->fetchByAssoc($result);
194         if($row != null)
195         {
196             //$this->parent_name_owner = $row['assigned_user_id'];
197             //$this->parent_name_mod = 'Project';
198             $return_value = $row['name'];
199         }
200
201         return $return_value;
202     }
203         /*
204          *
205          */
206         function _get_parent_name($parent_id)
207         {
208                 $return_value = '';
209
210                 $query  = "SELECT name, assigned_user_id FROM project WHERE id='{$parent_id}'";
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                         $this->parent_name_owner = $row['assigned_user_id'];
216                         $this->parent_name_mod = 'Project';
217                         $return_value = $row['name'];
218                 }
219
220                 return $return_value;
221         }
222
223         /*
224          *
225          */
226         function build_generic_where_clause ($the_query_string)
227         {
228                 $where_clauses = array();
229                 $the_query_string = $GLOBALS['db']->quote($the_query_string);
230                 array_push($where_clauses, "project_task.name like '$the_query_string%'");
231
232                 $the_where = "";
233                 foreach($where_clauses as $clause)
234                 {
235                         if($the_where != "") $the_where .= " or ";
236                         $the_where .= $clause;
237                 }
238
239                 return $the_where;
240         }
241
242         function get_list_view_data(){
243                 global $action, $currentModule, $focus, $current_module_strings, $app_list_strings, $timedate, $locale;
244                 $today = $timedate->handle_offset(date($GLOBALS['timedate']->get_db_date_time_format(), time()), $timedate->dbDayFormat, true);
245                 $task_fields =$this->get_list_view_array();
246                 //$date_due = $timedate->to_db_date($task_fields['DATE_DUE'],false);
247         if (isset($this->parent_type)) 
248                         $task_fields['PARENT_MODULE'] = $this->parent_type;
249                 /*
250         if ($this->status != "Completed" && $this->status != "Deferred" ) {
251                         $task_fields['SET_COMPLETE'] = "<a href='index.php?return_module=$currentModule&return_action=$action&return_id=" . ((!empty($focus->id)) ? $focus->id : "") . "&module=ProjectTask&action=EditView&record={$this->id}&status=Completed'>".SugarThemeRegistry::current()->getImage("close_inline","alt='Close' border='0'")."</a>";
252                 }
253         
254                 if( $date_due   < $today){
255                         $task_fields['DATE_DUE']= "<font class='overdueTask'>".$task_fields['DATE_DUE']."</font>";
256                 }else if( $date_due     == $today ){
257                         $task_fields['DATE_DUE'] = "<font class='todaysTask'>".$task_fields['DATE_DUE']."</font>";
258                 }else{
259                         $task_fields['DATE_DUE'] = "<font class='futureTask'>".$task_fields['DATE_DUE']."</font>";
260                 }
261         */
262
263         if ( !isset($task_fields["FIRST_NAME"]) )
264             $task_fields["FIRST_NAME"] = '';
265         if ( !isset($task_fields["LAST_NAME"]) )
266             $task_fields["LAST_NAME"] = '';
267                 $task_fields['CONTACT_NAME']= $locale->getLocaleFormattedName($task_fields["FIRST_NAME"],$task_fields["LAST_NAME"]);
268                 $task_fields['TITLE'] = '';
269                 if (!empty($task_fields['CONTACT_NAME'])) {
270                         $task_fields['TITLE'] .= $current_module_strings['LBL_LIST_CONTACT'].": ".$task_fields['CONTACT_NAME'];
271                 }
272
273                 return $task_fields;
274         }
275         
276         function bean_implements($interface){
277                 switch($interface){
278                         case 'ACL':return true;
279                 }
280                 return false;
281         }
282         function listviewACLHelper(){
283                 $array_assign = parent::listviewACLHelper();
284                 $is_owner = false;
285                 if(!empty($this->parent_name)){
286                         
287                         if(!empty($this->parent_name_owner)){
288                                 global $current_user;
289                                 $is_owner = $current_user->id == $this->parent_name_owner;
290                         }
291                 }
292                         if(ACLController::checkAccess('Project', 'view', $is_owner)){
293                                 $array_assign['PARENT'] = 'a';
294                         }else{
295                                 $array_assign['PARENT'] = 'span';
296                         }
297                 $is_owner = false;
298                 if(!empty($this->depends_on_name)){
299                         
300                         if(!empty($this->depends_on_name_owner)){
301                                 global $current_user;
302                                 $is_owner = $current_user->id == $this->depends_on_name_owner;
303                         }
304                 }
305                         if( ACLController::checkAccess('ProjectTask', 'view', $is_owner)){
306                                 $array_assign['PARENT_TASK'] = 'a';
307                         }else{
308                                 $array_assign['PARENT_TASK'] = 'span';
309                         }
310                 
311                 return $array_assign;
312         }
313         
314     function create_export_query(&$order_by, &$where, $relate_link_join='')
315     {
316         $custom_join = $this->custom_fields->getJOIN(true, true,$where);
317                 if($custom_join)
318                                 $custom_join['join'] .= $relate_link_join;
319                 $query = "SELECT
320                                 project_task.*,
321                 users.user_name as assigned_user_name ";
322         if($custom_join){
323                         $query .=  $custom_join['select'];
324                 }
325         $query .= " FROM project_task ";
326         
327                 if($custom_join){
328                         $query .=  $custom_join['join'];
329                 }
330         $query .= " LEFT JOIN users
331                         ON project_task.assigned_user_id=users.id ";
332
333         $where_auto = " project_task.deleted=0 ";
334
335         if($where != "")
336                 $query .= "where ($where) AND ".$where_auto;
337         else
338             $query .= "where ".$where_auto;
339
340         if(!empty($order_by)){
341                 //check to see if order by variable already has table name by looking for dot "."
342                 $table_defined_already = strpos($order_by, ".");
343
344                 if($table_defined_already === false){
345                         //table not defined yet, define accounts to avoid "ambigous column" SQL error 
346                         $query .= " ORDER BY $order_by";
347                 }else{
348                         //table already defined, just add it to end of query
349                     $query .= " ORDER BY $order_by";    
350                 }           
351         }
352         return $query;
353     }   
354
355         
356 }
357
358 function getUtilizationDropdown($focus, $field, $value, $view) {
359         global $app_list_strings;       
360
361         if($view == 'EditView') {
362                 global $app_list_strings;
363         $html = '<select name="'.$field.'">';
364         $html .= get_select_options_with_id($app_list_strings['project_task_utilization_options'], $value);
365         $html .= '</select>';
366         return $html;
367     }
368        
369     return translate('project_task_utilization_options', '', $focus->$field);    
370 }       
371 ?>