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-2013 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 ********************************************************************************/
38 /*********************************************************************************
40 * Description: TODO: To be written.
41 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
42 * All Rights Reserved.
43 * Contributor(s): ______________________________________..
44 ********************************************************************************/
60 // Bug is used to store customer information.
61 class Bug extends SugarBean {
62 var $field_name_map = array();
67 var $modified_user_id;
68 var $assigned_user_id;
77 var $found_in_release;
79 var $fixed_in_release_name;
82 var $modified_by_name;
91 var $assigned_user_name;
94 //BEGIN Additional fields being added to Bugs
96 var $fixed_in_release;
99 var $product_category;
100 //END Additional fields being added to Bugs
102 var $module_dir = 'Bugs';
103 var $table_name = "bugs";
104 var $rel_account_table = "accounts_bugs";
105 var $rel_contact_table = "contacts_bugs";
106 var $rel_case_table = "cases_bugs";
107 var $importable = true;
108 var $object_name = "Bug";
110 // This is used to retrieve related fields from form posts.
111 var $additional_column_fields = Array('assigned_user_name', 'assigned_user_id', 'case_id', 'account_id', 'contact_id', 'task_id', 'note_id', 'meeting_id', 'call_id', 'email_id');
113 var $relationship_fields = Array('case_id'=>'cases', 'account_id' => 'accounts', 'contact_id'=>'contacts',
114 'task_id'=>'tasks', 'note_id'=>'notes', 'meeting_id'=>'meetings',
115 'call_id'=>'calls', 'email_id'=>'emails');
121 $this->setupCustomFields('Bugs');
123 foreach ($this->field_defs as $field)
125 $this->field_name_map[$field['name']] = $field;
130 var $new_schema = true;
136 function get_summary_text()
138 return "$this->name";
141 function create_list_query($order_by, $where, $show_deleted = 0)
143 // Fill in the assigned_user_name
144 // $this->assigned_user_name = get_assigned_user_name($this->assigned_user_id);
146 $custom_join = $this->getCustomJoin();
153 ,users.user_name as assigned_user_name, releases.id release_id, releases.name release_name";
154 $query .= $custom_join['select'];
155 $query .= " FROM bugs ";
158 $query .= " LEFT JOIN releases ON bugs.found_in_release=releases.id
160 ON bugs.assigned_user_id=users.id";
162 $query .= $custom_join['join'];
164 if($show_deleted == 0){
165 $where_auto = " $this->table_name.deleted=0 ";
166 }else if($show_deleted == 1){
167 $where_auto = " $this->table_name.deleted=1 ";
172 $query .= "where $where AND ".$where_auto;
174 $query .= "where ".$where_auto;
175 if(substr_count($order_by, '.') > 0){
176 $query .= " ORDER BY $order_by";
178 else if($order_by != "")
179 $query .= " ORDER BY $order_by";
181 $query .= " ORDER BY bugs.name";
185 function create_export_query(&$order_by, &$where, $relate_link_join='')
187 $custom_join = $this->getCustomJoin(true, true, $where);
188 $custom_join['join'] .= $relate_link_join;
191 r1.name found_in_release_name,
192 r2.name fixed_in_release_name,
193 users.user_name assigned_user_name";
194 $query .= $custom_join['select'];
195 $query .= " FROM bugs ";
196 $query .= " LEFT JOIN releases r1 ON bugs.found_in_release = r1.id
197 LEFT JOIN releases r2 ON bugs.fixed_in_release = r2.id
199 ON bugs.assigned_user_id=users.id";
200 $query .= $custom_join['join'];
202 $where_auto = " bugs.deleted=0
206 $query .= " where $where AND ".$where_auto;
208 $query .= " where ".$where_auto;
211 $query .= " ORDER BY $order_by";
213 $query .= " ORDER BY bugs.bug_number";
217 function fill_in_additional_list_fields()
219 parent::fill_in_additional_list_fields();
220 // Fill in the assigned_user_name
221 //$this->assigned_user_name = get_assigned_user_name($this->assigned_user_id);
223 // $this->set_fixed_in_release();
226 function fill_in_additional_detail_fields()
230 // Fill in the assigned_user_name
231 $this->assigned_user_name = get_assigned_user_name($this->assigned_user_id);
233 parent::fill_in_additional_detail_fields();
234 //$this->created_by_name = get_assigned_user_name($this->created_by);
235 //$this->modified_by_name = get_assigned_user_name($this->modified_user_id);
236 $this->set_release();
237 $this->set_fixed_in_release();
241 public function set_release()
245 if ( empty($this->found_in_release) ) {
248 if ( isset($releases[$this->found_in_release]) ) {
249 $this->release_name = $releases[$this->found_in_release];
253 $query = "SELECT r1.name from releases r1, $this->table_name i1 where r1.id = i1.found_in_release and i1.id = '$this->id' and i1.deleted=0 and r1.deleted=0";
254 $result = $this->db->query($query,true," Error filling in additional detail fields: ");
256 // Get the id and the name.
257 $row = $this->db->fetchByAssoc($result);
261 $this->release_name = $row['name'];
265 $this->release_name = '';
268 $releases[$this->found_in_release] = $this->release_name;
272 public function set_fixed_in_release()
276 if ( empty($this->fixed_in_release) ) {
279 if ( isset($releases[$this->fixed_in_release]) ) {
280 $this->fixed_in_release_name = $releases[$this->fixed_in_release];
284 $query = "SELECT r1.name from releases r1, $this->table_name i1 where r1.id = i1.fixed_in_release and i1.id = '$this->id' and i1.deleted=0 and r1.deleted=0";
285 $result = $this->db->query($query,true," Error filling in additional detail fields: ");
287 // Get the id and the name.
288 $row = $this->db->fetchByAssoc($result);
294 $this->fixed_in_release_name = $row['name'];
298 $this->fixed_in_release_name = '';
301 $releases[$this->fixed_in_release] = $this->fixed_in_release_name;
306 function get_list_view_data(){
307 global $current_language;
308 $the_array = parent::get_list_view_data();
309 $app_list_strings = return_app_list_strings_language($current_language);
310 $mod_strings = return_module_language($current_language, 'Bugs');
312 $this->set_release();
314 // The new listview code only fetches columns that we're displaying and not all
315 // the columns so we need these checks.
316 $the_array['NAME'] = (($this->name == "") ? "<em>blank</em>" : $this->name);
317 $the_array['PRIORITY'] = empty($this->priority)? "" : (!isset($app_list_strings[$this->field_name_map['priority']['options']][$this->priority]) ? $this->priority : $app_list_strings[$this->field_name_map['priority']['options']][$this->priority]);
318 $the_array['STATUS'] = empty($this->status)? "" : (!isset($app_list_strings[$this->field_name_map['status']['options']][$this->status]) ? $this->status : $app_list_strings[$this->field_name_map['status']['options']][$this->status]);
319 $the_array['TYPE'] = empty($this->type)? "" : (!isset($app_list_strings[$this->field_name_map['type']['options']][$this->type]) ? $this->type : $app_list_strings[$this->field_name_map['type']['options']][$this->type]);
321 $the_array['RELEASE']= $this->release_name;
322 $the_array['BUG_NUMBER'] = $this->bug_number;
323 $the_array['ENCODED_NAME']=$this->name;
329 builds a generic search based on the query string using or
330 do not include any $this-> because this is called on without having the class instantiated
332 function build_generic_where_clause ($the_query_string) {
333 $where_clauses = Array();
334 $the_query_string = $this->db->quote($the_query_string);
335 array_push($where_clauses, "bugs.name like '$the_query_string%'");
336 if (is_numeric($the_query_string)) array_push($where_clauses, "bugs.bug_number like '$the_query_string%'");
339 foreach($where_clauses as $clause)
341 if($the_where != "") $the_where .= " or ";
342 $the_where .= $clause;
348 function set_notification_body($xtpl, $bug)
350 global $mod_strings, $app_list_strings;
354 $xtpl->assign("BUG_SUBJECT", $bug->name);
355 $xtpl->assign("BUG_TYPE", $app_list_strings['bug_type_dom'][$bug->type]);
356 $xtpl->assign("BUG_PRIORITY", $app_list_strings['bug_priority_dom'][$bug->priority]);
357 $xtpl->assign("BUG_STATUS", $app_list_strings['bug_status_dom'][$bug->status]);
358 $xtpl->assign("BUG_RESOLUTION", $app_list_strings['bug_resolution_dom'][$bug->resolution]);
359 $xtpl->assign("BUG_RELEASE", $bug->release_name);
360 $xtpl->assign("BUG_DESCRIPTION", $bug->description);
361 $xtpl->assign("BUG_WORK_LOG", $bug->work_log);
362 $xtpl->assign("BUG_BUG_NUMBER", $bug->bug_number);
366 function bean_implements($interface){
368 case 'ACL':return true;
373 function save($check_notify = FALSE){
374 return parent::save($check_notify);
378 function getReleaseDropDown(){
379 static $releases = null;
381 $seedRelease = new Release();
382 $releases = $seedRelease->get_releases(TRUE, "Active");