]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Bugs/Bug.php
Release 6.5.10
[Github/sugarcrm.git] / modules / Bugs / Bug.php
1 <?php
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.
6  * 
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.
13  * 
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
17  * details.
18  * 
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
22  * 02110-1301 USA.
23  * 
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.
26  * 
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.
30  * 
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  ********************************************************************************/
37
38 /*********************************************************************************
39
40  * Description:  TODO: To be written.
41  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
42  * All Rights Reserved.
43  * Contributor(s): ______________________________________..
44  ********************************************************************************/
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60 // Bug is used to store customer information.
61 class Bug extends SugarBean {
62         var $field_name_map = array();
63         // Stored fields
64         var $id;
65         var $date_entered;
66         var $date_modified;
67         var $modified_user_id;
68         var $assigned_user_id;
69         var $bug_number;
70         var $description;
71         var $name;
72         var $status;
73         var $priority;
74
75         // These are related
76         var $resolution;
77         var $found_in_release;
78         var $release_name;
79         var $fixed_in_release_name;
80         var $created_by;
81         var $created_by_name;
82         var $modified_by_name;
83         var $account_id;
84         var $contact_id;
85         var $case_id;
86         var $task_id;
87         var $note_id;
88         var $meeting_id;
89         var $call_id;
90         var $email_id;
91         var $assigned_user_name;
92         var $type;
93
94         //BEGIN Additional fields being added to Bug Tracker
95         
96         var $fixed_in_release;
97         var $work_log;
98         var $source;
99         var $product_category;
100         //END Additional fields being added to Bug Tracker
101         
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";
109
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');
112
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');
116
117         function Bug() {
118                 parent::SugarBean();
119                 
120
121                 $this->setupCustomFields('Bugs');
122
123                 foreach ($this->field_defs as $field)
124                 {
125                         $this->field_name_map[$field['name']] = $field;
126                 }
127
128         }
129
130         var $new_schema = true;
131
132         
133
134         
135
136         function get_summary_text()
137         {
138                 return "$this->name";
139         }
140
141         function create_list_query($order_by, $where, $show_deleted = 0)
142         {               
143                 // Fill in the assigned_user_name
144 //              $this->assigned_user_name = get_assigned_user_name($this->assigned_user_id);
145
146         $custom_join = $this->getCustomJoin();
147                 
148                 $query = "SELECT ";
149                 
150                 $query .= "
151                                bugs.*
152
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 ";
156                                
157
158                 $query .= "                             LEFT JOIN releases ON bugs.found_in_release=releases.id
159                                                                 LEFT JOIN users
160                                 ON bugs.assigned_user_id=users.id";
161                                 $query .= "  ";
162         $query .= $custom_join['join'];
163             $where_auto = '1=1';
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 ";  
168                         }
169           
170
171                 if($where != "")
172                         $query .= "where $where AND ".$where_auto;
173                 else
174                         $query .= "where ".$where_auto;
175                 if(substr_count($order_by, '.') > 0){
176                         $query .= " ORDER BY $order_by";
177                 }
178                 else if($order_by != "")
179                         $query .= " ORDER BY $order_by";
180                 else
181                         $query .= " ORDER BY bugs.name";
182                 return $query;
183         }
184
185         function create_export_query(&$order_by, &$where, $relate_link_join='')
186         {
187             $custom_join = $this->getCustomJoin(true, true, $where);
188             $custom_join['join'] .= $relate_link_join;
189                 $query = "SELECT
190                                 bugs.*,
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
198                                                                 LEFT JOIN users
199                                 ON bugs.assigned_user_id=users.id";
200             $query .=  $custom_join['join'];
201                                 $query .= "";
202                 $where_auto = "  bugs.deleted=0
203                 ";
204
205                 if($where != "")
206                         $query .= " where $where AND ".$where_auto;
207                 else
208                         $query .= " where ".$where_auto;
209
210                 if($order_by != "")
211                         $query .= " ORDER BY $order_by";
212                 else
213                         $query .= " ORDER BY bugs.bug_number";
214
215                 return $query;
216         }
217         function fill_in_additional_list_fields()
218         {
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);
222                 
223 //         $this->set_fixed_in_release();
224         }
225
226         function fill_in_additional_detail_fields()
227         {   
228                 
229             /*
230                 // Fill in the assigned_user_name
231                 $this->assigned_user_name = get_assigned_user_name($this->assigned_user_id);
232         */
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();
238         }
239
240
241         public function set_release() 
242         {
243             static $releases;
244             
245             if ( empty($this->found_in_release) ) {
246                 return;
247             }
248             if ( isset($releases[$this->found_in_release]) ) {
249                 $this->release_name = $releases[$this->found_in_release];
250                 return;
251             }
252             
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: ");
255
256         // Get the id and the name.
257         $row = $this->db->fetchByAssoc($result);
258
259         if($row != null)
260         {
261             $this->release_name = $row['name'];
262         }
263         else
264         {
265             $this->release_name = '';
266         }
267         
268         $releases[$this->found_in_release] = $this->release_name;
269         }
270
271         
272         public function set_fixed_in_release() 
273         {
274             static $releases;
275             
276             if ( empty($this->fixed_in_release) ) {
277                 return;
278             }
279             if ( isset($releases[$this->fixed_in_release]) ) {
280                 $this->fixed_in_release_name = $releases[$this->fixed_in_release];
281                 return;
282             }
283             
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: ");
286
287         // Get the id and the name.
288         $row = $this->db->fetchByAssoc($result);
289
290         
291         
292         if($row != null)
293         {
294             $this->fixed_in_release_name = $row['name'];
295         }
296         else
297         {
298             $this->fixed_in_release_name = '';
299         }
300                         
301         $releases[$this->fixed_in_release] = $this->fixed_in_release_name;
302                         
303         }
304         
305         
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');
311
312                 $this->set_release();
313             
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]);
320        
321            $the_array['RELEASE']= $this->release_name;
322            $the_array['BUG_NUMBER'] = $this->bug_number;
323            $the_array['ENCODED_NAME']=$this->name;
324                         
325         return  $the_array;
326         }
327
328         /**
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
331         */
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%'");
337
338         $the_where = "";
339         foreach($where_clauses as $clause)
340         {
341                 if($the_where != "") $the_where .= " or ";
342                 $the_where .= $clause;
343         }
344
345         return $the_where;
346         }
347
348         function set_notification_body($xtpl, $bug)
349         {
350                 global $mod_strings, $app_list_strings;
351
352                 $bug->set_release();
353
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);
363                 return $xtpl;
364         }
365         
366         function bean_implements($interface){
367                 switch($interface){
368                         case 'ACL':return true;
369                 }
370                 return false;
371         }
372         
373         function save($check_notify = FALSE){
374                 return parent::save($check_notify);
375         }
376 }
377
378 function getReleaseDropDown(){
379         static $releases = null;
380         if(!$releases){
381                 $seedRelease = new Release();
382                 $releases = $seedRelease->get_releases(TRUE, "Active");
383         }
384         return $releases;
385 }
386 ?>