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.
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);
141 * Save changes that have been made to a relationship.
143 * @param $is_update true if this save is an update.
145 function save_relationship_changes($is_update, $exclude=array())
147 parent::save_relationship_changes($is_update, $exclude);
149 $new_rel_link = false;
150 //this allows us to dynamically relate modules without adding it to the relationship_fields array
151 if(!empty($_REQUEST['relate_id']) && !in_array($_REQUEST['relate_to'], $exclude) && $_REQUEST['relate_id'] != $this->id){
152 $new_rel_id = $_REQUEST['relate_id'];
153 $new_rel_relname = $_REQUEST['relate_to'];
154 if(!empty($this->in_workflow) && !empty($this->not_use_rel_in_req)) {
155 $new_rel_id = $this->new_rel_id;
156 $new_rel_relname = $this->new_rel_relname;
158 $new_rel_link = $new_rel_relname;
159 //Try to find the link in this bean based on the relationship
160 foreach ( $this->field_defs as $key => $def ) {
161 if (isset($def['type']) && $def['type'] == 'link'
162 && isset($def['relationship']) && $def['relationship'] == $new_rel_relname) {
163 $new_rel_link = $key;
166 if ($new_rel_link == 'contacts') {
167 $accountId = $this->db->getOne('SELECT account_id FROM accounts_contacts WHERE contact_id="' . $new_rel_id .'"');
168 if ($accountId !== false) {
169 if($this->load_relationship('accounts')){
170 $this->accounts->add($accountId);
179 function _get_total_estimated_effort($project_id)
183 $query = 'SELECT SUM(estimated_effort) total_estimated_effort';
184 if ($this->db->dbType=='oci8') {
186 $query.= ' FROM project_task';
187 $query.= " WHERE parent_id='{$project_id}' AND deleted=0";
189 $result = $this->db->query($query,true," Error filling in additional detail fields: ");
190 $row = $this->db->fetchByAssoc($result);
193 $return_value = $row['total_estimated_effort'];
196 return $return_value;
202 function _get_total_actual_effort($project_id)
206 $query = 'SELECT SUM(actual_effort) total_actual_effort';
207 if ($this->db->dbType=='oci8') {
209 $query.= ' FROM project_task';
210 $query.= " WHERE parent_id='{$project_id}' AND deleted=0";
212 $result = $this->db->query($query,true," Error filling in additional detail fields: ");
213 $row = $this->db->fetchByAssoc($result);
216 $return_value = $row['total_actual_effort'];
219 return $return_value;
225 function get_summary_text()
233 function build_generic_where_clause ($the_query_string)
235 $where_clauses = array();
236 $the_query_string = $GLOBALS['db']->quote($the_query_string);
237 array_push($where_clauses, "project.name LIKE '%$the_query_string%'");
240 foreach($where_clauses as $clause)
242 if($the_where != '') $the_where .= " OR ";
243 $the_where .= $clause;
249 function get_list_view_data()
251 $field_list = $this->get_list_view_array();
252 $field_list['USER_NAME'] = empty($this->user_name) ? '' : $this->user_name;
253 $field_list['ASSIGNED_USER_NAME'] = $this->assigned_user_name;
256 function bean_implements($interface){
258 case 'ACL':return true;
263 function create_export_query(&$order_by, &$where, $relate_link_join='')
265 $custom_join = $this->custom_fields->getJOIN(true, true,$where);
267 $custom_join['join'] .= $relate_link_join;
270 users.user_name as assigned_user_name ";
272 $query .= $custom_join['select'];
274 $query .= " FROM project ";
277 $query .= $custom_join['join'];
279 $query .= " LEFT JOIN users
280 ON project.assigned_user_id=users.id ";
282 $where_auto = " project.deleted=0 ";
285 $query .= "where ($where) AND ".$where_auto;
287 $query .= "where ".$where_auto;
289 if(!empty($order_by)){
290 //check to see if order by variable already has table name by looking for dot "."
291 $table_defined_already = strpos($order_by, ".");
293 if($table_defined_already === false){
294 //table not defined yet, define accounts to avoid "ambigous column" SQL error
295 $query .= " ORDER BY $order_by";
297 //table already defined, just add it to end of query
298 $query .= " ORDER BY $order_by";
303 function getAllProjectTasks(){
304 $projectTasks = array();
306 $query = "SELECT * FROM project_task WHERE project_id = '" . $this->id. "' AND deleted = 0 ORDER BY project_task_id";
307 $result = $this->db->query($query,true,"Error retrieving project tasks");
308 $row = $this->db->fetchByAssoc($result);
310 while ($row != null){
311 $projectTaskBean = new ProjectTask();
312 $projectTaskBean->id = $row['id'];
313 $projectTaskBean->retrieve();
314 array_push($projectTasks, $projectTaskBean);
316 $row = $this->db->fetchByAssoc($result);
319 return $projectTasks;