Completed
Branch master (55a138)
by Michael
03:21
created

EventNotMemberHandler::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 4
loc 4
rs 10
c 0
b 0
f 0
1
<?php namespace XoopsModules\Extcal;
2
/*
3
 * You may not change or alter any portion of this comment or credits
4
 * of supporting developers from this source code or any supporting source code
5
 * which is considered copyrighted (c) material of the original comment or credit authors.
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
 */
11
12
/**
13
 * @copyright    {@link https://xoops.org/ XOOPS Project}
14
 * @license      {@link http://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later}
15
 * @package      extcal
16
 * @since
17
 * @author       XOOPS Development Team,
18
 */
19
20
use XoopsModules\Extcal;
21
22
// defined('XOOPS_ROOT_PATH') || exit('Restricted access.');
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
23
24
// // require_once __DIR__ . '/ExtcalPersistableObjectHandler.php';
25
26
27
/**
28
 * Class EventNotMemberHandler.
29
 */
30 View Code Duplication
class EventNotMemberHandler extends ExtcalPersistableObjectHandler
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
31
{
32
    /**
33
     * @param $db
34
     */
35
    public function __construct(\XoopsDatabase $db)
36
    {
37
        parent::__construct($db, 'extcal_eventnotmember', EventNotMember::class, ['event_id', 'uid']);
38
    }
39
40
    /**
41
     * @param $varArr
42
     */
43
    public function createEventNotMember($varArr)
44
    {
45
        $eventnotmember = $this->create();
46
        $eventnotmember->setVars($varArr);
47
48
        if ($this->insert($eventnotmember, true)) {
49
            $eventMemberHandler = Extcal\Helper::getInstance()->getHandler(_EXTCAL_CLN_MEMBER);
50
            $eventMemberHandler->deleteById([$varArr['event_id'], $varArr['uid']]);
51
        }
52
    }
53
54
    /**
55
     * @param $id
56
     *
57
     * @return bool
58
     */
59
    public function deleteEventNotMember($id)
60
    {
61
        return $this->deleteById($id, true);
62
    }
63
64
    /**
65
     * @param $eventId
66
     *
67
     * @return mixed
68
     */
69
    public function getMembers($eventId)
70
    {
71
        $memberHandler  = xoops_getHandler('member');
72
        $eventNotMember = $this->getObjects( new \Criteria('event_id', $eventId));
73
        $count          = count($eventNotMember);
74
        if ($count > 0) {
75
            $in = '(' . $eventNotMember[0]->getVar('uid');
76
            array_shift($eventNotMember);
77
            foreach ($eventNotMember as $member) {
78
                $in .= ',' . $member->getVar('uid');
79
            }
80
            $in       .= ')';
81
            $criteria =  new \Criteria('uid', $in, 'IN');
82
        } else {
83
            $criteria =  new \Criteria('uid', '(0)', 'IN');
84
        }
85
86
        return $memberHandler->getUsers($criteria, true);
87
    }
88
89
    /**
90
     * @param $eventId
91
     *
92
     * @return int
0 ignored issues
show
Documentation introduced by
Should the return type not be integer|array?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
93
     */
94
    public function getNbMember($eventId)
95
    {
96
        $criteria =  new \Criteria('event_id', $eventId);
97
98
        return $this->getCount($criteria);
99
    }
100
}
101