Passed
Push — scrutinizer-code-quality ( 09f5a1...c4c5fb )
by Adam
56:05 queued 14:08
created

Favorites::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?PHP
2
/*********************************************************************************
3
 * SugarCRM Community Edition is a customer relationship management program developed by
4
 * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
5
 * SuiteCRM is an extension to SugarCRM Community Edition developed by Salesagility Ltd.
6
 * Copyright (C) 2011 - 2014 Salesagility Ltd.
7
 *
8
 * This program is free software; you can redistribute it and/or modify it under
9
 * the terms of the GNU Affero General Public License version 3 as published by the
10
 * Free Software Foundation with the addition of the following permission added
11
 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
12
 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
13
 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
14
 *
15
 * This program is distributed in the hope that it will be useful, but WITHOUT
16
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17
 * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
18
 * details.
19
 *
20
 * You should have received a copy of the GNU Affero General Public License along with
21
 * this program; if not, see http://www.gnu.org/licenses or write to the Free
22
 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23
 * 02110-1301 USA.
24
 *
25
 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
26
 * SW2-130, Cupertino, CA 95014, USA. or at email address [email protected].
27
 *
28
 * The interactive user interfaces in modified source and object code versions
29
 * of this program must display Appropriate Legal Notices, as required under
30
 * Section 5 of the GNU Affero General Public License version 3.
31
 *
32
 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
33
 * these Appropriate Legal Notices must retain the display of the "Powered by
34
 * SugarCRM" logo and "Supercharged by SuiteCRM" logo. If the display of the logos is not
35
 * reasonably feasible for  technical reasons, the Appropriate Legal Notices must
36
 * display the words  "Powered by SugarCRM" and "Supercharged by SuiteCRM".
37
 ********************************************************************************/
38
39
/**
40
 * THIS CLASS IS FOR DEVELOPERS TO MAKE CUSTOMIZATIONS IN
41
 */
42 1
require_once('modules/Favorites/Favorites_sugar.php');
43
44
class Favorites extends Favorites_sugar
45
{
46
47 9
    public function __construct()
48
    {
49 9
        parent::__construct();
50 9
    }
51
52
    /**
53
     * @deprecated deprecated since version 7.6, PHP4 Style Constructors are deprecated and will be remove in 7.8, please update your code, use __construct instead
54
     */
55
    public function Favorites(){
56
        $deprecatedMessage = 'PHP4 Style Constructors are deprecated and will be remove in 7.8, please update your code';
57
        if(isset($GLOBALS['log'])) {
58
            $GLOBALS['log']->deprecated($deprecatedMessage);
59
        }
60
        else {
61
            trigger_error($deprecatedMessage, E_USER_DEPRECATED);
62
        }
63
        self::__construct();
64
    }
65
66
67 1
    public function deleteFavorite($id){
68 1
        if($id){
69
            $favorite_record = BeanFactory::getBean('Favorites',$id);
70
            $favorite_record->deleted = 1;
0 ignored issues
show
Documentation Bug introduced by
The property $deleted was declared of type boolean, but 1 is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
71
            $favorite_record->save();
72
            return true;
73
        }else{
74 1
            return false;
75
        }
76
77
    }
78
79 1
    public function getFavoriteID($module, $record_id)
80
    {
81 1
        global $db, $current_user;
82 1
        $query = "SELECT id FROM favorites WHERE parent_id= '" . $record_id . "' AND parent_type = '" . $module . "' AND assigned_user_id = '" . $current_user->id . "' AND deleted = 0 ORDER BY date_entered desc";
83 1
        return $db->getOne($query);
84
    }
85
86 1
    public function getCurrentUserSidebarFavorites($id = null)
87
    {
88 1
        global $db, $current_user;
89
90 1
        $return_array = array();
91
92 1
        if($id){
93 1
            $query = "SELECT parent_id, parent_type FROM favorites WHERE assigned_user_id = '" . $current_user->id . "' AND parent_id = '" . $id . "' AND deleted = 0 ORDER BY date_entered desc";
94
        }else{
95 1
            $query = "SELECT parent_id, parent_type FROM favorites WHERE assigned_user_id = '" . $current_user->id . "' AND deleted = 0 ORDER BY date_entered desc";
96
        }
97
98 1
        $result = $db->query($query);
99
100 1
        $i = 0;
101 1
        while ($row = $db->fetchByAssoc($result)) {
102
103
            $bean = BeanFactory::getBean($row['parent_type'],$row['parent_id']);
104
            $return_array[$i]['item_summary'] = $bean->name;
105
            $return_array[$i]['item_summary_short'] = to_html(getTrackerSubstring($bean->name));
106
            $return_array[$i]['id'] = $row['parent_id'];
107
            $return_array[$i]['module_name'] = $row['parent_type'];
108
            $return_array[$i]['image'] = SugarThemeRegistry::current() ->getImage($row['parent_type'],'border="0" align="absmiddle"',null,null,'.gif',$bean->name);
109
110
            $i++;
111
        }
112
113 1
        return $return_array;
114
    }
115
116
}
117
118
?>
119