2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4 * SugarCRM is a customer relationship management program developed by
5 * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
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.
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
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
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.
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.
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 ********************************************************************************/
54 class Project extends SugarBean {
55 // database table columns
59 var $assigned_user_id;
60 var $modified_user_id;
67 // related information
68 var $assigned_user_name;
69 var $modified_by_name;
76 var $estimated_start_date;
78 // calculated information
79 var $total_estimated_effort;
80 var $total_actual_effort;
82 var $object_name = 'Project';
83 var $module_dir = 'Project';
84 var $new_schema = true;
85 var $table_name = 'project';
87 // This is used to retrieve related fields from form posts.
88 var $additional_column_fields = array(
94 var $relationship_fields = array(
95 'account_id' => 'accounts',
96 'contact_id'=>'contacts',
97 'opportunity_id'=>'opportunities',
98 'email_id' => 'emails',
101 //////////////////////////////////////////////////////////////////
103 //////////////////////////////////////////////////////////////////
114 * overriding the base class function to do a join with users table
120 function fill_in_additional_detail_fields()
122 parent::fill_in_additional_detail_fields();
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);
132 function fill_in_additional_list_fields()
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);
143 function _get_total_estimated_effort($project_id)
147 $query = 'SELECT SUM(estimated_effort) total_estimated_effort';
148 if ($this->db->dbType=='oci8') {
150 $query.= ' FROM project_task';
151 $query.= " WHERE parent_id='{$project_id}' AND deleted=0";
153 $result = $this->db->query($query,true," Error filling in additional detail fields: ");
154 $row = $this->db->fetchByAssoc($result);
157 $return_value = $row['total_estimated_effort'];
160 return $return_value;
166 function _get_total_actual_effort($project_id)
170 $query = 'SELECT SUM(actual_effort) total_actual_effort';
171 if ($this->db->dbType=='oci8') {
173 $query.= ' FROM project_task';
174 $query.= " WHERE parent_id='{$project_id}' AND deleted=0";
176 $result = $this->db->query($query,true," Error filling in additional detail fields: ");
177 $row = $this->db->fetchByAssoc($result);
180 $return_value = $row['total_actual_effort'];
183 return $return_value;
189 function get_summary_text()
197 function build_generic_where_clause ($the_query_string)
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%'");
204 foreach($where_clauses as $clause)
206 if($the_where != '') $the_where .= " OR ";
207 $the_where .= $clause;
213 function get_list_view_data()
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;
220 function bean_implements($interface){
222 case 'ACL':return true;
227 function create_export_query(&$order_by, &$where, $relate_link_join='')
229 $custom_join = $this->custom_fields->getJOIN(true, true,$where);
231 $custom_join['join'] .= $relate_link_join;
234 users.user_name as assigned_user_name ";
236 $query .= $custom_join['select'];
238 $query .= " FROM project ";
241 $query .= $custom_join['join'];
243 $query .= " LEFT JOIN users
244 ON project.assigned_user_id=users.id ";
246 $where_auto = " project.deleted=0 ";
249 $query .= "where ($where) AND ".$where_auto;
251 $query .= "where ".$where_auto;
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, ".");
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";
261 //table already defined, just add it to end of query
262 $query .= " ORDER BY $order_by";
267 function getAllProjectTasks(){
268 $projectTasks = array();
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);
274 while ($row != null){
275 $projectTaskBean = new ProjectTask();
276 $projectTaskBean->id = $row['id'];
277 $projectTaskBean->retrieve();
278 array_push($projectTasks, $projectTaskBean);
280 $row = $this->db->fetchByAssoc($result);
283 return $projectTasks;