Completed
Push — master ( 047d50...4f5633 )
by Michael
02:19
created

PublicPhotoHandler::getUploadPhotoPath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php namespace XoopsModules\Extgallery;
2
3
/**
4
 * ExtGallery Class Manager
5
 *
6
 * You may not change or alter any portion of this comment or credits
7
 * of supporting developers from this source code or any supporting source code
8
 * which is considered copyrighted (c) material of the original comment or credit authors.
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
 *
13
 * @copyright   {@link https://xoops.org/ XOOPS Project}
14
 * @license     GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
15
 * @author      Zoullou (http://www.zoullou.net)
16
 * @package     ExtGallery
17
 */
18
19
use XoopsModules\Extgallery;
20
21
// defined('XOOPS_ROOT_PATH') || die('Restricted access');
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...
22
23
//require_once __DIR__ . '/photoHandler.php';
0 ignored issues
show
Unused Code Comprehensibility introduced by
48% 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...
24
//require_once __DIR__ . '/publicPerm.php';
25
26
27
/**
28
 * Class Extgallery\PublicPhotoHandler
29
 */
30
class PublicPhotoHandler extends Extgallery\PhotoHandler
31
{
32
    /**
33
     * Extgallery\PublicPhotoHandler constructor.
34
     * @param \XoopsDatabase $db
35
     */
36
    public function __construct(\XoopsDatabase $db)
0 ignored issues
show
Bug introduced by
The type XoopsDatabase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
37
    {
38
        parent::__construct($db, 'public');
39
    }
40
41
    /**
42
     * @param $photo
43
     */
44
    public function deleteFile(\XoopsObject $photo = null)
0 ignored issues
show
Bug introduced by
The type XoopsObject was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
45
    {
46
        if (file_exists(XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/thumb/thumb_' . $photo->getVar('photo_name'))) {
0 ignored issues
show
Bug introduced by
The constant XoopsModules\Extgallery\XOOPS_ROOT_PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The method getVar() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

46
        if (file_exists(XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/thumb/thumb_' . $photo->/** @scrutinizer ignore-call */ getVar('photo_name'))) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
47
            unlink(XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/thumb/thumb_' . $photo->getVar('photo_name'));
48
        }
49
50
        if (file_exists(XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/medium/' . $photo->getVar('photo_name'))) {
51
            unlink(XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/medium/' . $photo->getVar('photo_name'));
52
        }
53
54
        if (file_exists(XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/large/large_' . $photo->getVar('photo_name'))) {
55
            unlink(XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/large/large_' . $photo->getVar('photo_name'));
56
        }
57
58
        if ('' != $photo->getVar('photo_orig_name')
59
            && file_exists(XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/original/' . $photo->getVar('photo_orig_name'))) {
60
            unlink(XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/original/' . $photo->getVar('photo_orig_name'));
61
        }
62
    }
63
64
    /**
65
     * @return array|int|string
66
     */
67
    public function getAllSize()
68
    {
69
        return $this->getSum(null, 'photo_size');
70
    }
71
72
    /**
73
     * @return string
74
     */
75
    public function getUploadPhotoPath()
76
    {
77
        return XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/';
0 ignored issues
show
Bug introduced by
The constant XoopsModules\Extgallery\XOOPS_ROOT_PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
78
    }
79
80
    /**
81
     * @param $userId
82
     * @param $start
83
     * @param $sortby
84
     * @param $orderby
85
     *
86
     * @return array
87
     */
88
    public function getUserAlbumPhotoPage($userId, $start, $sortby, $orderby)
89
    {
90
        $catHandler = Extgallery\Helper::getInstance()->getHandler('PublicCategory');
91
92
        $criteria = new \CriteriaCompo();
0 ignored issues
show
Bug introduced by
The type CriteriaCompo was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
93
        $criteria->add($catHandler->getCatRestrictCriteria());
94
        $criteria->add(new \Criteria('photo_approved', 1));
0 ignored issues
show
Bug introduced by
The type Criteria was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
95
        $criteria->add(new \Criteria('uid', $userId));
96
        $criteria->setSort($sortby);
97
        $criteria->setOrder($orderby);
98
        $criteria->setStart($start);
99
        $criteria->setLimit($GLOBALS['xoopsModuleConfig']['nb_column'] * $GLOBALS['xoopsModuleConfig']['nb_line']);
100
101
        return $this->getObjects($criteria);
102
    }
103
104
    /**
105
     * @param $userId
106
     * @param $photoDate
107
     *
108
     * @return array
109
     */
110
    public function getUserAlbumPrevPhoto($userId, $photoDate)
111
    {
112
        $catHandler = Extgallery\Helper::getInstance()->getHandler('PublicCategory');
113
114
        $criteria = new \CriteriaCompo();
115
        $criteria->add($catHandler->getCatRestrictCriteria());
116
        $criteria->add(new \Criteria('photo_approved', 1));
117
        $criteria->add(new \Criteria('uid', $userId));
118
        $criteria->add(new \Criteria('photo_date', $photoDate, '>'));
119
        $criteria->setSort('photo_date');
120
        $criteria->setOrder('ASC');
121
        $criteria->setLimit(1);
122
123
        return $this->getObjects($criteria);
124
    }
125
126
    /**
127
     * @param $userId
128
     * @param $photoDate
129
     *
130
     * @return array
131
     */
132
    public function getUserAlbumNextPhoto($userId, $photoDate)
133
    {
134
        $catHandler = Extgallery\Helper::getInstance()->getHandler('PublicCategory');
135
136
        $criteria = new \CriteriaCompo();
137
        $criteria->add($catHandler->getCatRestrictCriteria());
138
        $criteria->add(new \Criteria('photo_approved', 1));
139
        $criteria->add(new \Criteria('uid', $userId));
140
        $criteria->add(new \Criteria('photo_date', $photoDate, '<'));
141
        $criteria->setSort('photo_date');
142
        $criteria->setOrder('DESC');
143
        $criteria->setLimit(1);
144
145
        return $this->getObjects($criteria);
146
    }
147
148
    /**
149
     * @param $userId
150
     * @param $photoDate
151
     *
152
     * @return int
153
     */
154
    public function getUserAlbumCurrentPhotoPlace($userId, $photoDate)
155
    {
156
        $catHandler = Extgallery\Helper::getInstance()->getHandler('PublicCategory');
157
158
        $criteria = new \CriteriaCompo();
159
        $criteria->add($catHandler->getCatRestrictCriteria());
160
        $criteria->add(new \Criteria('photo_approved', 1));
161
        $criteria->add(new \Criteria('uid', $userId));
162
        $criteria->add(new \Criteria('photo_date', $photoDate, '>='));
163
        $criteria->setSort('photo_date');
164
        $criteria->setOrder('ASC');
165
166
        return $this->getCount($criteria);
167
    }
168
169
    /**
170
     * @param $userId
171
     *
172
     * @return int
173
     */
174
    public function getUserAlbumCount($userId)
175
    {
176
        $catHandler = Extgallery\Helper::getInstance()->getHandler('PublicCategory');
177
178
        $criteria = new \CriteriaCompo();
179
        $criteria->add($catHandler->getCatRestrictCriteria());
180
        $criteria->add(new \Criteria('photo_approved', 1));
181
        $criteria->add(new \Criteria('uid', $userId));
182
183
        return $this->getCount($criteria);
184
    }
185
186
    /**
187
     * @param $userId
188
     *
189
     * @return array
190
     */
191
    public function getUserPhotoAlbumId($userId)
192
    {
193
        $criteria = new \CriteriaCompo();
194
        $criteria->add(new \Criteria('uid', $userId));
195
        $criteria->add(new \Criteria('photo_approved', 1));
196
197
        $sql = 'SELECT photo_id FROM ' . $this->db->prefix('extgallery_publicphoto') . ' ' . $criteria->renderWhere() . ' ORDER BY photo_date, photo_id DESC;';
198
199
        $result = $this->db->query($sql);
200
        $ret    = [];
201
        while (false !== ($myrow = $this->db->fetchArray($result))) {
202
            $ret[] = $myrow['photo_id'];
203
        }
204
205
        return $ret;
206
    }
207
}
208