Passed
Branch master (410c7b)
by Michael
03:30
created

GroupsHandler   B

Complexity

Total Complexity 49

Size/Duplication

Total Lines 617
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 49
eloc 251
c 1
b 1
f 0
dl 0
loc 617
rs 8.48

12 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 15 2
A get2() 0 21 3
B getObjects() 0 44 7
A create() 0 14 2
A deleteAll() 0 16 4
B receiveGroup() 0 115 6
A renderFormSubmit() 0 27 1
B getGroups() 0 55 6
A renderFormEdit() 0 65 1
A getCount() 0 18 4
A delete() 0 25 4
B insert2() 0 78 9

How to fix   Complexity   

Complex Class

Complex classes like GroupsHandler often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use GroupsHandler, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
declare(strict_types=1);
4
5
namespace XoopsModules\Suico;
6
7
/*
8
 You may not change or alter any portion of this comment or credits
9
 of supporting developers from this source code or any supporting source code
10
 which is considered copyrighted (c) material of the original comment or credit authors.
11
 
12
 This program is distributed in the hope that it will be useful,
13
 but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
*/
16
17
/**
18
 * @category        Module
19
 * @package         suico
20
 * @copyright       {@link https://xoops.org/ XOOPS Project}
21
 * @license         GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html)
22
 * @author          Marcello Brandão aka  Suico, Mamba, LioMJ  <https://xoops.org>
23
 */
24
25
use CriteriaElement;
26
use XoopsDatabase;
27
use XoopsFormButton;
28
use XoopsFormFile;
29
use XoopsFormHidden;
30
use XoopsFormLabel;
31
use XoopsFormText;
32
use XoopsFormTextArea;
33
use XoopsMediaUploader;
34
use XoopsObject;
35
use XoopsPersistableObjectHandler;
36
use XoopsThemeForm;
37
38
/**
39
 * Protection against inclusion outside the site
40
 */
41
if (!\defined('XOOPS_ROOT_PATH')) {
42
    die('XOOPS root path not defined');
43
}
44
45
// -------------------------------------------------------------------------
46
// ------------------Groups user handler class -------------------
47
// -------------------------------------------------------------------------
48
49
/**
50
 * suico_groupshandler class.
51
 * This class provides simple mecanisme for Groups object
52
 */
