Passed
Push — master ( 06e1aa...b7b18e )
by
unknown
03:40 queued 51s
created

GroupsHandler::getComment()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 11
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
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
 * suico_groupshandler class.
47
 * This class provides simple mechanism for Groups object
48
 */
49
class GroupsHandler extends XoopsPersistableObjectHandler
50
{
51
    public $helper;
52
    public $isAdmin;
53
54
    /**
55
     * Constructor
56
     * @param \XoopsDatabase|null             $xoopsDatabase
57
     * @param \XoopsModules\Suico\Helper|null $helper
58
     */
59
    public function __construct(
60
        ?XoopsDatabase $xoopsDatabase = null,
61
        $helper = null
62
    ) {
63
        /** @var \XoopsModules\Suico\Helper $this ->helper */
64
        if (null === $helper) {
65
            $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...
66
        } else {
67
            $this->helper = $helper;
68
        }
69
        $isAdmin = $this->helper->isUserAdmin();
0 ignored issues
show
Unused Code introduced by
The assignment to $isAdmin is dead and can be removed.
Loading history...
70
        parent::__construct($xoopsDatabase, 'suico_groups', Groups::class, 'group_id', 'group_title');
71
    }
72
73
    /**
74
     * create a new Groups
75
     *
76
     * @param bool $isNew flag the new objects as "new"?
77
     * @return \XoopsObject Groups
78
     */
79
    public function create(
80
        $isNew = true
81
    ) {
82
        $obj = parent::create($isNew);
83
        if ($isNew) {
84
            $obj->setNew();
85
        } else {
86
            $obj->unsetNew();
87
        }
88
        $obj->helper = $this->helper;
89
        return $obj;
90
    }
91
92
    /**
93
     * retrieve a Groups
94
     *
95
     * @param int  $id of the Groups
96
     * @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...
97
     * @return mixed reference to the {@link Groups} object, FALSE if failed
98
     */
99
    public function get2(
100
        $id = null,
101
        $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

101
        /** @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...
102
    ) {
103
        $sql = 'SELECT * FROM ' . $this->db->prefix('suico_groups') . ' WHERE group_id=' . $id;
104
        if (!$result = $this->db->query($sql)) {
105
            return false;
106
        }
107
        $numrows = $this->db->getRowsNum($result);
108
        if (1 === $numrows) {
109
            $suico_groups = new Groups();
110
            $suico_groups->assignVars($this->db->fetchArray($result));
111
            return $suico_groups;
112
        }
113
        return false;
114
    }
115
116
    /**
117
     * insert a new Groups in the database
118
     *
119
     * @param \XoopsObject $xoopsObject   reference to the {@link Groups}
120
     *                                    object
121
     * @param bool         $force
122
     * @return bool FALSE if failed, TRUE if already present and unchanged or successful
123
     */
124
    public function insert2(
125
        XoopsObject $xoopsObject,
126
        $force = false
127
    ) {
128
        global $xoopsConfig;
129
        if (!$xoopsObject instanceof Groups) {
130
            return false;
131
        }
132
        if (!$xoopsObject->isDirty()) {
133
            return true;
134
        }
135
        if (!$xoopsObject->cleanVars()) {
136
            return false;
137
        }
138
        foreach ($xoopsObject->cleanVars as $k => $v) {
139
            ${$k} = $v;
140
        }
141
        //        $now = 'date_add(now(), interval ' . $xoopsConfig['server_TZ'] . ' hour)';
142
        if ($xoopsObject->isNew()) {
143
            // ajout/modification d'un Groups
144
            $xoopsObject = new Groups();
145
            $format      = 'INSERT INTO %s (group_id, owner_uid, group_title, group_desc, group_img)';
146
            $format      .= 'VALUES (%u, %u, %s, %s, %s)';
147
            $sql         = \sprintf(
148
                $format,
149
                $this->db->prefix('suico_groups'),
150
                $group_id,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $group_id seems to be never defined.
Loading history...
151
                $owner_uid,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $owner_uid seems to be never defined.
Loading history...
152
                $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...
153
                $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...
154
                $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...
155
            );
156
            $force       = true;
157
        } else {
158
            $format = 'UPDATE %s SET ';
159
            $format .= 'group_id=%u, owner_uid=%u, group_title=%s, group_desc=%s, group_img=%s';
160
            $format .= ' WHERE group_id = %u';
161
            $sql    = \sprintf(
162
                $format,
163
                $this->db->prefix('suico_groups'),
164
                $group_id,
165
                $owner_uid,
166
                $this->db->quoteString($group_title),
167
                $this->db->quoteString($group_desc),
168
                $this->db->quoteString($group_img),
169
                $group_id
170
            );
171
        }
172
        if ($force) {
173
            $result = $this->db->queryF($sql);
174
        } else {
175
            $result = $this->db->query($sql);
176
        }
177
        if (!$result) {
178
            return false;
179
        }
180
        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...
181
            $group_id = $this->db->getInsertId();
182
        }
183
        $xoopsObject->assignVar('group_id', $group_id);
184
        return true;
185
    }
186
187
    /**
188
     * delete a Groups from the database
189
     *
190
     * @param \XoopsObject $xoopsObject reference to the Groups to delete
191
     * @param bool         $force
192
     * @return bool FALSE if failed.
193
     */
194
    public function delete(
195
        XoopsObject $xoopsObject,
196
        $force = false
197
    ) {
198
        if (!$xoopsObject instanceof Groups) {
199
            return false;
200
        }
201
        $sql = \sprintf(
202
            'DELETE FROM %s WHERE group_id = %u',
203
            $this->db->prefix('suico_groups'),
204
            $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

204
            /** @scrutinizer ignore-type */ $xoopsObject->getVar('group_id')
Loading history...
205
        );
206
        if ($force) {
207
            $result = $this->db->queryF($sql);
208
        } else {
209
            $result = $this->db->query($sql);
210
        }
211
        if (!$result) {
212
            return false;
213
        }
214
        return true;
215
    }
216
217
    /**
218
     * retrieve suico_groupss from the database
219
     *
220
     * @param \CriteriaElement|\CriteriaCompo|null $criteriaElement {@link \CriteriaElement} conditions to be met
221
     * @param bool                                 $id_as_key       use the UID as key for the array?
222
     * @param bool                                 $as_object
223
     * @return array array of {@link Groups} objects
224
     */
225
    public function &getObjects(
226
        ?CriteriaElement $criteriaElement = null,
227
        $id_as_key = false,
228
        $as_object = true
229
    ) {
230
        $ret   = [];
231
        $limit = $start = 0;
232
        $sql   = 'SELECT * FROM ' . $this->db->prefix('suico_groups');
233
        if (isset($criteriaElement) && $criteriaElement instanceof CriteriaElement) {
234
            $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

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

267
        /** @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...
268
    ) {
269
        $ret   = [];
270
		$sort = 'group_title';
271
        $order = 'ASC';
272
        $limit = $start = 0;
273
        $sql   = 'SELECT * FROM ' . $this->db->prefix('suico_groups');
274
        if (isset($criteria) && $criteria instanceof CriteriaElement) {
275
            $sql .= ' ' . $criteria->renderWhere();
276
            if ('' !== $sort) {
0 ignored issues
show
introduced by
The condition '' !== $sort is always true.
Loading history...
277
                $sql .= ' ORDER BY ' . $sort . ' ' . $order;
278
            }
279
            $limit = $criteria->getLimit();
280
            $start = $criteria->getStart();
281
        }
282
        $result = $this->db->query($sql, $limit, $start);
283
        if (!$result) {
284
            return $ret;
285
        }
286
        $i = 0;
287
        while (false !== ($myrow = $this->db->fetchArray($result))) {
288
            $ret[$i]['id']                = $myrow['group_id'];
289
            $ret[$i]['title']             = $myrow['group_title'];
290
            $ret[$i]['img']               = $myrow['group_img'];
291
            $ret[$i]['desc']              = $myrow['group_desc'];
292
            $ret[$i]['uid']               = $myrow['owner_uid'];
293
            $groupid                      = $myrow['group_id'];
294
            $query                        = 'SELECT COUNT(rel_id) AS grouptotalmembers FROM ' . $GLOBALS['xoopsDB']->prefix('suico_relgroupuser') . ' WHERE rel_group_id=' . $groupid . '';
295
            $queryresult                  = $GLOBALS['xoopsDB']->query($query);
296
            $row                          = $GLOBALS['xoopsDB']->fetchArray($queryresult);
297
            $group_total_members          = $row['grouptotalmembers'];
298
			
299
			if ($group_total_members > 0) {
300
                if (1 == $group_total_members) {
301
                    $ret[$i]['group_total_members'] ='' . _MD_SUICO_ONEMEMBER . '&nbsp;';
302
                } else {
303
                    $ret[$i]['group_total_members'] ='' . $group_total_members . '&nbsp;' . _MD_SUICO_GROUPMEMBERS . '&nbsp;';
304
                }
305
            } else {
306
                $ret[$i]['group_total_members'] ='' . _MD_SUICO_NO_MEMBER . '&nbsp;';
307
            }
308
            $i++;
309
        }
310
        return $ret;
311
    }
312
313
    /**
314
     * count suico_groupss matching a condition
315
     *
316
     * @param \CriteriaElement|\CriteriaCompo|null $criteriaElement {@link \CriteriaElement} to match
317
     * @return int count of suico_groupss
318
     */
319
    public function getCount(
320
        ?CriteriaElement $criteriaElement = null
321
    ) {
322
        $sql = 'SELECT COUNT(*) FROM ' . $this->db->prefix('suico_groups');
323
        if (isset($criteriaElement) && $criteriaElement instanceof CriteriaElement) {
324
            $sql .= ' ' . $criteriaElement->renderWhere();
325
        }
326
        $result = $this->db->query($sql);
327
        if (!$result) {
328
            return 0;
329
        }
330
        [$count] = $this->db->fetchRow($result);
331
        return $count;
332
    }
333
334
    /**
335
     * delete suico_groupss matching a set of conditions
336
     *
337
     * @param \CriteriaElement|\CriteriaCompo|null $criteriaElement {@link \CriteriaElement}
338
     * @param bool                                 $force
339
     * @param bool                                 $asObject
340
     * @return bool FALSE if deletion failed
341
     */
342
    public function deleteAll(
343
        ?CriteriaElement $criteriaElement = null,
344
        $force = true,
345
        $asObject = false
346
    ) {
347
        $sql = 'DELETE FROM ' . $this->db->prefix('suico_groups');
348
        if (isset($criteriaElement) && $criteriaElement instanceof CriteriaElement) {
349
            $sql .= ' ' . $criteriaElement->renderWhere();
350
        }
351
        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...
352
            return false;
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
        return true;
382
    }
383
384
    /**
385
     * @param $group
386
     * @param $maxbytes
387
     * @return bool
388
     */
389
    public function renderFormEdit(
390
        $group,
391
        $maxbytes
392
    ) {
393
        $form = new XoopsThemeForm(\_MD_SUICO_EDIT_GROUP, 'form_editgroup', 'editgroup.php', 'post', true);
394
        $form->setExtra('enctype="multipart/form-data"');
395
        $field_groupid = new XoopsFormHidden('group_id', $group->getVar('group_id'));
396
        $field_url     = new XoopsFormFile(\_MD_SUICO_GROUP_IMAGE, 'img', $maxbytes);
397
        $field_url->setExtra('style="visibility:hidden;"');
398
        $field_title         = new XoopsFormText(\_MD_SUICO_GROUP_TITLE, 'title', 35, 55, $group->getVar('group_title'));
399
        $field_desc          = new XoopsFormTextArea(\_MD_SUICO_GROUP_DESC, 'desc', $group->getVar('group_desc'));
400
        $field_marker        = new XoopsFormHidden('marker', '1');
401
        $buttonSend          = new XoopsFormButton('', 'submit_button', \_MD_SUICO_UPLOADGROUP, 'submit');
402
        $field_warning       = new XoopsFormLabel(\sprintf(\_MD_SUICO_YOU_CAN_UPLOAD, $maxbytes / 1024));
403
        $field_oldpicture    = new XoopsFormLabel(
404
            \_MD_SUICO_GROUP_IMAGE, '<img src="' . \XOOPS_UPLOAD_URL . '/' . $group->getVar(
405
                                      'group_img'
406
                                  ) . '">'
407
        );
408
        $field_maintainimage = new XoopsFormLabel(
409
            \_MD_SUICO_MAINTAIN_OLD_IMAGE, "<input type='checkbox' value='1' id='flag_oldimg' name='flag_oldimg' onclick=\"groupImgSwitch(img)\"  checked>"
410
        );
411
        $form->addElement($field_oldpicture);
412
        $form->addElement($field_maintainimage);
413
        $form->addElement($field_warning);
414
        $form->addElement($field_url);
415
        $form->addElement($field_groupid);
416
        $form->addElement($field_title);
417
        $form->addElement($field_desc);
418
        $form->addElement($field_marker);
419
        $form->addElement($buttonSend);
420
        $form->display();
421
        echo "
422
        <!-- Start Form Validation JavaScript //-->
423
<script type='text/javascript'>
424
<!--//
425
function groupImgSwitch(img) {
426
427
var elestyle = xoopsGetElementById(img).style;
428
429
    if (elestyle.visibility == \"hidden\") {
430
        elestyle.visibility = \"visible\";
431
    } else {
432
        elestyle.visibility = \"hidden\";
433
    }
434
435
436
}
437
//--></script>
438
<!-- End Form Validation JavaScript //-->
439
        ";
440
        return true;
441
    }
442
443
    /**
444
     * @param string $group_title
445
     * @param string $group_desc
446
     * @param string $group_img
447
     * @param string $path_upload
448
     * @param int    $maxfilebytes
449
     * @param int    $maxfilewidth
450
     * @param int    $maxfileheight
451
     * @param int    $change_img
452
     * @param string $group
453
     * @return bool
454
     */
455
    public function receiveGroup(
456
        $group_title,
457
        $group_desc,
458
        $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

458
        /** @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...
459
        $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

459
        /** @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...
460
        $maxfilebytes,
461
        $maxfilewidth,
462
        $maxfileheight,
463
        $change_img = 1,
464
        $group = ''
465
        //        $pictwidth,
466
        //        $pictheight,
467
        //        $thumbwidth,
468
        //        $thumbheight
469
    )
470
    {
471
        global $xoopsUser, $xoopsDB, $_POST, $_FILES;
472
        //search logged user id
473
        $uid = $xoopsUser->getVar('uid');
474
        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

474
        if ('' === $group || Groups::class !== \get_class(/** @scrutinizer ignore-type */ $group)) {
Loading history...
475
            $group = $this->create();
476
        } else {
477
            $group->unsetNew();
478
        }
479
        $helper      = Helper::getInstance();
480
        $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...
481
        $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...
482
        $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...
483
        $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...
484
        if (1 === $change_img) {
485
            // mimetypes and settings put this in admin part later
486
            $allowed_mimetypes = Helper::getInstance()->getConfig(
487
                'mimetypes'
488
            );
489
            $maxfilesize       = $maxfilebytes;
490
            $uploadDir         = \XOOPS_UPLOAD_PATH . '/suico/groups/';
491
            // create the object to upload
492
            $uploader = new XoopsMediaUploader(
493
                $uploadDir, $allowed_mimetypes, $maxfilesize, $maxfilewidth, $maxfileheight
494
            );
495
            // fetch the media
496
            if ($uploader->fetchMedia($_POST['xoops_upload_file'][0])) {
497
                //lets create a name for it
498
                $uploader->setPrefix('group_' . $uid . '_');
499
                //now let s upload the file
500
                if (!$uploader->upload()) {
501
                    // if there are errors lets return them
502
                    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>';
503
                    return false;
504
                }
505
                // now let s create a new object picture and set its variables
506
                $savedFilename = $uploader->getSavedFileName();
507
                $group->setVar('group_img', $savedFilename);
508
                $imageMimetype = $uploader->getMediaType();
509
                $group->setVar('group_img', $savedFilename);
510
                $maxWidth_grouplogo     = Helper::getInstance()->getConfig('groupslogo_width');
511
                $maxHeight_grouplogo    = Helper::getInstance()->getConfig('groupslogo_height');
512
                $resizer                = new Common\Resizer();
513
                $resizer->sourceFile    = $uploadDir . $savedFilename;
514
                $resizer->endFile       = $uploadDir . $savedFilename;
515
                $resizer->imageMimetype = $imageMimetype;
516
                $resizer->maxWidth      = $maxWidth_grouplogo;
517
                $resizer->maxHeight     = $maxHeight_grouplogo;
518
                $result                 = $resizer->resizeImage();
0 ignored issues
show
Unused Code introduced by
The assignment to $result is dead and can be removed.
Loading history...
519
                $maxWidth_grouplogo     = Helper::getInstance()->getConfig('thumb_width');
520
                $maxHeight_grouplogo    = Helper::getInstance()->getConfig('thumb_height');
521
                $resizer->endFile       = $uploadDir . '/thumb_' . $savedFilename;
522
                $resizer->imageMimetype = $imageMimetype;
523
                $resizer->maxWidth      = $maxWidth_grouplogo;
524
                $resizer->maxHeight     = $maxHeight_grouplogo;
525
                $result                 = $resizer->resizeImage();
526
                $maxWidth_grouplogo     = Helper::getInstance()->getConfig('resized_width');
527
                $maxHeight_grouplogo    = Helper::getInstance()->getConfig('resized_height');
528
                $resizer->endFile       = $uploadDir . '/resized_' . $savedFilename;
529
                $resizer->imageMimetype = $imageMimetype;
530
                $resizer->maxWidth      = $maxWidth_grouplogo;
531
                $resizer->maxHeight     = $maxHeight_grouplogo;
532
                $result                 = $resizer->resizeImage();
533
            } else {
534
                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>';
535
                return false;
536
            }
537
        }
538
        $group->setVar('group_title', $group_title);
539
        $group->setVar('group_desc', $group_desc);
540
        $group->setVar('owner_uid', $uid);
541
        $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

541
        $this->insert(/** @scrutinizer ignore-type */ $group);
Loading history...
542
        return true;
543
    }	
544
	
545
	
546
	 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

546
	 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...
547
    {
548
        $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...
549
		$queryresult                  = $GLOBALS['xoopsDB']->query($query);
550
        $row                          = $GLOBALS['xoopsDB']->fetchArray($queryresult);
551
        $group_total_members          = $row['grouptotalmembers'];
552
553
        return $group_total_members;
554
    }
555
	
556
	
557
    public function getComment($group_id)
558
    {
559
        $module_handler = xoops_gethandler("module"); 
560
		$mod_suico = $module_handler->getByDirname('suico');
0 ignored issues
show
Bug introduced by
The method getByDirname() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsModuleHandler or XoopsPersistableObjectHandler. ( Ignorable by Annotation )

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

560
		/** @scrutinizer ignore-call */ 
561
  $mod_suico = $module_handler->getByDirname('suico');
Loading history...
561
		$sql= "SELECT count(com_id) FROM ".$GLOBALS['xoopsDB']->prefix('xoopscomments')." WHERE com_modid = '".$mod_suico->getVar('mid')."' AND com_itemid = '".$group_id."'";
562
		$result = $GLOBALS['xoopsDB']->query($sql);
563
		while ($row = $GLOBALS['xoopsDB']->fetchArray($result)) {
564
			$group_total_comments=$row['count(com_id)'];
565
		}
566
567
        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...
568
    }
569
	
570
	 public function getGroupTotalMembers($group_id)
571
    {
572
        $query                        = 'SELECT COUNT(rel_id) AS grouptotalmembers FROM ' . $GLOBALS['xoopsDB']->prefix('suico_relgroupuser') . ' WHERE rel_group_id=' . $group_id . '';
573
		$queryresult                  = $GLOBALS['xoopsDB']->query($query);
574
        $row                          = $GLOBALS['xoopsDB']->fetchArray($queryresult);
575
        $group_total_members          = $row['grouptotalmembers'];
576
577
        return $group_total_members;
578
    }
579
	
580
}
581