Completed
Branch master (f9052b)
by Michael
02:32
created

ExtgalleryPublicPhoto::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 26 and the first side effect is on line 20.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * ExtGallery Class Manager
4
 *
5
 * You may not change or alter any portion of this comment or credits
6
 * of supporting developers from this source code or any supporting source code
7
 * which is considered copyrighted (c) material of the original comment or credit authors.
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
 * @copyright   {@link http://xoops.org/ XOOPS Project}
13
 * @license     GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
14
 * @author      Zoullou (http://www.zoullou.net)
15
 * @package     ExtGallery
16
 */
17
18
// defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined');
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
19
20
include_once __DIR__ . '/photoHandler.php';
21
include_once __DIR__ . '/publicPerm.php';
22
23
/**
24
 * Class ExtgalleryPublicPhoto
25
 */
26
class ExtgalleryPublicPhoto extends ExtgalleryPhoto
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
27
{
28
    /**
29
     * ExtgalleryPublicPhoto constructor.
30
     */
31
    public function __construct()
32
    {
33
        parent::__construct();
34
    }
35
}
36
37
/**
38
 * Class ExtgalleryPublicPhotoHandler
39
 */
40
class ExtgalleryPublicPhotoHandler extends ExtgalleryPhotoHandler
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
41
{
42
    /**
43
     * ExtgalleryPublicPhotoHandler constructor.
44
     * @param XoopsDatabase $db
45
     */
46
    public function __construct(XoopsDatabase $db)
47
    {
48
        parent::__construct($db, 'public');
49
    }
50
51
    /**
52
     * @param $photo
53
     */
54
    public function deleteFile(XoopsObject $photo = null)
55
    {
56 View Code Duplication
        if (file_exists(XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/thumb/thumb_' . $photo->getVar('photo_name'))) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
57
            unlink(XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/thumb/thumb_' . $photo->getVar('photo_name'));
58
        }
59
60 View Code Duplication
        if (file_exists(XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/medium/' . $photo->getVar('photo_name'))) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
61
            unlink(XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/medium/' . $photo->getVar('photo_name'));
62
        }
63
64 View Code Duplication
        if (file_exists(XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/large/large_' . $photo->getVar('photo_name'))) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
65
            unlink(XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/large/large_' . $photo->getVar('photo_name'));
66
        }
67
68 View Code Duplication
        if ($photo->getVar('photo_orig_name') != ''
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
69
            && file_exists(XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/original/' . $photo->getVar('photo_orig_name'))
70
        ) {
71
            unlink(XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/original/' . $photo->getVar('photo_orig_name'));
72
        }
73
    }
74
75
    /**
76
     * @return array|int|string
77
     */
78
    public function getAllSize()
79
    {
80
        return $this->getSum(null, 'photo_size');
81
    }
82
83
    /**
84
     * @return string
85
     */
86
    public function _getUploadPhotoPath()
87
    {
88
        return XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/';
89
    }
90
91
    /**
92
     * @param $userId
93
     * @param $start
94
     * @param $sortby
95
     * @param $orderby
96
     *
97
     * @return array
98
     */
99
    public function getUserAlbumPhotoPage($userId, $start, $sortby, $orderby)
0 ignored issues
show
Coding Style introduced by
getUserAlbumPhotoPage uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
100
    {
101
        $catHandler = xoops_getModuleHandler('publiccat', 'extgallery');
102
103
        $criteria = new CriteriaCompo();
104
        $criteria->add($catHandler->getCatRestrictCriteria());
105
        $criteria->add(new Criteria('photo_approved', 1));
106
        $criteria->add(new Criteria('uid', $userId));
107
        $criteria->setSort($sortby);
108
        $criteria->setOrder($orderby);
109
        $criteria->setStart($start);
110
        $criteria->setLimit($GLOBALS['xoopsModuleConfig']['nb_column'] * $GLOBALS['xoopsModuleConfig']['nb_line']);
111
112
        return $this->getObjects($criteria);
113
    }
114
115
    /**
116
     * @param $userId
117
     * @param $photoDate
118
     *
119
     * @return array
120
     */
121 View Code Duplication
    public function getUserAlbumPrevPhoto($userId, $photoDate)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
122
    {
123
        $catHandler = xoops_getModuleHandler('publiccat', 'extgallery');
124
125
        $criteria = new CriteriaCompo();
126
        $criteria->add($catHandler->getCatRestrictCriteria());
127
        $criteria->add(new Criteria('photo_approved', 1));
128
        $criteria->add(new Criteria('uid', $userId));
129
        $criteria->add(new Criteria('photo_date', $photoDate, '>'));
130
        $criteria->setSort('photo_date');
131
        $criteria->setOrder('ASC');
132
        $criteria->setLimit(1);
133
134
        return $this->getObjects($criteria);
135
    }
136
137
    /**
138
     * @param $userId
139
     * @param $photoDate
140
     *
141
     * @return array
142
     */
143 View Code Duplication
    public function getUserAlbumNextPhoto($userId, $photoDate)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
144
    {
145
        $catHandler = xoops_getModuleHandler('publiccat', 'extgallery');
146
147
        $criteria = new CriteriaCompo();
148
        $criteria->add($catHandler->getCatRestrictCriteria());
149
        $criteria->add(new Criteria('photo_approved', 1));
150
        $criteria->add(new Criteria('uid', $userId));
151
        $criteria->add(new Criteria('photo_date', $photoDate, '<'));
152
        $criteria->setSort('photo_date');
153
        $criteria->setOrder('DESC');
154
        $criteria->setLimit(1);
155
156
        return $this->getObjects($criteria);
157
    }
158
159
    /**
160
     * @param $userId
161
     * @param $photoDate
162
     *
163
     * @return int
164
     */
165 View Code Duplication
    public function getUserAlbumCurrentPhotoPlace($userId, $photoDate)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
166
    {
167
        $catHandler = xoops_getModuleHandler('publiccat', 'extgallery');
168
169
        $criteria = new CriteriaCompo();
170
        $criteria->add($catHandler->getCatRestrictCriteria());
171
        $criteria->add(new Criteria('photo_approved', 1));
172
        $criteria->add(new Criteria('uid', $userId));
173
        $criteria->add(new Criteria('photo_date', $photoDate, '>='));
174
        $criteria->setSort('photo_date');
175
        $criteria->setOrder('ASC');
176
177
        return $this->getCount($criteria);
178
    }
179
180
    /**
181
     * @param $userId
182
     *
183
     * @return int
184
     */
185
    public function getUserAlbumCount($userId)
186
    {
187
        $catHandler = xoops_getModuleHandler('publiccat', 'extgallery');
188
189
        $criteria = new CriteriaCompo();
190
        $criteria->add($catHandler->getCatRestrictCriteria());
191
        $criteria->add(new Criteria('photo_approved', 1));
192
        $criteria->add(new Criteria('uid', $userId));
193
194
        return $this->getCount($criteria);
195
    }
196
197
    /**
198
     * @param $userId
199
     *
200
     * @return array
201
     */
202 View Code Duplication
    public function getUserPhotoAlbumId($userId)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
203
    {
204
        $criteria = new CriteriaCompo();
205
        $criteria->add(new Criteria('uid', $userId));
206
        $criteria->add(new Criteria('photo_approved', 1));
207
208
        $sql = 'SELECT photo_id FROM ' . $this->db->prefix('extgallery_publicphoto') . ' ' . $criteria->renderWhere() . ' ORDER BY photo_date, photo_id DESC;';
209
210
        $result = $this->db->query($sql);
211
        $ret    = array();
212
        while (false !== ($myrow = $this->db->fetchArray($result))) {
213
            $ret[] = $myrow['photo_id'];
214
        }
215
216
        return $ret;
217
    }
218
}
219