Completed
Branch master (452dd2)
by Pierre-Henry
61:36 queued 26:09
created

ModeratorController::clearPictureCache()   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
2
/**
3
 * @author         Pierre-Henry Soria <[email protected]>
4
 * @copyright      (c) 2012-2017, Pierre-Henry Soria. All Rights Reserved.
5
 * @license        GNU General Public License; See PH7.LICENSE.txt and PH7.COPYRIGHT.txt in the root directory.
6
 * @package        PH7 / App / System / Module / Admin / Controller
7
 */
8
9
namespace PH7;
10
11
use PH7\Framework\Navigation\Page;
12
use PH7\Framework\Layout\Html\Design;
13
use PH7\Framework\Cache\Cache;
14
use PH7\Framework\Url\Header;
15
use PH7\Framework\Mvc\Router\Uri;
16
17
class ModeratorController extends Controller
18
{
19
    const ITEMS_PER_PAGE = 20;
20
21
    /** @var ModeratorModel */
22
    private $oModeratorModel;
23
24
    /** @var Page */
25
    private $oPage;
26
27
    /** @var string */
28
    private $sMsg;
29
30
    public function __construct()
31
    {
32
        parent::__construct();
33
34
        $this->oPage = new Page();
35
        $this->oModeratorModel = new ModeratorModel;
36
        $this->view->oUser = new UserCore;
37
    }
38
39
    public function index()
40
    {
41
        $this->view->page_title = $this->view->h2_title = t('Moderation Panel');
42
43
        $this->output();
0 ignored issues
show
Bug introduced by
The method output() does not seem to exist on object<PH7\ModeratorController>.

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...
44
    }
45
46
    public function pictureAlbum()
47
    {
48
        $this->view->page_title = $this->view->h2_title = t('Photo Albums Moderation');
49
50
        $this->view->total_pages = $this->oPage->getTotalPages(
51
            $this->oModeratorModel->totalPictureAlbums(), self::ITEMS_PER_PAGE
52
        );
53
        $this->view->current_page = $this->oPage->getCurrentPage();
54
        $this->view->albums = $this->oModeratorModel->getAlbumsPicture(
55
            $this->oPage->getFirstItem(), $this->oPage->getNbItemsPerPage()
56
        );
57
58
        $this->output();
0 ignored issues
show
Bug introduced by
The method output() does not seem to exist on object<PH7\ModeratorController>.

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...
59
    }
60
61
    public function picture()
62
    {
63
        $this->view->page_title = $this->view->h2_title = t('Pictures Moderation');
64
65
        $this->view->total_pages = $this->oPage->getTotalPages(
66
            $this->oModeratorModel->totalPictures(), self::ITEMS_PER_PAGE
67
        );
68
        $this->view->current_page = $this->oPage->getCurrentPage();
69
        $this->view->pictures = $this->oModeratorModel->getPictures(
70
            $this->oPage->getFirstItem(), $this->oPage->getNbItemsPerPage()
71
        );
72
73
        $this->output();
0 ignored issues
show
Bug introduced by
The method output() does not seem to exist on object<PH7\ModeratorController>.

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...
74
    }
75
76
    public function videoAlbum()
77
    {
78
        $this->view->page_title = $this->view->h2_title = t('Video Albums Moderation');
79
80
        $this->view->total_pages = $this->oPage->getTotalPages(
81
            $this->oModeratorModel->totalVideoAlbums(), self::ITEMS_PER_PAGE
82
        );
83
        $this->view->current_page = $this->oPage->getCurrentPage();
84
        $this->view->albums = $this->oModeratorModel->getAlbumsVideo(
85
            $this->oPage->getFirstItem(), $this->oPage->getNbItemsPerPage()
86
        );
87
88
        $this->output();
0 ignored issues
show
Bug introduced by
The method output() does not seem to exist on object<PH7\ModeratorController>.

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...
89
    }
90
91
    public function video()
92
    {
93
        $this->design->addCss(PH7_LAYOUT . PH7_SYS . PH7_MOD . 'video/' . PH7_TPL . PH7_TPL_MOD_NAME . PH7_SH . PH7_CSS, 'common.css');
94
95
        $this->view->page_title = $this->view->h2_title = t('Videos Moderation');
96
97
        $this->view->total_pages = $this->oPage->getTotalPages(
98
            $this->oModeratorModel->totalVideos(), self::ITEMS_PER_PAGE
99
        );
100
        $this->view->current_page = $this->oPage->getCurrentPage();
101
        $this->view->videos = $this->oModeratorModel->getVideos(
102
            $this->oPage->getFirstItem(), $this->oPage->getNbItemsPerPage()
103
        );
104
105
        $this->output();
0 ignored issues
show
Bug introduced by
The method output() does not seem to exist on object<PH7\ModeratorController>.

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...
106
    }
107
108
    public function avatar()
109
    {
110
        $this->view->page_title = $this->view->h2_title = t('Avatars Moderation');
111
112
        $this->view->total_pages = $this->oPage->getTotalPages(
113
            $this->oModeratorModel->totalAvatars(), self::ITEMS_PER_PAGE
114
        );
115
        $this->view->current_page = $this->oPage->getCurrentPage();
116
        $this->view->avatars = $this->oModeratorModel->getAvatars(
117
            $this->oPage->getFirstItem(), $this->oPage->getNbItemsPerPage()
118
        );
119
        $this->view->avatarDesign = new AvatarDesignCore; // Avatar Design Class
120
121
        $this->output();
0 ignored issues
show
Bug introduced by
The method output() does not seem to exist on object<PH7\ModeratorController>.

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...
122
    }
123
124
    public function background()
125
    {
126
        $this->view->page_title = $this->view->h2_title = t('Profile Backgrounds Moderation');
127
128
        $this->view->total_pages = $this->oPage->getTotalPages(
129
            $this->oModeratorModel->totalBackgrounds(), self::ITEMS_PER_PAGE
130
        );
131
        $this->view->current_page = $this->oPage->getCurrentPage();
132
        $this->view->backgrounds = $this->oModeratorModel->getBackgrounds(
133
            $this->oPage->getFirstItem(), $this->oPage->getNbItemsPerPage()
134
        );
135
136
        $this->output();
0 ignored issues
show
Bug introduced by
The method output() does not seem to exist on object<PH7\ModeratorController>.

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...
137
    }
138
139
    public function pictureWebcam()
140
    {
141
        Header::redirect(
142
            Uri::get('webcam', 'webcam', 'picture'),
143
            t('Welcome to the Picture Webcam in "administrator mode"')
144
        );
145
    }
146
147
    public function approvedPictureAlbum()
148
    {
149
        if ($this->oModeratorModel->approvedPictureAlbum($this->httpRequest->post('album_id'))) {
150
            $this->clearPictureCache();
151
            $this->sMsg = t('The photo album has been approved!');
152
        } else {
153
            $this->sMsg = t('Oops! The photo album could not be approved!');
154
        }
155
156
        Header::redirect(Uri::get(PH7_ADMIN_MOD, 'moderator', 'picturealbum'), $this->sMsg);
157
    }
158
159
    public function approvedPhoto()
160
    {
161
        if ($this->oModeratorModel->approvedPicture($this->httpRequest->post('picture_id'))) {
162
            $this->clearPictureCache();
163
            $this->sMsg = t('The picture has been approved!');
164
        } else {
165
            $this->sMsg = t('Oops! The picture could not be approved!');
166
        }
167
168
        Header::redirect(Uri::get(PH7_ADMIN_MOD, 'moderator', 'picture'), $this->sMsg);
169
    }
170
171
    public function approvedVideoAlbum()
172
    {
173
        if ($this->oModeratorModel->approvedVideoAlbum($this->httpRequest->post('album_id'))) {
174
            $this->clearVideoCache();
175
            $this->sMsg = t('The video album has been approved!');
176
        } else {
177
            $this->sMsg = t('Oops! The video album could not be approved!');
178
        }
179
180
        Header::redirect(Uri::get(PH7_ADMIN_MOD, 'moderator', 'videoalbum'), $this->sMsg);
181
    }
182
183
    public function approvedVideo()
184
    {
185
        if ($this->oModeratorModel->approvedVideo($this->httpRequest->post('video_id'))) {
186
            $this->clearVideoCache();
187
            $this->sMsg = t('The video has been approved!');
188
        } else {
189
            $this->sMsg = t('Oops! The video could not be approved!');
190
        }
191
192
        Header::redirect(Uri::get(PH7_ADMIN_MOD, 'moderator', 'video'), $this->sMsg);
193
    }
194
195
    public function approvedAvatar()
196
    {
197
        if ($this->oModeratorModel->approvedAvatar($this->httpRequest->post('id'))) {
198
            $this->clearAvatarCache();
199
            $this->sMsg = t('The avatar has been approved!');
200
        } else {
201
            $this->sMsg = t('Oops! The avatar could not be approved!');
202
        }
203
204
        Header::redirect(Uri::get(PH7_ADMIN_MOD, 'moderator', 'avatar'), $this->sMsg);
205
    }
206
207
    public function approvedBackground()
208
    {
209
        if ($this->oModeratorModel->approvedBackground($this->httpRequest->post('id'))) {
210
            $this->clearUserBgCache();
211
            $this->sMsg = t('The wallpaper has been approved!');
212
        } else {
213
            $this->sMsg = t('Oops! The wallpaper could not be approved!');
214
        }
215
216
        Header::redirect(Uri::get(PH7_ADMIN_MOD, 'moderator', 'background'), $this->sMsg);
217
    }
218
219
    public function disapprovedPictureAlbum()
220
    {
221
        if ($this->oModeratorModel->approvedPictureAlbum($this->httpRequest->post('album_id'), '0')) {
222
            $this->clearPictureCache();
223
            $this->sMsg = t('The photo album has been disapproved!');
224
        } else {
225
            $this->sMsg = t('Oops! The photo album could not be disapproved!');
226
        }
227
228
        Header::redirect(Uri::get(PH7_ADMIN_MOD, 'moderator', 'picturealbum'), $this->sMsg);
229
    }
230
231
    public function disapprovedPhoto()
232
    {
233
        if ($this->oModeratorModel->approvedPicture($this->httpRequest->post('picture_id'), '0')) {
234
            $this->clearPictureCache();
235
            $this->sMsg = t('The picture has been disapproved!');
236
        } else {
237
            $this->sMsg = t('Oops! The picture could not be disapproved!');
238
        }
239
240
        Header::redirect(Uri::get(PH7_ADMIN_MOD, 'moderator', 'picture'), $this->sMsg);
241
    }
242
243
    public function disapprovedVideoAlbum()
244
    {
245
        if ($this->oModeratorModel->approvedVideoAlbum($this->httpRequest->post('album_id'), '0')) {
246
            $this->clearVideoCache();
247
            $this->sMsg = t('The video album has been disapproved!');
248
        } else {
249
            $this->sMsg = t('Oops! The video album could not be disapproved!');
250
        }
251
252
        Header::redirect(Uri::get(PH7_ADMIN_MOD, 'moderator', 'videoalbum'), $this->sMsg);
253
    }
254
255
    public function disapprovedVideo()
256
    {
257
        if ($this->oModeratorModel->approvedVideo($this->httpRequest->post('video_id'), '0')) {
258
            $this->clearVideoCache();
259
            $this->sMsg = t('The video has been disapproved!');
260
        } else {
261
            $this->sMsg = t('Oops! The video could not be disapproved!');
262
        }
263
264
        Header::redirect(Uri::get(PH7_ADMIN_MOD, 'moderator', 'video'), $this->sMsg);
265
    }
266
267
    public function disapprovedAvatar()
268
    {
269
        if ($this->oModeratorModel->approvedAvatar($this->httpRequest->post('id'), '0')) {
270
            $this->clearAvatarCache();
271
            $this->sMsg = t('The avatar has been disapproved!');
272
        } else {
273
            $this->sMsg = t('Oops! The avatar could not be disapprove!');
274
        }
275
276
        Header::redirect(Uri::get(PH7_ADMIN_MOD, 'moderator', 'avatar'), $this->sMsg);
277
    }
278
279
    public function disapprovedBackground()
280
    {
281
        if ($this->oModeratorModel->approvedBackground($this->httpRequest->post('id'), '0')) {
282
            $this->clearUserBgCache();
283
            $this->sMsg = t('The wallpaper has been disapproved!');
284
        } else {
285
            $this->sMsg = t('Oops! The wallpaper could not be disapprove!');
286
        }
287
288
        Header::redirect(Uri::get(PH7_ADMIN_MOD, 'moderator', 'background'), $this->sMsg);
289
    }
290
291
    public function deletePictureAlbum()
292
    {
293
        if ((new PictureCoreModel)->deletePhoto($this->httpRequest->post('id'), $this->httpRequest->post('album_id'))
294
            && $this->oModeratorModel->deletePictureAlbum($this->httpRequest->post('album_id'))) {
295
            $sDir = PH7_PATH_PUBLIC_DATA_SYS_MOD . 'picture/img/' . $this->httpRequest->post('username') . PH7_DS . $this->httpRequest->post('album_id') . PH7_DS;
296
            $this->file->deleteDir($sDir);
297
            $this->clearPictureCache();
298
            $this->sMsg = t('The photo album has been deleted!');
299
        } else {
300
            $this->sMsg = t('Oops! The photo album could not be deleted');
301
        }
302
303
        Header::redirect(Uri::get(PH7_ADMIN_MOD, 'moderator', 'picturealbum'), $this->sMsg);
304
    }
305
306
    public function deletePhoto()
307
    {
308
        $bPicture = (new PictureCoreModel)->deletePhoto($this->httpRequest->post('id'), $this->httpRequest->post('album_id'), $this->httpRequest->post('picture_id'));
309
310
        if ($bPicture) {
311
            (new PictureCore)->deletePhoto($this->httpRequest->post('album_id'), $this->httpRequest->post('username'), $this->httpRequest->post('picture_link'));
312
            $this->clearPictureCache();
313
            $this->sMsg = t('The picture has been deleted!');
314
        } else {
315
            $this->sMsg = t('Oops! The picture could not be deleted!');
316
        }
317
318
        Header::redirect(Uri::get(PH7_ADMIN_MOD, 'moderator', 'picture'), $this->sMsg);
319
    }
320
321
    public function deleteVideoAlbum()
322
    {
323
        if ((new VideoCoreModel)->deleteVideo($this->httpRequest->post('id'), $this->httpRequest->post('album_id'))
324
            && $this->oModeratorModel->deleteVideoAlbum($this->httpRequest->post('album_id'))) {
325
            $sDir = PH7_PATH_PUBLIC_DATA_SYS_MOD . 'video/file/' . $this->httpRequest->post('username') . PH7_DS . $this->httpRequest->post('album_id') . PH7_DS;
326
            $this->file->deleteDir($sDir);
327
            $this->clearVideoCache();
328
            $this->sMsg = t('The video album has been deleted!');
329
        } else {
330
            $this->sMsg = t('Oops! The video album could not be deleted');
331
        }
332
333
        Header::redirect(Uri::get(PH7_ADMIN_MOD, 'moderator', 'videoalbum'), $this->sMsg);
334
    }
335
336
    public function deleteVideo()
337
    {
338
        $bVideo = (new VideoCoreModel)->deleteVideo($this->httpRequest->post('id'), $this->httpRequest->post('album_id'), $this->httpRequest->post('video_id'));
339
340
        if ($bVideo) {
341
            (new VideoCore)->deleteVideo($this->httpRequest->post('album_id'), $this->httpRequest->post('username'), $this->httpRequest->post('video_link'));
342
            $this->clearVideoCache();
343
            $this->sMsg = t('The video has been deleted!');
344
        } else {
345
            $this->sMsg = t('Oops! The video could not be deleted!');
346
        }
347
348
        Header::redirect(Uri::get(PH7_ADMIN_MOD, 'moderator', 'video'), $this->sMsg);
349
    }
350
351
    public function deleteAvatar()
352
    {
353
        (new Admin)->deleteAvatar($this->httpRequest->post('id'), $this->httpRequest->post('username'));
354
        $this->clearAvatarCache();
355
356
        Header::redirect(Uri::get(PH7_ADMIN_MOD, 'moderator', 'avatar'), $this->sMsg);
357
    }
358
359
    public function deleteBackground()
360
    {
361
        (new Admin)->deleteBackground($this->httpRequest->post('id'), $this->httpRequest->post('username'));
362
        $this->clearUserBgCache();
363
364
        Header::redirect(Uri::get(PH7_ADMIN_MOD, 'moderator', 'background'), $this->sMsg);
365
    }
366
367
    /**
368
     * Clear PictureCoreModel Cache
369
     *
370
     * @return void
371
     */
372
    private function clearPictureCache()
373
    {
374
        (new Cache)->start(PictureCoreModel::CACHE_GROUP, null, null)->clear();
375
    }
376
377
    /**
378
     * Clear VideoCoreModel Cache
379
     *
380
     * @return void
381
     */
382
    private function clearVideoCache()
383
    {
384
        (new Cache)->start(VideoCoreModel::CACHE_GROUP, null, null)->clear();
385
    }
386
387
    /**
388
     * Clear "Design Avatar" & "UserCoreModel Avatar" Cache
389
     *
390
     * @return void
391
     */
392
    private function clearAvatarCache()
393
    {
394
        (new Cache)
395
            ->start(Design::CACHE_AVATAR_GROUP . $this->httpRequest->post('username'), null, null)->clear()
396
            ->start(UserCoreModel::CACHE_GROUP, 'avatar' . $this->httpRequest->post('id'), null)->clear();
397
    }
398
399
    /**
400
     * Clear UserCoreModel Background Cache
401
     *
402
     * @return void
403
     */
404
    private function clearUserBgCache()
405
    {
406
        (new Cache)->start(UserCoreModel::CACHE_GROUP, 'background' . $this->httpRequest->post('id'), null)->clear();
407
    }
408
}
409