GroupsHandler::delete()   A
last analyzed

Complexity

Conditions 4
Paths 5

Size

Total Lines 22
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 13
nc 5
nop 2
dl 0
loc 22
rs 9.8333
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace XoopsModules\Suico;
4
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
10
 This program is distributed in the hope that it will be useful,
11
 but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
*/
14
15
/**
16
 * @category        Module
17
 * @copyright       {@link https://xoops.org/ XOOPS Project}
18
 * @license         GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html)
19
 * @author          Marcello Brandão aka  Suico, Mamba, LioMJ  <https://xoops.org>
20
 */
21
22
use CriteriaElement;
23
use XoopsDatabase;
24
use XoopsFormButton;
25
use XoopsFormFile;
26
use XoopsFormHidden;
27
use XoopsFormLabel;
28
use XoopsFormText;
29
use XoopsFormTextArea;
30
use XoopsMediaUploader;
31
use XoopsObject;
32
use XoopsPersistableObjectHandler;
33
use XoopsThemeForm;
34
35
/**
36
 * suico_groupshandler class.
37
 * This class provides simple mechanism for Groups object
38
 */
39
class GroupsHandler extends XoopsPersistableObjectHandler
40
{
41
    public Helper $helper;
42
    public        $isAdmin;
43
44
    /**
45
     * Constructor
46
     * @param \XoopsDatabase|null             $xoopsDatabase
47
     * @param \XoopsModules\Suico\Helper|null $helper
48
     */
49
    public function __construct(
50
        ?XoopsDatabase $xoopsDatabase = null,
51
        $helper = null
52
    ) {
53
        /** @var \XoopsModules\Suico\Helper $this- >helper */
54
        if (null === $helper) {
55
            $this->helper = Helper::getInstance();
56
        } else {
57
            $this->helper = $helper;
58
        }
59
        $this->isAdmin = $this->helper->isUserAdmin();
60
        parent::__construct($xoopsDatabase, 'suico_groups', Groups::class, 'group_id', 'group_title');
61
    }
62
63
    /**
64
     * create a new Groups
65
     *
66
     * @param bool $isNew flag the new objects as "new"?
67
     * @return \XoopsObject Groups
68
     */
69
    public function create(
70
        $isNew = true
71
    ) {
72
        $obj = parent::create($isNew);
73
        if ($isNew) {
74
            $obj->setNew();
75
        } else {
76
            $obj->unsetNew();
77
        }
78
        $obj->helper = $this->helper;
79
80
        return $obj;
81
    }
82
83
    /**
84
     * retrieve a Groups
85
     *
86
     * @param int  $id of the Groups
87
     * @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...
88
     * @return false|\XoopsModules\Suico\Groups reference to the {@link Groups} object, FALSE if failed
89
     */
90
    public function get2(
91
        $id = null,
92
        $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

92
        /** @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...
93
    ) {
94
        $sql = 'SELECT * FROM ' . $this->db->prefix('suico_groups') . ' WHERE group_id=' . $id;
95
        if (!$result = $this->db->query($sql)) {
96
            return false;
97
        }
98
        $numrows = $this->db->getRowsNum($result);
99
        if (1 === $numrows) {
100
            $suico_groups = new Groups();
101
            $suico_groups->assignVars($this->db->fetchArray($result));
102
103
            return $suico_groups;
104
        }
105
106
        return false;
107
    }
108
109
    /**
110
     * insert a new Groups in the database
111
     *
112
     * @param \XoopsObject $object   reference to the {@link Groups}
113
     *                                    object
114
     * @param bool         $force
115
     * @return bool FALSE if failed, TRUE if already present and unchanged or successful
116
     */
117
    public function insert2(
118
        XoopsObject $object,
119
        $force = false
120
    ) {
121
        global $xoopsConfig;
122
        if (!$object instanceof Groups) {
123
            return false;
124
        }
125
        if (!$object->isDirty()) {
126
            return true;
127
        }
128
        if (!$object->cleanVars()) {
129
            return false;
130
        }
131
        foreach ($object->cleanVars as $k => $v) {
132
            ${$k} = $v;
133
        }
134
        //        $now = 'date_add(now(), interval ' . $xoopsConfig['server_TZ'] . ' hour)';
135
        if ($object->isNew()) {
136
            // ajout/modification d'un Groups
137
            $object = new Groups();
138
            $format      = 'INSERT INTO %s (group_id, owner_uid, group_title, group_desc, group_img)';
139
            $format      .= 'VALUES (%u, %u, %s, %s, %s)';
140
            $sql         = \sprintf(
141
                $format,
142
                $this->db->prefix('suico_groups'),
143
                $group_id,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $group_id seems to be never defined.
Loading history...
144
                $owner_uid,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $owner_uid seems to be never defined.
Loading history...
145
                $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...
146
                $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...
147
                $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...
148
            );
149
            $force       = true;
150
        } else {
151
            $format = 'UPDATE %s SET ';
152
            $format .= 'group_id=%u, owner_uid=%u, group_title=%s, group_desc=%s, group_img=%s';
153
            $format .= ' WHERE group_id = %u';
154
            $sql    = \sprintf(
155
                $format,
156
                $this->db->prefix('suico_groups'),
157
                $group_id,
158
                $owner_uid,
159
                $this->db->quoteString($group_title),
160
                $this->db->quoteString($group_desc),
161
                $this->db->quoteString($group_img),
162
                $group_id
163
            );
164
        }
165
        if ($force) {
166
            $result = $this->db->queryF($sql);
167
        } else {
168
            $result = $this->db->query($sql);
169
        }
170
        if (!$result) {
171
            return false;
172
        }
173
        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...
174
            $group_id = $this->db->getInsertId();
175
        }
176
        $object->assignVar('group_id', $group_id);
177
178
        return true;
179
    }
180
181
    /**
182
     * delete a Groups from the database
183
     *
184
     * @param \XoopsObject $object reference to the Groups to delete
185
     * @param bool         $force
186
     * @return bool FALSE if failed.
187
     */
188
    public function delete(
189
        XoopsObject $object,
190
        $force = false
191
    ) {
192
        if (!$object instanceof Groups) {
193
            return false;
194
        }
195
        $sql = \sprintf(
196
            'DELETE FROM %s WHERE group_id = %u',
197
            $this->db->prefix('suico_groups'),
198
            (int)$object->getVar('group_id')
199
        );
200
        if ($force) {
201
            $result = $this->db->queryF($sql);
202
        } else {
203
            $result = $this->db->query($sql);
204
        }
205
        if (!$result) {
206
            return false;
207
        }
208
209
        return true;
210
    }
211
212
    /**
213
     * retrieve suico_groupss from the database
214
     *
215
     * @param \CriteriaElement|\CriteriaCompo|null $criteria {@link \CriteriaElement} conditions to be met
216
     * @param bool                                 $id_as_key       use the UID as key for the array?
217
     * @param bool                                 $as_object
218
     * @return array array of {@link Groups} objects
219
     */
220
    public function &getObjects(
221
        ?CriteriaElement $criteria = null,
222
        $id_as_key = false,
223
        $as_object = true
224
    ) {
225
        $ret   = [];
226
        $start = 0;
227
        $limit = 0;
228
        $sql   = 'SELECT * FROM ' . $this->db->prefix('suico_groups');
229
        if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
230
            $sql .= ' ' . $criteria->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

230
            $sql .= ' ' . $criteria->/** @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...
231
            if ('' !== $criteria->getSort()) {
232
                $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder();
233
            }
234
            $limit = $criteria->getLimit();
235
            $start = $criteria->getStart();
236
        }
237
        $result = $this->db->query($sql, $limit, $start);
238
        if (!$result) {
239
            return $ret;
240
        }
241
        while (false !== ($myrow = $this->db->fetchArray($result))) {
242
            $suico_groups = new Groups();
243
            $suico_groups->assignVars($myrow);
244
            if ($id_as_key) {
245
                $ret[$myrow['group_id']] = &$suico_groups;
246
            } else {
247
                $ret[] = &$suico_groups;
248
            }
249
            unset($suico_groups);
250
        }
251
252
        return $ret;
253
    }
254
255
    /**
256
     * retrieve suico_groupss from the database
257
     *
258
     * @param \CriteriaElement|\CriteriaCompo|null $criteria  {@link \CriteriaElement} conditions to be met
259
     * @param bool                                 $id_as_key use the UID as key for the array?
260
     * @return array array of {@link Groups} objects
261
     */
262
    public function getGroups(
263
        $criteria = null,
264
        $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

264
        /** @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...
265
    ) {
266
        $ret   = [];
267
        $sort  = 'group_title';
268
        $order = 'ASC';
269
        $start = 0;
270
        $limit = 0;
271
        $sql   = 'SELECT * FROM ' . $this->db->prefix('suico_groups');
272
        if (($criteria instanceof \CriteriaCompo) || ($criteria instanceof \Criteria)) {
273
            $sql .= ' ' . $criteria->renderWhere();
274
            if ('' !== $sort) {
0 ignored issues
show
introduced by
The condition '' !== $sort is always true.
Loading history...
275
                $sql .= ' ORDER BY ' . $sort . ' ' . $order;
276
            }
277
            $limit = $criteria->getLimit();
278
            $start = $criteria->getStart();
279
        }
280
        $result = $this->db->query($sql, $limit, $start);
281
        if (!$result) {
282
            return $ret;
283
        }
284
        $i = 0;
285
        while (false !== ($myrow = $this->db->fetchArray($result))) {
286
            $ret[$i]['id']       = $myrow['group_id'];
287
            $ret[$i]['title']    = $myrow['group_title'];
288
            $ret[$i]['img']      = $myrow['group_img'];
289
            $ret[$i]['desc']     = $myrow['group_desc'];
290
            $ret[$i]['uid']      = $myrow['owner_uid'];
291
            $groupid             = $myrow['group_id'];
292
            $query               = 'SELECT COUNT(rel_id) AS grouptotalmembers FROM ' . $GLOBALS['xoopsDB']->prefix('suico_relgroupuser') . ' WHERE rel_group_id=' . $groupid . '';
293
            $queryresult         = $GLOBALS['xoopsDB']->query($query);
294
            $row                 = $GLOBALS['xoopsDB']->fetchArray($queryresult);
295
            $group_total_members = $row['grouptotalmembers'];
296
            if ($group_total_members > 0) {
297
                if (1 == $group_total_members) {
298
                    $ret[$i]['group_total_members'] = '' . \_MD_SUICO_ONEMEMBER . '&nbsp;';
299
                } else {
300
                    $ret[$i]['group_total_members'] = '' . $group_total_members . '&nbsp;' . \_MD_SUICO_GROUPMEMBERS . '&nbsp;';
301
                }
302
            } else {
303
                $ret[$i]['group_total_members'] = '' . \_MD_SUICO_NO_MEMBER . '&nbsp;';
304
            }
305
            $i++;
306
        }
307
308
        return $ret;
309
    }
310
311
    /**
312
     * count suico_groupss matching a condition
313
     *
314
     * @param \CriteriaElement|\CriteriaCompo|null $criteria {@link \CriteriaElement} to match
315
     * @return int count of suico_groupss
316
     */
317
    public function getCount(
318
        ?CriteriaElement $criteria = null
319
    ) {
320
        $sql = 'SELECT COUNT(*) FROM ' . $this->db->prefix('suico_groups');
321
        if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
322
            $sql .= ' ' . $criteria->renderWhere();
323
        }
324
        $result = $this->db->query($sql);
325
        if (!$result) {
326
            return 0;
327
        }
328
        [$count] = $this->db->fetchRow($result);
329
330
        return $count;
331
    }
332
333
    /**
334
     * delete suico_groupss matching a set of conditions
335
     *
336
     * @param \CriteriaElement|\CriteriaCompo|null $criteria {@link \CriteriaElement}
337
     * @param bool                                 $force
338
     * @param bool                                 $asObject
339
     * @return bool FALSE if deletion failed
340
     */
341
    public function deleteAll(
342
        ?CriteriaElement $criteria = null,
343
        $force = true,
344
        $asObject = false
345
    ) {
346
        $sql = 'DELETE FROM ' . $this->db->prefix('suico_groups');
347
        if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
348
            $sql .= ' ' . $criteria->renderWhere();
349
        }
350
        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...
351
            return false;
352
        }
353
354
        return true;
355
    }
