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-2012 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 Bug Tracker
96 var $fixed_in_release;
99 var $product_category;
100 //END Additional fields being added to Bug Tracker
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->custom_fields->getJOIN();
153 ,users.user_name as assigned_user_name, releases.id release_id, releases.name release_name";
155 $query .= $custom_join['select'];
157 $query .= " FROM bugs ";
160 $query .= " LEFT JOIN releases ON bugs.found_in_release=releases.id
162 ON bugs.assigned_user_id=users.id";
165 $query .= $custom_join['join'];
168 if($show_deleted == 0){
169 $where_auto = " $this->table_name.deleted=0 ";
170 }else if($show_deleted == 1){
171 $where_auto = " $this->table_name.deleted=1 ";
176 $query .= "where $where AND ".$where_auto;
178 $query .= "where ".$where_auto;
179 if(substr_count($order_by, '.') > 0){
180 $query .= " ORDER BY $order_by";
182 else if($order_by != "")
183 $query .= " ORDER BY $order_by";
185 $query .= " ORDER BY bugs.name";
189 function create_export_query(&$order_by, &$where, $relate_link_join='')
191 $custom_join = $this->custom_fields->getJOIN(true, true,$where);
193 $custom_join['join'] .= $relate_link_join;
196 r1.name found_in_release_name,
197 r2.name fixed_in_release_name,
198 users.user_name assigned_user_name";
200 $query .= $custom_join['select'];
202 $query .= " FROM bugs ";
203 $query .= " LEFT JOIN releases r1 ON bugs.found_in_release = r1.id
204 LEFT JOIN releases r2 ON bugs.fixed_in_release = r2.id
206 ON bugs.assigned_user_id=users.id";
208 $query .= $custom_join['join'];
211 $where_auto = " bugs.deleted=0
215 $query .= " where $where AND ".$where_auto;
217 $query .= " where ".$where_auto;
220 $query .= " ORDER BY $order_by";
222 $query .= " ORDER BY bugs.bug_number";
226 function fill_in_additional_list_fields()
228 parent::fill_in_additional_list_fields();
229 // Fill in the assigned_user_name
230 //$this->assigned_user_name = get_assigned_user_name($this->assigned_user_id);
232 // $this->set_fixed_in_release();
235 function fill_in_additional_detail_fields()
239 // Fill in the assigned_user_name
240 $this->assigned_user_name = get_assigned_user_name($this->assigned_user_id);
242 parent::fill_in_additional_detail_fields();
243 //$this->created_by_name = get_assigned_user_name($this->created_by);
244 //$this->modified_by_name = get_assigned_user_name($this->modified_user_id);
245 $this->set_release();
246 $this->set_fixed_in_release();
250 public function set_release()
254 if ( empty($this->found_in_release) ) {
257 if ( isset($releases[$this->found_in_release]) ) {
258 $this->release_name = $releases[$this->found_in_release];
262 $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";
263 $result = $this->db->query($query,true," Error filling in additional detail fields: ");
265 // Get the id and the name.
266 $row = $this->db->fetchByAssoc($result);
270 $this->release_name = $row['name'];
274 $this->release_name = '';
277 $releases[$this->found_in_release] = $this->release_name;
281 public function set_fixed_in_release()
285 if ( empty($this->fixed_in_release) ) {
288 if ( isset($releases[$this->fixed_in_release]) ) {
289 $this->fixed_in_release_name = $releases[$this->fixed_in_release];
293 $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";
294 $result = $this->db->query($query,true," Error filling in additional detail fields: ");
296 // Get the id and the name.
297 $row = $this->db->fetchByAssoc($result);
303 $this->fixed_in_release_name = $row['name'];
307 $this->fixed_in_release_name = '';
310 $releases[$this->fixed_in_release] = $this->fixed_in_release_name;
315 function get_list_view_data(){
316 global $current_language;
317 $the_array = parent::get_list_view_data();
318 $app_list_strings = return_app_list_strings_language($current_language);
319 $mod_strings = return_module_language($current_language, 'Bugs');
321 $this->set_release();
323 // The new listview code only fetches columns that we're displaying and not all
324 // the columns so we need these checks.
325 $the_array['NAME'] = (($this->name == "") ? "<em>blank</em>" : $this->name);
326 if (!empty($this->priority))
327 $the_array['PRIORITY'] = $app_list_strings['bug_priority_dom'][$this->priority];
328 if (!empty($this->status))
329 $the_array['STATUS'] =$app_list_strings['bug_status_dom'][$this->status];
330 $the_array['RELEASE']= $this->release_name;
331 if (!empty($this->type))
332 $the_array['TYPE']= $app_list_strings['bug_type_dom'][$this->type];
333 $the_array['BUG_NUMBER'] = $this->bug_number;
334 $the_array['ENCODED_NAME']=$this->name;
340 builds a generic search based on the query string using or
341 do not include any $this-> because this is called on without having the class instantiated
343 function build_generic_where_clause ($the_query_string) {
344 $where_clauses = Array();
345 $the_query_string = $this->db->quote($the_query_string);
346 array_push($where_clauses, "bugs.name like '$the_query_string%'");
347 if (is_numeric($the_query_string)) array_push($where_clauses, "bugs.bug_number like '$the_query_string%'");
350 foreach($where_clauses as $clause)
352 if($the_where != "") $the_where .= " or ";
353 $the_where .= $clause;
359 function set_notification_body($xtpl, $bug)
361 global $mod_strings, $app_list_strings;
365 $xtpl->assign("BUG_SUBJECT", $bug->name);
366 $xtpl->assign("BUG_TYPE", $app_list_strings['bug_type_dom'][$bug->type]);
367 $xtpl->assign("BUG_PRIORITY", $app_list_strings['bug_priority_dom'][$bug->priority]);
368 $xtpl->assign("BUG_STATUS", $app_list_strings['bug_status_dom'][$bug->status]);
369 $xtpl->assign("BUG_RESOLUTION", $app_list_strings['bug_resolution_dom'][$bug->resolution]);
370 $xtpl->assign("BUG_RELEASE", $bug->release_name);
371 $xtpl->assign("BUG_DESCRIPTION", $bug->description);
372 $xtpl->assign("BUG_WORK_LOG", $bug->work_log);
373 $xtpl->assign("BUG_BUG_NUMBER", $bug->bug_number);
377 function bean_implements($interface){
379 case 'ACL':return true;
384 function save($check_notify = FALSE){
385 return parent::save($check_notify);
389 function getReleaseDropDown(){
390 static $releases = null;
392 $seedRelease = new Release();
393 $releases = $seedRelease->get_releases(TRUE, "Active");