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 ********************************************************************************/
39 class Project extends SugarBean {
40 // database table columns
44 var $assigned_user_id;
45 var $modified_user_id;
52 // related information
53 var $assigned_user_name;
54 var $modified_by_name;
61 var $estimated_start_date;
63 // calculated information
64 var $total_estimated_effort;
65 var $total_actual_effort;
67 var $object_name = 'Project';
68 var $module_dir = 'Project';
69 var $new_schema = true;
70 var $table_name = 'project';
72 // This is used to retrieve related fields from form posts.
73 var $additional_column_fields = array(
79 var $relationship_fields = array(
80 'account_id' => 'accounts',
81 'contact_id'=>'contacts',
82 'opportunity_id'=>'opportunities',
83 'email_id' => 'emails',
86 //////////////////////////////////////////////////////////////////
88 //////////////////////////////////////////////////////////////////
99 * overriding the base class function to do a join with users table
105 function fill_in_additional_detail_fields()
107 parent::fill_in_additional_detail_fields();
109 $this->assigned_user_name = get_assigned_user_name($this->assigned_user_id);
110 //$this->total_estimated_effort = $this->_get_total_estimated_effort($this->id);
111 //$this->total_actual_effort = $this->_get_total_actual_effort($this->id);
117 function fill_in_additional_list_fields()
119 parent::fill_in_additional_list_fields();
120 $this->assigned_user_name = get_assigned_user_name($this->assigned_user_id);
121 //$this->total_estimated_effort = $this->_get_total_estimated_effort($this->id);
122 //$this->total_actual_effort = $this->_get_total_actual_effort($this->id);
126 * Save changes that have been made to a relationship.
128 * @param $is_update true if this save is an update.
130 function save_relationship_changes($is_update, $exclude=array())
132 parent::save_relationship_changes($is_update, $exclude);
134 $new_rel_link = false;
135 //this allows us to dynamically relate modules without adding it to the relationship_fields array
136 if(!empty($_REQUEST['relate_id']) && !in_array($_REQUEST['relate_to'], $exclude) && $_REQUEST['relate_id'] != $this->id){
137 $new_rel_id = $_REQUEST['relate_id'];
138 $new_rel_relname = $_REQUEST['relate_to'];
139 if(!empty($this->in_workflow) && !empty($this->not_use_rel_in_req)) {
140 $new_rel_id = $this->new_rel_id;
141 $new_rel_relname = $this->new_rel_relname;
143 $new_rel_link = $new_rel_relname;
144 //Try to find the link in this bean based on the relationship
145 foreach ( $this->field_defs as $key => $def ) {
146 if (isset($def['type']) && $def['type'] == 'link'
147 && isset($def['relationship']) && $def['relationship'] == $new_rel_relname) {
148 $new_rel_link = $key;
151 if ($new_rel_link == 'contacts') {
152 $accountId = $this->db->getOne('SELECT account_id FROM accounts_contacts WHERE contact_id=' . $this->db->quoted($new_rel_id));
153 if ($accountId !== false) {
154 if($this->load_relationship('accounts')){
155 $this->accounts->add($accountId);
164 function _get_total_estimated_effort($project_id)
168 $query = 'SELECT SUM('.$this->db->convert('estimated_effort', "IFNULL", 0).') total_estimated_effort';
169 $query.= ' FROM project_task';
170 $query.= " WHERE parent_id='{$project_id}' AND deleted=0";
172 $result = $this->db->query($query,true," Error filling in additional detail fields: ");
173 $row = $this->db->fetchByAssoc($result);
176 $return_value = $row['total_estimated_effort'];
179 return $return_value;
185 function _get_total_actual_effort($project_id)
189 $query = 'SELECT SUM('.$this->db->convert('actual_effort', "IFNULL", 0).') total_actual_effort';
190 $query.= ' FROM project_task';
191 $query.= " WHERE parent_id='{$project_id}' AND deleted=0";
193 $result = $this->db->query($query,true," Error filling in additional detail fields: ");
194 $row = $this->db->fetchByAssoc($result);
197 $return_value = $row['total_actual_effort'];
200 return $return_value;
206 function get_summary_text()
214 function build_generic_where_clause ($the_query_string)
216 $where_clauses = array();
217 $the_query_string = $GLOBALS['db']->quote($the_query_string);
218 array_push($where_clauses, "project.name LIKE '%$the_query_string%'");
221 foreach($where_clauses as $clause)
223 if($the_where != '') $the_where .= " OR ";
224 $the_where .= $clause;
230 function get_list_view_data()
232 $field_list = $this->get_list_view_array();
233 $field_list['USER_NAME'] = empty($this->user_name) ? '' : $this->user_name;
234 $field_list['ASSIGNED_USER_NAME'] = $this->assigned_user_name;
237 function bean_implements($interface){
239 case 'ACL':return true;
244 function create_export_query(&$order_by, &$where, $relate_link_join='')
246 $custom_join = $this->custom_fields->getJOIN(true, true,$where);
248 $custom_join['join'] .= $relate_link_join;
251 users.user_name as assigned_user_name ";
253 $query .= $custom_join['select'];
255 $query .= " FROM project ";
258 $query .= $custom_join['join'];
260 $query .= " LEFT JOIN users
261 ON project.assigned_user_id=users.id ";
263 $where_auto = " project.deleted=0 ";
266 $query .= "where ($where) AND ".$where_auto;
268 $query .= "where ".$where_auto;
270 if(!empty($order_by)){
271 //check to see if order by variable already has table name by looking for dot "."
272 $table_defined_already = strpos($order_by, ".");
274 if($table_defined_already === false){
275 //table not defined yet, define accounts to avoid "ambigous column" SQL error
276 $query .= " ORDER BY $order_by";
278 //table already defined, just add it to end of query
279 $query .= " ORDER BY $order_by";
284 function getAllProjectTasks(){
285 $projectTasks = array();
287 $query = "SELECT * FROM project_task WHERE project_id = '" . $this->id. "' AND deleted = 0 ORDER BY project_task_id";
288 $result = $this->db->query($query,true,"Error retrieving project tasks");
289 $row = $this->db->fetchByAssoc($result);
291 while ($row != null){
292 $projectTaskBean = new ProjectTask();
293 $projectTaskBean->id = $row['id'];
294 $projectTaskBean->retrieve();
295 array_push($projectTasks, $projectTaskBean);
297 $row = $this->db->fetchByAssoc($result);
300 return $projectTasks;