53
class GroupsHandler extends XoopsPersistableObjectHandler
54
{
55
    public $helper;
56
57
    public $isAdmin;
58
59
    /**
60
     * Constructor
61
     * @param \XoopsDatabase|null              $xoopsDatabase
62
     * @param \XoopsModules\Suico\Helper|null $helper
63
     */
64
65
    public function __construct(
66
        ?XoopsDatabase $xoopsDatabase = null,
67
        $helper = null
68
    ) {
69
        /** @var \XoopsModules\Suico\Helper $this ->helper */
70
71
        if (null === $helper) {
72
            $this->helper = Helper::getInstance();
0 ignored issues
show
Bug introduced by
The property helper does not seem to exist on XoopsModules\Suico\Helper.
Loading history...
73
        } else {
74
            $this->helper = $helper;
75
        }
76
77
        $isAdmin = $this->helper->isUserAdmin();
0 ignored issues
show
Unused Code introduced by
The assignment to $isAdmin is dead and can be removed.
Loading history...
78
79
        parent::__construct($xoopsDatabase, 'suico_groups', Groups::class, 'group_id', 'group_title');
80
    }
81
82
    /**
83
     * create a new Groups
84
     *
85
     * @param bool $isNew flag the new objects as "new"?
86
     * @return \XoopsObject Groups
87
     */
88
89
    public function create(
90
        $isNew = true
91
    ) {
92
        $obj = parent::create($isNew);
93
94
        if ($isNew) {
95
            $obj->setNew();
96
        } else {
97
            $obj->unsetNew();
98
        }
99
100
        $obj->helper = $this->helper;
101
102
        return $obj;
103
    }
104
105
    /**
106
     * retrieve a Groups
107
     *
108
     * @param int  $id of the Groups
109
     * @param null $fields
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $fields is correct as it would always require null to be passed?
Loading history...
110
     * @return mixed reference to the {@link Groups} object, FALSE if failed
111
     */
112
113
    public function get2(
114
        $id = null,
115
        $fields = null
0 ignored issues
show
Unused Code introduced by
The parameter $fields is not used and could be removed. ( Ignorable by Annotation )

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

115
        /** @scrutinizer ignore-unused */ $fields = null

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
116
    ) {
117
        $sql = 'SELECT * FROM ' . $this->db->prefix('suico_groups') . ' WHERE group_id=' . $id;
118
119
        if (!$result = $this->db->query($sql)) {
120
            return false;
121
        }
122
123
        $numrows = $this->db->getRowsNum($result);
124
125
        if (1 === $numrows) {
126
            $suico_groups = new Groups();
127
128
            $suico_groups->assignVars($this->db->fetchArray($result));
129
130
            return $suico_groups;
131
        }
132
133
        return false;
134
    }
135
136
    /**
137
     * insert a new Groups in the database
138
     *
139
     * @param \XoopsObject $xoopsObject   reference to the {@link Groups}
140
     *                                    object
141
     * @param bool         $force
142
     * @return bool FALSE if failed, TRUE if already present and unchanged or successful
143
     */
144
145
    public function insert2(
146
        XoopsObject $xoopsObject,
147
        $force = false
148
    ) {
149
        global $xoopsConfig;
150
151
        if (!$xoopsObject instanceof Groups) {
152
            return false;
153
        }
154
155
        if (!$xoopsObject->isDirty()) {
156
            return true;
157
        }
158
159
        if (!$xoopsObject->cleanVars()) {
160
            return false;
161
        }
162
163
        foreach ($xoopsObject->cleanVars as $k => $v) {
164
            ${$k} = $v;
165
        }
166
        //        $now = 'date_add(now(), interval ' . $xoopsConfig['server_TZ'] . ' hour)';
167
        if ($xoopsObject->isNew()) {
168
            // ajout/modification d'un Groups
169
170
            $xoopsObject = new Groups();
171
172
            $format = 'INSERT INTO %s (group_id, owner_uid, group_title, group_desc, group_img)';
173
174
            $format .= 'VALUES (%u, %u, %s, %s, %s)';
175
176
            $sql = \sprintf(
177
                $format,
178
                $this->db->prefix('suico_groups'),
179
                $group_id,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $group_id seems to be never defined.
Loading history...
180
                $owner_uid,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $owner_uid seems to be never defined.
Loading history...
181
                $this->db->quoteString($group_title),
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $group_title does not exist. Did you maybe mean $group_id?
Loading history...
182
                $this->db->quoteString($group_desc),
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $group_desc does not exist. Did you maybe mean $group_id?
Loading history...
183
                $this->db->quoteString($group_img)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $group_img does not exist. Did you maybe mean $group_id?
Loading history...
184
            );
185
186
            $force = true;
187
        } else {
188
            $format = 'UPDATE %s SET ';
189
190
            $format .= 'group_id=%u, owner_uid=%u, group_title=%s, group_desc=%s, group_img=%s';
191
192
            $format .= ' WHERE group_id = %u';
193
194
            $sql = \sprintf(
195
                $format,
196
                $this->db->prefix('suico_groups'),
197
                $group_id,
198
                $owner_uid,
199
                $this->db->quoteString($group_title),
200
                $this->db->quoteString($group_desc),
201
                $this->db->quoteString($group_img),
202
                $group_id
203
            );
204
        }
205
206
        if ($force) {
207
            $result = $this->db->queryF($sql);
208
        } else {
209
            $result = $this->db->query($sql);
210
        }
211
212
        if (!$result) {
213
            return false;
214
        }
215
216
        if (empty($group_id)) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $group_id seems to never exist and therefore empty should always be true.
Loading history...
217
            $group_id = $this->db->getInsertId();
218
        }
219
220
        $xoopsObject->assignVar('group_id', $group_id);
221
222
        return true;
223
    }
