AdsenseHandler::getAdsensesByTag()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 2
nop 0
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
1
<?php namespace XoopsModules\Smartobject;
2
3
/*
4
 * You may not change or alter any portion of this comment or credits
5
 * of supporting developers from this source code or any supporting source code
6
 * which is considered copyrighted (c) material of the original comment or credit authors.
7
 *
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 */
12
13
/**
14
 * @copyright    XOOPS Project https://xoops.org/
15
 * @license      GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
16
 * @package
17
 * @since
18
 * @author     XOOPS Development Team
19
 */
20
21
use XoopsModules\Smartobject;
22
23
// defined('XOOPS_ROOT_PATH') || die('Restricted access');
24
25
//require_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobject.php';
26
27
28
/**
29
 * Class SmartobjectAdsenseHandler
30
 */
31
class AdsenseHandler extends Smartobject\PersistableObjectHandler
32
{
33
    public $adFormats;
34
    public $adFormatsList;
35
    public $objects = false;
36
//    public $classname = Adsense::class;
37
38
    /**
39
     * SmartobjectAdsenseHandler constructor.
40
     * @param \XoopsDatabase $db
41
     */
42
    public function __construct(\XoopsDatabase $db)
43
    {
44
        parent::__construct($db, Adsense::class, 'adsenseid', 'description', '', 'smartobject');
45
        $this->adFormats     = [];
46
        $this->adFormatsList = [];
47
48
        $this->adFormats['728x90_as']['caption'] = '728 X 90 Leaderboard';
49
        $this->adFormats['728x90_as']['width']   = 728;
50
        $this->adFormats['728x90_as']['height']  = 90;
51
        $this->adFormatsList['728x90_as']        = $this->adFormats['728x90_as']['caption'];
52
53
        $this->adFormats['468x60_as']['caption'] = '468 X 60 Banner';
54
        $this->adFormats['468x60_as']['width']   = 468;
55
        $this->adFormats['468x60_as']['height']  = 60;
56
        $this->adFormatsList['468x60_as']        = $this->adFormats['468x60_as']['caption'];
57
58
        $this->adFormats['234x60_as']['caption'] = '234 X 60 Half Banner';
59
        $this->adFormats['234x60_as']['width']   = 234;
60
        $this->adFormats['234x60_as']['height']  = 60;
61
        $this->adFormatsList['234x60_as']        = $this->adFormats['234x60_as']['caption'];
62
63
        $this->adFormats['120x600_as']['caption'] = '120 X 600 Skyscraper';
64
        $this->adFormats['120x600_as']['width']   = 120;
65
        $this->adFormats['120x600_as']['height']  = 600;
66
        $this->adFormatsList['120x600_as']        = $this->adFormats['120x600_as']['caption'];
67
68
        $this->adFormats['160x600_as']['caption'] = '160 X 600 Wide Skyscraper';
69
        $this->adFormats['160x600_as']['width']   = 160;
70
        $this->adFormats['160x600_as']['height']  = 600;
71
        $this->adFormatsList['160x600_as']        = $this->adFormats['160x600_as']['caption'];
72
73
        $this->adFormats['120x240_as']['caption'] = '120 X 240 Vertical Banner';
74
        $this->adFormats['120x240_as']['width']   = 120;
75
        $this->adFormats['120x240_as']['height']  = 240;
76
        $this->adFormatsList['120x240_as']        = $this->adFormats['120x240_as']['caption'];
77
78
        $this->adFormats['336x280_as']['caption'] = '336 X 280 Large Rectangle';
79
        $this->adFormats['336x280_as']['width']   = 136;
80
        $this->adFormats['336x280_as']['height']  = 280;
81
        $this->adFormatsList['336x280_as']        = $this->adFormats['336x280_as']['caption'];
82
83
        $this->adFormats['300x250_as']['caption'] = '300 X 250 Medium Rectangle';
84
        $this->adFormats['300x250_as']['width']   = 300;
85
        $this->adFormats['300x250_as']['height']  = 250;
86
        $this->adFormatsList['300x250_as']        = $this->adFormats['300x250_as']['caption'];
87
88
        $this->adFormats['250x250_as']['caption'] = '250 X 250 Square';
89
        $this->adFormats['250x250_as']['width']   = 250;
90
        $this->adFormats['250x250_as']['height']  = 250;
91
        $this->adFormatsList['250x250_as']        = $this->adFormats['250x250_as']['caption'];
92
93
        $this->adFormats['200x200_as']['caption'] = '200 X 200 Small Square';
94
        $this->adFormats['200x200_as']['width']   = 200;
95
        $this->adFormats['200x200_as']['height']  = 200;
96
        $this->adFormatsList['200x200_as']        = $this->adFormats['200x200_as']['caption'];
97
98
        $this->adFormats['180x150_as']['caption'] = '180 X 150 Small Rectangle';
99
        $this->adFormats['180x150_as']['width']   = 180;
100
        $this->adFormats['180x150_as']['height']  = 150;
101
        $this->adFormatsList['180x150_as']        = $this->adFormats['180x150_as']['caption'];
102
103
        $this->adFormats['125x125_as']['caption'] = '125 X 125 Button';
104
        $this->adFormats['125x125_as']['width']   = 125;
105
        $this->adFormats['125x125_as']['height']  = 125;
106
        $this->adFormatsList['125x125_as']        = $this->adFormats['125x125_as']['caption'];
107
    }
108
109
    /**
110
     * @return array
111
     */
112
    public function getFormats()
113
    {
114
        return $this->adFormatsList;
115
    }
116
117
    /**
118
     * @param $obj
119
     * @return bool
120
     */
121
    public function beforeSave($obj)
122
    {
123
        if ('' === $obj->getVar('tag')) {
124
            $obj->setVar('tag', $title = $obj->generateTag());
125
        }
126
127
        return true;
128
    }
129
130
    /**
131
     * @return array|bool
132
     */
133
    public function getAdsensesByTag()
134
    {
135
        if (!$this->objects) {
136
            $adsensesObj =& $this->getObjects(null, true);
137
            $ret         = [];
138
            foreach ($adsensesObj as $adsenseObj) {
139
                $ret[$adsenseObj->getVar('tag')] = $adsenseObj;
140
            }
141
            $this->objects = $ret;
0 ignored issues
show
Documentation Bug introduced by
It seems like $ret of type array is incompatible with the declared type boolean of property $objects.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
142
        }
143
144
        return $this->objects;
145
    }
146
}
147