356
357
    /**
358
     * @param $maxbytes
359
     * @param $xoopsTpl
360
     * @return bool
361
     */
362
    public function renderFormSubmit(
363
        $maxbytes,
364
        $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

364
        /** @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...
365
    ) {
366
        $form = new XoopsThemeForm(\_MD_SUICO_SUBMIT_GROUP, 'form_group', 'submitGroup.php', 'post', true);
367
        $form->setExtra('enctype="multipart/form-data"');
368
        $field_url     = new XoopsFormFile(\_MD_SUICO_GROUP_IMAGE, 'group_img', $maxbytes);
369
        $field_title   = new XoopsFormText(\_MD_SUICO_GROUP_TITLE, 'group_title', 35, 55);
370
        $field_desc    = new XoopsFormText(\_MD_SUICO_GROUP_DESC, 'group_desc', 35, 55);
371
        $field_marker  = new XoopsFormHidden('marker', '1');
372
        $buttonSend    = new XoopsFormButton('', 'submit_button', \_MD_SUICO_UPLOADGROUP, 'submit');
373
        $field_warning = new XoopsFormLabel(\sprintf(\_MD_SUICO_YOU_CAN_UPLOAD, $maxbytes / 1024));
374
        $form->addElement($field_warning);
375
        $form->addElement($field_url, true);
376
        $form->addElement($field_title);
377
        $form->addElement($field_desc);
378
        $form->addElement($field_marker);
379
        $form->addElement($buttonSend);
380
        $form->display();
381
382
        return true;
383
    }
384
385
    /**
386
     * @param $group
387
     * @param $maxbytes
388
     * @return bool
389
     */
390
    public function renderFormEdit(
391
        $group,
392
        $maxbytes
393
    ) {
394
        $form = new XoopsThemeForm(\_MD_SUICO_EDIT_GROUP, 'form_editgroup', 'editgroup.php', 'post', true);
395
        $form->setExtra('enctype="multipart/form-data"');
396
        $field_groupid = new XoopsFormHidden('group_id', $group->getVar('group_id'));
397
        $field_url     = new XoopsFormFile(\_MD_SUICO_GROUP_IMAGE, 'img', $maxbytes);
398
        $field_url->setExtra('style="visibility:hidden;"');
399
        $field_title         = new XoopsFormText(\_MD_SUICO_GROUP_TITLE, 'title', 35, 55, $group->getVar('group_title'));
400
        $field_desc          = new XoopsFormTextArea(\_MD_SUICO_GROUP_DESC, 'desc', $group->getVar('group_desc'));
401
        $field_marker        = new XoopsFormHidden('marker', '1');
402
        $buttonSend          = new XoopsFormButton('', 'submit_button', \_MD_SUICO_UPLOADGROUP, 'submit');
403
        $field_warning       = new XoopsFormLabel(\sprintf(\_MD_SUICO_YOU_CAN_UPLOAD, $maxbytes / 1024));
404
        $field_oldpicture    = new XoopsFormLabel(
405
            \_MD_SUICO_GROUP_IMAGE,
406
            '<img src="' . \XOOPS_UPLOAD_URL . '/' . $group->getVar(
407
                'group_img'
408
            ) . '">'
409
        );
410
        $field_maintainimage = new XoopsFormLabel(
411
            \_MD_SUICO_MAINTAIN_OLD_IMAGE,
412
            "<input type='checkbox' value='1' id='flag_oldimg' name='flag_oldimg' onclick=\"groupImgSwitch(img)\"  checked>"
413
        );
414
        $form->addElement($field_oldpicture);
415
        $form->addElement($field_maintainimage);
416
        $form->addElement($field_warning);
417
        $form->addElement($field_url);
418
        $form->addElement($field_groupid);
419
        $form->addElement($field_title);
420
        $form->addElement($field_desc);
421
        $form->addElement($field_marker);
422
        $form->addElement($buttonSend);
423
        $form->display();
424
        echo "
425
        <!-- Start Form Validation JavaScript //-->
426
<script type='text/javascript'>
427
<!--//
428
function groupImgSwitch(img) {
429
430
var elestyle = xoopsGetElementById(img).style;
431
432
    if (elestyle.visibility == \"hidden\") {
433
        elestyle.visibility = \"visible\";
434
    } else {
435
        elestyle.visibility = \"hidden\";
436
    }
437
438
439
}
440
//--></script>
441
<!-- End Form Validation JavaScript //-->
442
        ";
443
444
        return true;
445
    }
446
447
    /**
448
     * @param string       $group_title
449
     * @param string       $group_desc
450
     * @param string       $group_img
451
     * @param string       $path_upload
452
     * @param int          $maxfilebytes
453
     * @param int          $maxfilewidth
454
     * @param int          $maxfileheight
455
     * @param int          $change_img
456
     * @param string|Group $group
457
     * @return bool
458
     */
459
    public function receiveGroup(
460
        $group_title,
461
        $group_desc,
462
        $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

462
        /** @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...
463
        $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

463
        /** @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...
464
        $maxfilebytes,
465
        $maxfilewidth,
466
        $maxfileheight,
467
        $change_img = 1,
468
        $group = ''
469
        //        $pictwidth,
470
        //        $pictheight,
471
        //        $thumbwidth,
472
        //        $thumbheight
473
    )
474
    {
475
        global $xoopsUser, $xoopsDB, $_POST, $_FILES;
476
        /** @var Groups $group */
477
        //search logged user id
478
        $uid = $xoopsUser->getVar('uid');
479
        if ('' === $group || Groups::class !== \get_class($group)) {
480
            $group = $this->create();
481
        } else {
482
            $group->unsetNew();
483
        }
484
        $helper      = Helper::getInstance();
485
        $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...
486
        $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...
487
        $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...
488
        $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...
489
        if (1 === $change_img) {
490
            // mimetypes and settings put this in admin part later
491
            $allowed_mimetypes = Helper::getInstance()->getConfig(
492
                'mimetypes'
493
            );
494
            $maxfilesize       = $maxfilebytes;
495
            $uploadDir         = \XOOPS_UPLOAD_PATH . '/suico/groups/';
496
            // create the object to upload
497
            $uploader = new XoopsMediaUploader(
498
                $uploadDir,
499
                $allowed_mimetypes,
500
                $maxfilesize,
501
                $maxfilewidth,
502
                $maxfileheight
503
            );
504
            // fetch the media
505
            if ($uploader->fetchMedia($_POST['xoops_upload_file'][0])) {
506
                //lets create a name for it
507
                $uploader->setPrefix('group_' . $uid . '_');
508
                //now let s upload the file
509
                if (!$uploader->upload()) {
510
                    // if there are errors lets return them
511
                    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>';
512
513
                    return false;
514
                }
515
                // now let s create a new object picture and set its variables
516
                $savedFilename = $uploader->getSavedFileName();
517
                $group->setVar('group_img', $savedFilename);
518
                $imageMimetype = $uploader->getMediaType();
519
                $group->setVar('group_img', $savedFilename);
520
                $maxWidth_grouplogo     = Helper::getInstance()->getConfig('groupslogo_width');
521
                $maxHeight_grouplogo    = Helper::getInstance()->getConfig('groupslogo_height');
522
                $resizer                = new Common\Resizer();
523
                $resizer->sourceFile    = $uploadDir . $savedFilename;
524
                $resizer->endFile       = $uploadDir . $savedFilename;
525
                $resizer->imageMimetype = $imageMimetype;
526
                $resizer->maxWidth      = $maxWidth_grouplogo;
527
                $resizer->maxHeight     = $maxHeight_grouplogo;
528
                $result                 = $resizer->resizeImage();
0 ignored issues
show
Unused Code introduced by
The assignment to $result is dead and can be removed.
Loading history...
529
                $maxWidth_grouplogo     = Helper::getInstance()->getConfig('thumb_width');
530
                $maxHeight_grouplogo    = Helper::getInstance()->getConfig('thumb_height');
531
                $resizer->endFile       = $uploadDir . '/thumb_' . $savedFilename;
532
                $resizer->imageMimetype = $imageMimetype;
533
                $resizer->maxWidth      = $maxWidth_grouplogo;
534
                $resizer->maxHeight     = $maxHeight_grouplogo;
535
                $result                 = $resizer->resizeImage();
536
                $maxWidth_grouplogo     = Helper::getInstance()->getConfig('resized_width');
537
                $maxHeight_grouplogo    = Helper::getInstance()->getConfig('resized_height');
538
                $resizer->endFile       = $uploadDir . '/resized_' . $savedFilename;
539
                $resizer->imageMimetype = $imageMimetype;
540
                $resizer->maxWidth      = $maxWidth_grouplogo;
541
                $resizer->maxHeight     = $maxHeight_grouplogo;
542
                $result                 = $resizer->resizeImage();
543
            } else {
544
                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>';
545
546
                return false;
547
            }
548
        }
549
        $group->setVar('group_title', $group_title);
550
        $group->setVar('group_desc', $group_desc);
551
        $group->setVar('owner_uid', $uid);
552
        $this->insert($group);
553
554
        return true;
555
    }
556
557
    /**
558
     * @param $owner_id
559
     * @return mixed
560
     */
561
    public function isGroupMember($owner_id)
0 ignored issues
show
Unused Code introduced by
The parameter $owner_id 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

561
    public function isGroupMember(/** @scrutinizer ignore-unused */ $owner_id)

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...
562
    {
563
        $query               = 'SELECT COUNT(rel_id) AS grouptotalmembers FROM ' . $GLOBALS['xoopsDB']->prefix('suico_relgroupuser') . ' WHERE rel_group_id=' . $group_id . '';
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $group_id seems to be never defined.
Loading history...
564
        $queryresult         = $GLOBALS['xoopsDB']->query($query);
565
        $row                 = $GLOBALS['xoopsDB']->fetchArray($queryresult);
566
        $group_total_members = $row['grouptotalmembers'];
567
568
        return $group_total_members;
569
    }
570
571
    /**
572
     * @param $group_id
573
     * @return mixed
574
     */
575
    public function getComment($group_id)
576
    {
577
        $moduleSuico = Helper::getInstance()->getModule();
578
        $sql         = 'SELECT count(com_id) FROM ' . $GLOBALS['xoopsDB']->prefix('xoopscomments') . " WHERE com_modid = '" . $moduleSuico->getVar('mid') . "' AND com_itemid = '" . $group_id . "'";
579
        $result      = $GLOBALS['xoopsDB']->query($sql);
580
        while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
581
            $group_total_comments = $row['count(com_id)'];
582
        }
583
584
        return $group_total_comments;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $group_total_comments does not seem to be defined for all execution paths leading up to this point.
Loading history...
585
    }
586
587
    /**
588
     * @param $group_id
589
     * @return mixed
590
     */
591
    public function getGroupTotalMembers($group_id)
592
    {
593
        $query               = 'SELECT COUNT(rel_id) AS grouptotalmembers FROM ' . $GLOBALS['xoopsDB']->prefix('suico_relgroupuser') . ' WHERE rel_group_id=' . $group_id . '';
594
        $queryresult         = $GLOBALS['xoopsDB']->query($query);
595
        $row                 = $GLOBALS['xoopsDB']->fetchArray($queryresult);
596
        $group_total_members = $row['grouptotalmembers'];
597
598
        return $group_total_members;
599
    }
600
}
601