224
225
    /**
226
     * delete a Groups from the database
227
     *
228
     * @param \XoopsObject $xoopsObject reference to the Groups to delete
229
     * @param bool         $force
230
     * @return bool FALSE if failed.
231
     */
232
233
    public function delete(
234
        XoopsObject $xoopsObject,
235
        $force = false
236
    ) {
237
        if (!$xoopsObject instanceof Groups) {
238
            return false;
239
        }
240
241
        $sql = \sprintf(
242
            'DELETE FROM %s WHERE group_id = %u',
243
            $this->db->prefix('suico_groups'),
244
            $xoopsObject->getVar('group_id')
0 ignored issues
show
Bug introduced by
It seems like $xoopsObject->getVar('group_id') can also be of type array and array; however, parameter $args of sprintf() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

244
            /** @scrutinizer ignore-type */ $xoopsObject->getVar('group_id')
Loading history...
245
        );
246
247
        if ($force) {
248
            $result = $this->db->queryF($sql);
249
        } else {
250
            $result = $this->db->query($sql);
251
        }
252
253
        if (!$result) {
254
            return false;
255
        }
256
257
        return true;
258
    }
259
260
    /**
261
     * retrieve suico_groupss from the database
262
     *
263
     * @param \CriteriaElement|\CriteriaCompo|null $criteriaElement {@link \CriteriaElement} conditions to be met
264
     * @param bool                                 $id_as_key       use the UID as key for the array?
265
     * @param bool                                 $as_object
266
     * @return array array of {@link Groups} objects
267
     */
268
269
    public function &getObjects(
270
        ?CriteriaElement $criteriaElement = null,
271
        $id_as_key = false,
272
        $as_object = true
273
    ) {
274
        $ret = [];
275
276
        $limit = $start = 0;
277
278
        $sql = 'SELECT * FROM ' . $this->db->prefix('suico_groups');
279
280
        if (isset($criteriaElement) && $criteriaElement instanceof CriteriaElement) {
281
            $sql .= ' ' . $criteriaElement->renderWhere();
0 ignored issues
show
Bug introduced by
The method renderWhere() does not exist on CriteriaElement. Did you maybe mean render()? ( Ignorable by Annotation )

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

281
            $sql .= ' ' . $criteriaElement->/** @scrutinizer ignore-call */ renderWhere();

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...
282
283
            if ('' !== $criteriaElement->getSort()) {
284
                $sql .= ' ORDER BY ' . $criteriaElement->getSort() . ' ' . $criteriaElement->getOrder();
285
            }
286
287
            $limit = $criteriaElement->getLimit();
288
289
            $start = $criteriaElement->getStart();
290
        }
291
292
        $result = $this->db->query($sql, $limit, $start);
293
294
        if (!$result) {
295
            return $ret;
296
        }
297
298
        while (false !== ($myrow = $this->db->fetchArray($result))) {
299
            $suico_groups = new Groups();
300
301
            $suico_groups->assignVars($myrow);
302
303
            if (!$id_as_key) {
304
                $ret[] = &$suico_groups;
305
            } else {
306
                $ret[$myrow['group_id']] = &$suico_groups;
307
            }
308
309
            unset($suico_groups);
310
        }
311
312
        return $ret;
313
    }
314
315
    /**
316
     * retrieve suico_groupss from the database
317
     *
318
     * @param \CriteriaElement|\CriteriaCompo|null $criteria  {@link \CriteriaElement} conditions to be met
319
     * @param bool                                 $id_as_key use the UID as key for the array?
320
     * @return array array of {@link Groups} objects
321
     */
