]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Project/Project.php
Release 6.2.0
[Github/sugarcrm.git] / modules / Project / Project.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
51 /**
52  *
53  */
54 class Project extends SugarBean {
55         // database table columns
56         var $id;
57         var $date_entered;
58         var $date_modified;
59         var $assigned_user_id;
60         var $modified_user_id;
61         var $created_by;
62         var $name;
63         var $description;
64         var $deleted;
65
66
67         // related information
68         var $assigned_user_name;
69         var $modified_by_name;
70         var $created_by_name;
71
72         var $account_id;
73         var $contact_id;
74         var $opportunity_id;
75         var $email_id;
76     var $estimated_start_date;
77
78         // calculated information
79         var $total_estimated_effort;
80         var $total_actual_effort;
81
82         var $object_name = 'Project';
83         var $module_dir = 'Project';
84         var $new_schema = true;
85         var $table_name = 'project';
86
87         // This is used to retrieve related fields from form posts.
88         var $additional_column_fields = array(
89                 'account_id',
90                 'contact_id',
91                 'opportunity_id',
92         );
93
94         var $relationship_fields = array(
95                 'account_id' => 'accounts',
96                 'contact_id'=>'contacts',
97                 'opportunity_id'=>'opportunities',
98                 'email_id' => 'emails',
99         );
100
101         //////////////////////////////////////////////////////////////////
102         // METHODS
103         //////////////////////////////////////////////////////////////////
104
105         /**
106          *
107          */
108         function Project()
109         {
110                 parent::SugarBean();
111         }
112
113         /**
114          * overriding the base class function to do a join with users table
115          */
116
117         /**
118          *
119          */
120         function fill_in_additional_detail_fields()
121         {
122             parent::fill_in_additional_detail_fields();
123
124                 $this->assigned_user_name = get_assigned_user_name($this->assigned_user_id);
125                 //$this->total_estimated_effort = $this->_get_total_estimated_effort($this->id);
126                 //$this->total_actual_effort = $this->_get_total_actual_effort($this->id);
127         }
128
129         /**
130          *
131          */
132         function fill_in_additional_list_fields()
133         {
134             parent::fill_in_additional_list_fields();
135                 $this->assigned_user_name = get_assigned_user_name($this->assigned_user_id);
136                 //$this->total_estimated_effort = $this->_get_total_estimated_effort($this->id);
137                 //$this->total_actual_effort = $this->_get_total_actual_effort($this->id);
138         }
139
140         /**
141          *
142          */
143         function _get_total_estimated_effort($project_id)
144         {
145                 $return_value = '';
146
147                 $query = 'SELECT SUM(estimated_effort) total_estimated_effort';
148                 if ($this->db->dbType=='oci8') {
149                 }
150                 $query.= ' FROM project_task';
151                 $query.= " WHERE parent_id='{$project_id}' AND deleted=0";
152
153                 $result = $this->db->query($query,true," Error filling in additional detail fields: ");
154                 $row = $this->db->fetchByAssoc($result);
155                 if($row != null)
156                 {
157                         $return_value = $row['total_estimated_effort'];
158                 }
159
160                 return $return_value;
161         }
162
163         /**
164          *
165          */
166         function _get_total_actual_effort($project_id)
167         {
168                 $return_value = '';
169
170                 $query = 'SELECT SUM(actual_effort) total_actual_effort';
171                 if ($this->db->dbType=='oci8') {
172                 }
173                 $query.=  ' FROM project_task';
174                 $query.=  " WHERE parent_id='{$project_id}' AND deleted=0";
175
176                 $result = $this->db->query($query,true," Error filling in additional detail fields: ");
177                 $row = $this->db->fetchByAssoc($result);
178                 if($row != null)
179                 {
180                         $return_value = $row['total_actual_effort'];
181                 }
182
183                 return $return_value;
184         }
185
186         /**
187          *
188          */
189         function get_summary_text()
190         {
191                 return $this->name;
192         }
193
194         /**
195          *
196          */
197         function build_generic_where_clause ($the_query_string)
198         {
199                 $where_clauses = array();
200                 $the_query_string = $GLOBALS['db']->quote($the_query_string);
201                 array_push($where_clauses, "project.name LIKE '%$the_query_string%'");
202
203                 $the_where = '';
204                 foreach($where_clauses as $clause)
205                 {
206                         if($the_where != '') $the_where .= " OR ";
207                         $the_where .= $clause;
208                 }
209
210                 return $the_where;
211         }
212
213         function get_list_view_data()
214         {
215                 $field_list = $this->get_list_view_array();
216                 $field_list['USER_NAME'] = empty($this->user_name) ? '' : $this->user_name;
217                 $field_list['ASSIGNED_USER_NAME'] = $this->assigned_user_name;
218                 return $field_list;
219         }
220           function bean_implements($interface){
221                 switch($interface){
222                         case 'ACL':return true;
223                 }
224                 return false;
225         }
226
227     function create_export_query(&$order_by, &$where, $relate_link_join='')
228     {
229         $custom_join = $this->custom_fields->getJOIN(true, true,$where);
230                 if($custom_join)
231                                 $custom_join['join'] .= $relate_link_join;
232                 $query = "SELECT
233                                 project.*,
234                 users.user_name as assigned_user_name ";
235         if($custom_join){
236                         $query .=  $custom_join['select'];
237                 }
238         $query .= " FROM project ";
239
240                 if($custom_join){
241                         $query .=  $custom_join['join'];
242                 }
243         $query .= " LEFT JOIN users
244                         ON project.assigned_user_id=users.id ";
245
246         $where_auto = " project.deleted=0 ";
247
248         if($where != "")
249                 $query .= "where ($where) AND ".$where_auto;
250         else
251             $query .= "where ".$where_auto;
252
253         if(!empty($order_by)){
254                 //check to see if order by variable already has table name by looking for dot "."
255                 $table_defined_already = strpos($order_by, ".");
256
257                 if($table_defined_already === false){
258                         //table not defined yet, define accounts to avoid "ambigous column" SQL error
259                         $query .= " ORDER BY $order_by";
260                 }else{
261                         //table already defined, just add it to end of query
262                     $query .= " ORDER BY $order_by";
263                 }
264         }
265         return $query;
266     }
267         function getAllProjectTasks(){
268                 $projectTasks = array();
269
270                 $query = "SELECT * FROM project_task WHERE project_id = '" . $this->id. "' AND deleted = 0 ORDER BY project_task_id";
271                 $result = $this->db->query($query,true,"Error retrieving project tasks");
272                 $row = $this->db->fetchByAssoc($result);
273
274                 while ($row != null){
275                         $projectTaskBean = new ProjectTask();
276                         $projectTaskBean->id = $row['id'];
277                         $projectTaskBean->retrieve();
278                         array_push($projectTasks, $projectTaskBean);
279
280                         $row = $this->db->fetchByAssoc($result);
281                 }
282
283                 return $projectTasks;
284         }
285 }
286 ?>