]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Bugs/Bug.php
Release 6.5.0
[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-2012 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->custom_fields->getJOIN();
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                                  if($custom_join){
155                                          $query .= $custom_join['select'];
156                                 }
157                                 $query .= " FROM bugs ";
158                                
159
160                 $query .= "                             LEFT JOIN releases ON bugs.found_in_release=releases.id
161                                                                 LEFT JOIN users
162                                 ON bugs.assigned_user_id=users.id";
163                                 $query .= "  ";
164                                                                 if($custom_join){
165                                          $query .= $custom_join['join'];
166                                 }
167             $where_auto = '1=1';
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 ";  
172                         }
173           
174
175                 if($where != "")
176                         $query .= "where $where AND ".$where_auto;
177                 else
178                         $query .= "where ".$where_auto;
179                 if(substr_count($order_by, '.') > 0){
180                         $query .= " ORDER BY $order_by";
181                 }
182                 else if($order_by != "")
183                         $query .= " ORDER BY $order_by";
184                 else
185                         $query .= " ORDER BY bugs.name";
186                 return $query;
187         }
188
189         function create_export_query(&$order_by, &$where, $relate_link_join='')
190         {
191                 $custom_join = $this->custom_fields->getJOIN(true, true,$where);
192                         if($custom_join)
193                                 $custom_join['join'] .= $relate_link_join;
194                 $query = "SELECT
195                                 bugs.*,
196                                 r1.name found_in_release_name,
197                                 r2.name fixed_in_release_name,
198                                 users.user_name assigned_user_name";
199                                  if($custom_join){
200                                                                         $query .=  $custom_join['select'];
201                                                                 }
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
205                                                                 LEFT JOIN users
206                                 ON bugs.assigned_user_id=users.id";
207                                  if($custom_join){
208                                                                         $query .=  $custom_join['join'];
209                                                                 }
210                                 $query .= "";
211                 $where_auto = "  bugs.deleted=0
212                 ";
213
214                 if($where != "")
215                         $query .= " where $where AND ".$where_auto;
216                 else
217                         $query .= " where ".$where_auto;
218
219                 if($order_by != "")
220                         $query .= " ORDER BY $order_by";
221                 else
222                         $query .= " ORDER BY bugs.bug_number";
223
224                 return $query;
225         }
226         function fill_in_additional_list_fields()
227         {
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);
231                 
232 //         $this->set_fixed_in_release();
233         }
234
235         function fill_in_additional_detail_fields()
236         {   
237                 
238             /*
239                 // Fill in the assigned_user_name
240                 $this->assigned_user_name = get_assigned_user_name($this->assigned_user_id);
241         */
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();
247         }
248
249
250         public function set_release() 
251         {
252             static $releases;
253             
254             if ( empty($this->found_in_release) ) {
255                 return;
256             }
257             if ( isset($releases[$this->found_in_release]) ) {
258                 $this->release_name = $releases[$this->found_in_release];
259                 return;
260             }
261             
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: ");
264
265         // Get the id and the name.
266         $row = $this->db->fetchByAssoc($result);
267
268         if($row != null)
269         {
270             $this->release_name = $row['name'];
271         }
272         else
273         {
274             $this->release_name = '';
275         }
276         
277         $releases[$this->found_in_release] = $this->release_name;
278         }
279
280         
281         public function set_fixed_in_release() 
282         {
283             static $releases;
284             
285             if ( empty($this->fixed_in_release) ) {
286                 return;
287             }
288             if ( isset($releases[$this->fixed_in_release]) ) {
289                 $this->fixed_in_release_name = $releases[$this->fixed_in_release];
290                 return;
291             }
292             
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: ");
295
296         // Get the id and the name.
297         $row = $this->db->fetchByAssoc($result);
298
299         
300         
301         if($row != null)
302         {
303             $this->fixed_in_release_name = $row['name'];
304         }
305         else
306         {
307             $this->fixed_in_release_name = '';
308         }
309                         
310         $releases[$this->fixed_in_release] = $this->fixed_in_release_name;
311                         
312         }
313         
314         
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');
320
321                 $this->set_release();
322             
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;
335                         
336         return  $the_array;
337         }
338
339         /**
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
342         */
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%'");
348
349         $the_where = "";
350         foreach($where_clauses as $clause)
351         {
352                 if($the_where != "") $the_where .= " or ";
353                 $the_where .= $clause;
354         }
355
356         return $the_where;
357         }
358
359         function set_notification_body($xtpl, $bug)
360         {
361                 global $mod_strings, $app_list_strings;
362
363                 $bug->set_release();
364
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);
374                 return $xtpl;
375         }
376         
377         function bean_implements($interface){
378                 switch($interface){
379                         case 'ACL':return true;
380                 }
381                 return false;
382         }
383         
384         function save($check_notify = FALSE){
385                 return parent::save($check_notify);
386         }
387 }
388
389 function getReleaseDropDown(){
390         static $releases = null;
391         if(!$releases){
392                 $seedRelease = new Release();
393                 $releases = $seedRelease->get_releases(TRUE, "Active");
394         }
395         return $releases;
396 }
397 ?>