322
323
    public function getGroups(
324
        $criteria = null,
325
        $id_as_key = false
0 ignored issues
show
Unused Code introduced by
The parameter $id_as_key is not used and could be removed. ( Ignorable by Annotation )

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

325
        /** @scrutinizer ignore-unused */ $id_as_key = false

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
326
    ) {
327
        $ret = [];
328
329
        $limit = $start = 0;
330
331
        $sql = 'SELECT * FROM ' . $this->db->prefix('suico_groups');
332
333
        if (isset($criteria) && $criteria instanceof CriteriaElement) {
334
            $sql .= ' ' . $criteria->renderWhere();
335
336
            if ('' !== $criteria->getSort()) {
337
                $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder();
338
            }
339
340
            $limit = $criteria->getLimit();
341
342
            $start = $criteria->getStart();
343
        }
344
345
        $result = $this->db->query($sql, $limit, $start);
346
347
        if (!$result) {
348
            return $ret;
349
        }
350
351
        $i = 0;
352
353
        while (false !== ($myrow = $this->db->fetchArray($result))) {
354
            $ret[$i]['id'] = $myrow['group_id'];
355
356
            $ret[$i]['title'] = $myrow['group_title'];
357
358
            $ret[$i]['img'] = $myrow['group_img'];
359
360
            $ret[$i]['desc'] = $myrow['group_desc'];
361
362
            $ret[$i]['uid'] = $myrow['owner_uid'];
363
364
            $groupid = $myrow['group_id'];
365
366
            $query = 'SELECT COUNT(rel_id) AS grouptotalmembers FROM ' . $GLOBALS['xoopsDB']->prefix('suico_relgroupuser') . ' WHERE rel_group_id=' . $groupid . '';
367
368
            $queryresult = $GLOBALS['xoopsDB']->query($query);
369
370
            $row = $GLOBALS['xoopsDB']->fetchArray($queryresult);
371
372
            $grouptotalmembers            = $row['grouptotalmembers'];
373
            $ret[$i]['grouptotalmembers'] = $grouptotalmembers . ' ' . \_MD_SUICO_GROUPMEMBERS;
374
            $i++;
375
        }
376
377
        return $ret;
378
    }
379
380
    /**
381
     * count suico_groupss matching a condition
382
     *
383
     * @param \CriteriaElement|\CriteriaCompo|null $criteriaElement {@link \CriteriaElement} to match
384
     * @return int count of suico_groupss
385
     */
386
387
    public function getCount(
388
        ?CriteriaElement $criteriaElement = null
389
    ) {
390
        $sql = 'SELECT COUNT(*) FROM ' . $this->db->prefix('suico_groups');
391
392
        if (isset($criteriaElement) && $criteriaElement instanceof CriteriaElement) {
393
            $sql .= ' ' . $criteriaElement->renderWhere();
394
        }
395
396
        $result = $this->db->query($sql);
397
398
        if (!$result) {
399
            return 0;
400
        }
401
402
        [$count] = $this->db->fetchRow($result);
403
404
        return $count;
405
    }
406
407
    /**
408
     * delete suico_groupss matching a set of conditions
409
     *
410
     * @param \CriteriaElement|\CriteriaCompo|null $criteriaElement {@link \CriteriaElement}
411
     * @param bool                                 $force
412
     * @param bool                                 $asObject
413
     * @return bool FALSE if deletion failed
414
     */
415
416
    public function deleteAll(
417
        ?CriteriaElement $criteriaElement = null,
418
        $force = true,
419
        $asObject = false
420
    ) {
421
        $sql = 'DELETE FROM ' . $this->db->prefix('suico_groups');
422
423
        if (isset($criteriaElement) && $criteriaElement instanceof CriteriaElement) {
424
            $sql .= ' ' . $criteriaElement->renderWhere();
425
        }
426
427
        if (!$result = $this->db->query($sql)) {
0 ignored issues
show
Unused Code introduced by
The assignment to $result is dead and can be removed.
Loading history...
428
            return false;
429
        }
430
431
        return true;
432
    }
