EventmemberHandler::getNbMember()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace XoopsModules\Extcal;
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
 * @copyright    {@link https://xoops.org/ XOOPS Project}
17
 * @license      {@link https://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later}
18
 * @package      extcal
19
 * @since
20
 * @author       XOOPS Development Team,
21
 */
22
23
use XoopsModules\Extcal\{Helper
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, XoopsModules\Extcal\Helper. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
24
};
25
26
// // require_once __DIR__ . '/ExtcalPersistableObjectHandler.php';
27
28
/**
29
 * Class EventmemberHandler.
30
 */
31
class EventmemberHandler extends ExtcalPersistableObjectHandler
32
{
33
    /**
34
     * @param \XoopsDatabase|null $db
35
     */
36
    public function __construct(\XoopsDatabase $db = null)
37
    {
38
        if (null === $db) {
39
            $db = \XoopsDatabaseFactory::getDatabaseConnection();
40
        }
41
        parent::__construct($db, 'extcal_eventmember', Eventmember::class, ['event_id', 'uid']);
0 ignored issues
show
Bug introduced by
array('event_id', 'uid') of type array<integer,string> is incompatible with the type string expected by parameter $keyname of XoopsModules\Extcal\Extc...tHandler::__construct(). ( Ignorable by Annotation )

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

41
        parent::__construct($db, 'extcal_eventmember', Eventmember::class, /** @scrutinizer ignore-type */ ['event_id', 'uid']);
Loading history...
42
    }
43
44
    /**
45
     * @param $varArr
46
     */
47
    public function createEventmember($varArr)
48
    {
49
        $eventmember = $this->create();
50
        $eventmember->setVars($varArr);
51
        if ($this->insert($eventmember, true)) {
52
            $eventNotMemberHandler = Helper::getInstance()->getHandler(\_EXTCAL_CLN_NOT_MEMBER);
53
            $eventNotMemberHandler->deleteById([$varArr['event_id'], $varArr['uid']]);
0 ignored issues
show
Bug introduced by
The method deleteById() does not exist on XoopsObjectHandler. Did you maybe mean delete()? ( Ignorable by Annotation )

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

53
            $eventNotMemberHandler->/** @scrutinizer ignore-call */ 
54
                                    deleteById([$varArr['event_id'], $varArr['uid']]);

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...
54
        }
55
    }
56
57
    /**
58
     * @param $key
59
     *
60
     * @return bool
61
     */
62
    public function deleteEventmember($key)
63
    {
64
        return $this->deleteById($key, true);
65
    }
66
67
    /**
68
     * @param $eventId
69
     *
70
     * @return mixed
71
     */
72
    public function getMembers($eventId)
73
    {
74
        /** @var \XoopsMemberHandler $memberHandler */
75
        $memberHandler = \xoops_getHandler('member');
76
        $eventMember   = $this->getObjects(new \Criteria('event_id', $eventId));
77
        $count         = \count($eventMember);
78
        if ($count > 0) {
79
            $in = '(' . $eventMember[0]->getVar('uid');
80
            \array_shift($eventMember);
81
            foreach ($eventMember as $member) {
82
                $in .= ',' . $member->getVar('uid');
83
            }
84
            $in       .= ')';
85
            $criteria = new \Criteria('uid', $in, 'IN');
86
        } else {
87
            $criteria = new \Criteria('uid', '(0)', 'IN');
88
        }
89
90
        return $memberHandler->getUsers($criteria, true);
91
    }
92
93
    /**
94
     * @param $eventId
95
     *
96
     * @return int|array
97
     */
98
    public function getNbMember($eventId)
99
    {
100
        $criteria = new \Criteria('event_id', $eventId);
101
102
        return $this->getCount($criteria);
103
    }
104
}
105