433
434
    /**
435
     * @param $maxbytes
436
     * @param $xoopsTpl
437
     * @return bool
438
     */
439
440
    public function renderFormSubmit(
441
        $maxbytes,
442
        $xoopsTpl
0 ignored issues
show
Unused Code introduced by
The parameter $xoopsTpl is not used and could be removed. ( Ignorable by Annotation )

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

442
        /** @scrutinizer ignore-unused */ $xoopsTpl

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
443
    ) {
444
        $form = new XoopsThemeForm(\_MD_SUICO_SUBMIT_GROUP, 'form_group', 'submitGroup.php', 'post', true);
445
        $form->setExtra('enctype="multipart/form-data"');
446
447
        $field_url     = new XoopsFormFile(\_MD_SUICO_GROUP_IMAGE, 'group_img', $maxbytes);
448
        $field_title   = new XoopsFormText(\_MD_SUICO_GROUP_TITLE, 'group_title', 35, 55);
449
        $field_desc    = new XoopsFormText(\_MD_SUICO_GROUP_DESC, 'group_desc', 35, 55);
450
        $field_marker  = new XoopsFormHidden('marker', '1');
451
        $buttonSend    = new XoopsFormButton('', 'submit_button', \_MD_SUICO_UPLOADGROUP, 'submit');
452
        $field_warning = new XoopsFormLabel(\sprintf(\_MD_SUICO_YOU_CAN_UPLOAD, $maxbytes / 1024));
453
454
        $form->addElement($field_warning);
455
456
        $form->addElement($field_url, true);
457
458
        $form->addElement($field_title);
459
460
        $form->addElement($field_desc);
461
462
        $form->addElement($field_marker);
463
        $form->addElement($buttonSend);
464
        $form->display();
465
466
        return true;
467
    }
468
469
    /**
470
     * @param $group
471
     * @param $maxbytes
472
     * @return bool
473
     */
474
475
    public function renderFormEdit(
476
        $group,
477
        $maxbytes
478
    ) {
479
        $form = new XoopsThemeForm(\_MD_SUICO_EDIT_GROUP, 'form_editgroup', 'editgroup.php', 'post', true);
480
        $form->setExtra('enctype="multipart/form-data"');
481
482
        $field_groupid = new XoopsFormHidden('group_id', $group->getVar('group_id'));
483
        $field_url     = new XoopsFormFile(\_MD_SUICO_GROUP_IMAGE, 'img', $maxbytes);
484
        $field_url->setExtra('style="visibility:hidden;"');
485
        $field_title   = new XoopsFormText(\_MD_SUICO_GROUP_TITLE, 'title', 35, 55, $group->getVar('group_title'));
486
        $field_desc    = new XoopsFormTextArea(\_MD_SUICO_GROUP_DESC, 'desc', $group->getVar('group_desc'));
487
        $field_marker  = new XoopsFormHidden('marker', '1');
488
        $buttonSend    = new XoopsFormButton('', 'submit_button', \_MD_SUICO_UPLOADGROUP, 'submit');
489
        $field_warning = new XoopsFormLabel(\sprintf(\_MD_SUICO_YOU_CAN_UPLOAD, $maxbytes / 1024));
490
491
        $field_oldpicture = new XoopsFormLabel(
492
            \_MD_SUICO_GROUP_IMAGE, '<img src="' . \XOOPS_UPLOAD_URL . '/' . $group->getVar(
493
                                       'group_img'
494
                                   ) . '">'
495
        );
496
497
        $field_maintainimage = new XoopsFormLabel(
498
            \_MD_SUICO_MAINTAIN_OLD_IMAGE, "<input type='checkbox' value='1' id='flag_oldimg' name='flag_oldimg' onclick=\"groupImgSwitch(img)\"  checked>"
499
        );
500
501
        $form->addElement($field_oldpicture);
502
503
        $form->addElement($field_maintainimage);
504
505
        $form->addElement($field_warning);
506
507
        $form->addElement($field_url);
508
509
        $form->addElement($field_groupid);
510
511
        $form->addElement($field_title);
512
513
        $form->addElement($field_desc);
514
515
        $form->addElement($field_marker);
516
        $form->addElement($buttonSend);
517
        $form->display();
518
519
        echo "
520
        <!-- Start Form Validation JavaScript //-->
521
<script type='text/javascript'>
522
<!--//
523
function groupImgSwitch(img) {
524
525
var elestyle = xoopsGetElementById(img).style;
526
527
    if (elestyle.visibility == \"hidden\") {
528
        elestyle.visibility = \"visible\";
529
    } else {
530
        elestyle.visibility = \"hidden\";
531
    }
532
533
534
}
535
//--></script>
536
<!-- End Form Validation JavaScript //-->
537
        ";
538
539
        return true;
540
    }
541
542
    /**
543
     * @param string $group_title
544
     * @param string $group_desc
545
     * @param string $group_img
546
     * @param string $path_upload
547
     * @param int    $maxfilebytes
548
     * @param int    $maxfilewidth
549
     * @param int    $maxfileheight
550
     * @param int    $change_img
551
     * @param string $group
552
     * @return bool
553
     */
554
555
    public function receiveGroup(
556
        $group_title,
557
        $group_desc,
558
        $group_img,
0 ignored issues
show
Unused Code introduced by
The parameter $group_img is not used and could be removed. ( Ignorable by Annotation )

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

558
        /** @scrutinizer ignore-unused */ $group_img,

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
559
        $path_upload,
0 ignored issues
show
Unused Code introduced by
The parameter $path_upload is not used and could be removed. ( Ignorable by Annotation )

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

559
        /** @scrutinizer ignore-unused */ $path_upload,

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
560
        $maxfilebytes,
561
        $maxfilewidth,
562
        $maxfileheight,
563
        $change_img = 1,
564
        $group = ''
565
        //        $pictwidth,
566
        //        $pictheight,
567
        //        $thumbwidth,
568
        //        $thumbheight
569
    )
570
    {
571
        global $xoopsUser, $xoopsDB, $_POST, $_FILES;
572
573
        //search logged user id
574
575
        $uid = $xoopsUser->getVar('uid');
576
577
        if ('' === $group || Groups::class !== \get_class($group)) {
0 ignored issues
show
Bug introduced by
$group of type string is incompatible with the type object expected by parameter $object of get_class(). ( Ignorable by Annotation )

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

577
        if ('' === $group || Groups::class !== \get_class(/** @scrutinizer ignore-type */ $group)) {
Loading history...
578
            $group = $this->create();
579
        } else {
580
            $group->unsetNew();
581
        }
582
583
        $helper = Helper::getInstance();
584
585
        $pictwidth = $helper->getConfig('resized_width');
0 ignored issues
show
Unused Code introduced by
The assignment to $pictwidth is dead and can be removed.
Loading history...
586
        $pictheight = $helper->getConfig('resized_height');
0 ignored issues
show
Unused Code introduced by
The assignment to $pictheight is dead and can be removed.
Loading history...
587
        $thumbwidth = $helper->getConfig('thumb_width');
0 ignored issues
show
Unused Code introduced by
The assignment to $thumbwidth is dead and can be removed.
Loading history...
588
        $thumbheight = $helper->getConfig('thumb_height');
0 ignored issues
show
Unused Code introduced by
The assignment to $thumbheight is dead and can be removed.
Loading history...
589
590
        if (1 === $change_img) {
591
            // mimetypes and settings put this in admin part later
592
593
            $allowed_mimetypes = Helper::getInstance()->getConfig(
594
                'mimetypes'
595
            );
596
597
            $maxfilesize = $maxfilebytes;
598
599
            $uploadDir = \XOOPS_UPLOAD_PATH . '/suico/groups/';
600
601
            // create the object to upload
602
603
            $uploader = new XoopsMediaUploader(
604
                $uploadDir, $allowed_mimetypes, $maxfilesize, $maxfilewidth, $maxfileheight
605
            );
606
607
            // fetch the media
608
609
            if ($uploader->fetchMedia($_POST['xoops_upload_file'][0])) {
610
                //lets create a name for it
611
612
                $uploader->setPrefix('group_' . $uid . '_');
613
614
                //now let s upload the file
615
616
                if (!$uploader->upload()) {
617
                    // if there are errors lets return them
618
619
                    echo '<div style="color:#FF0000; background-color:#FFEAF4; border-color:#FF0000; border-width:thick; border-style:solid; text-align:center"><p>' . $uploader->getErrors() . '</p></div>';
620
621
                    return false;
622
                }
623
624
                // now let s create a new object picture and set its variables
625
626
                $savedFilename = $uploader->getSavedFileName();
627
                $group->setVar('group_img', $savedFilename);
628
                $imageMimetype = $uploader->getMediaType();
629
                $group->setVar('group_img', $savedFilename);
630
                $maxWidth_grouplogo = Helper::getInstance()->getConfig('groupslogo_width');
631
                $maxHeight_grouplogo = Helper::getInstance()->getConfig('groupslogo_height');
632
633
                $resizer = new Common\Resizer();
634
                $resizer->sourceFile = $uploadDir . $savedFilename;
635
                $resizer->endFile = $uploadDir . $savedFilename;
636
                $resizer->imageMimetype = $imageMimetype;
637
                $resizer->maxWidth = $maxWidth_grouplogo;
638
                $resizer->maxHeight = $maxHeight_grouplogo;
639
                $result = $resizer->resizeImage();
0 ignored issues
show
Unused Code introduced by
The assignment to $result is dead and can be removed.
Loading history...
640
641
                $maxWidth_grouplogo = Helper::getInstance()->getConfig('thumb_width');
642
                $maxHeight_grouplogo = Helper::getInstance()->getConfig('thumb_height');
643
                $resizer->endFile = $uploadDir . '/thumb_' . $savedFilename;
644
                $resizer->imageMimetype = $imageMimetype;
645
                $resizer->maxWidth = $maxWidth_grouplogo;
646
                $resizer->maxHeight = $maxHeight_grouplogo;
647
                $result = $resizer->resizeImage();
648
649
                $maxWidth_grouplogo = Helper::getInstance()->getConfig('resized_width');
650
                $maxHeight_grouplogo = Helper::getInstance()->getConfig('resized_height');
651
                $resizer->endFile = $uploadDir . '/resized_' . $savedFilename;
652
                $resizer->imageMimetype = $imageMimetype;
653
                $resizer->maxWidth = $maxWidth_grouplogo;
654
                $resizer->maxHeight = $maxHeight_grouplogo;
655
                $result = $resizer->resizeImage();
656
657
            } else {
658
                echo '<div style="color:#FF0000; background-color:#FFEAF4; border-color:#FF0000; border-width:thick; border-style:solid; text-align:center"><p>' . $uploader->getErrors() . '</p></div>';
659
660
                return false;
661
            }
662
        }
663
664
        $group->setVar('group_title', $group_title);
665
        $group->setVar('group_desc', $group_desc);
666
        $group->setVar('owner_uid', $uid);
667
        $this->insert($group);
0 ignored issues
show
Bug introduced by
It seems like $group can also be of type string; however, parameter $object of XoopsPersistableObjectHandler::insert() does only seem to accept XoopsObject, maybe add an additional type check? ( Ignorable by Annotation )

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

667
        $this->insert(/** @scrutinizer ignore-type */ $group);
Loading history...
668
669
        return true;
670
    }
671
}
672