Passed
Push — main ( 6ca2bb...bc39e3 )
by Thierry
05:43
created

Session::close()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 2
nop 1
dl 0
loc 11
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Ajax\Web\Meeting;
4
5
use App\Ajax\CallableClass;
6
use Siak\Tontine\Service\Meeting\SessionService;
7
8
use function Jaxon\jq;
9
use function trans;
10
11
/**
12
 * @before checkGuestAccess ["meeting", "sessions"]
13
 */
14
class Session extends CallableClass
15
{
16
    /**
17
     * @param SessionService $sessionService
18
     */
19
    public function __construct(protected SessionService $sessionService)
20
    {}
21
22
    /**
23
     * @before checkRoundSessions
24
     * @after hideMenuOnMobile
25
     */
26
    public function home()
27
    {
28
        $this->response->html('section-title', trans('tontine.menus.meeting'));
29
        $html = $this->renderView('pages.meeting.session.list.home');
30
        $this->response->html('content-home', $html);
0 ignored issues
show
Bug introduced by
It seems like $html can also be of type null; however, parameter $sData of Jaxon\Response\Response::html() 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

30
        $this->response->html('content-home', /** @scrutinizer ignore-type */ $html);
Loading history...
31
32
        $this->jq('#btn-sessions-refresh')->click($this->rq()->page());
33
34
        return $this->page();
35
    }
36
37
    public function page(int $pageNumber = 0)
38
    {
39
        $sessionCount = $this->sessionService->getSessionCount();
40
        [$pageNumber, $perPage] = $this->pageNumber($pageNumber, $sessionCount, 'session', 'page');
41
        $sessions = $this->sessionService->getSessions($pageNumber);
42
        $pagination = $this->rq()->page()->paginate($pageNumber, $perPage, $sessionCount);
43
44
        $html = $this->renderView('pages.meeting.session.list.page', [
45
            'sessions' => $sessions,
46
            'statuses' => $this->sessionService->getSessionStatuses(),
47
            'pagination' => $pagination
48
        ]);
49
        $this->response->html('content-page', $html);
0 ignored issues
show
Bug introduced by
It seems like $html can also be of type null; however, parameter $sData of Jaxon\Response\Response::html() 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

49
        $this->response->html('content-page', /** @scrutinizer ignore-type */ $html);
Loading history...
50
        $this->response->call('makeTableResponsive', 'content-page');
51
52
        $rqHome = $this->rq(Session\Home::class);
53
        $sessionId = jq()->parent()->attr('data-session-id')->toInt();
54
        $this->jq('.btn-session-resync')->click($this->rq()->resync($sessionId)
55
            ->confirm(trans('tontine.session.questions.resync')));
56
        $this->jq('.btn-session-open')->click($this->rq()->open($sessionId)
57
            ->confirm(trans('tontine.session.questions.open') . '<br/>' .
58
            trans('tontine.session.questions.warning')));
59
        $this->jq('.btn-session-close')->click($this->rq()->close($sessionId)
60
            ->confirm(trans('tontine.session.questions.close')));
61
62
        $this->jq('.btn-session-pools')->click($rqHome->pools($sessionId));
63
        $this->jq('.btn-session-savings')->click($rqHome->savings($sessionId));
64
        $this->jq('.btn-session-credits')->click($rqHome->credits($sessionId));
65
        $this->jq('.btn-session-cash')->click($rqHome->cash($sessionId));
66
        $this->jq('.btn-session-charges')->click($rqHome->charges($sessionId));
67
        $this->jq('.btn-session-reports')->click($rqHome->reports($sessionId));
68
69
        return $this->response;
70
    }
71
72
    public function open(int $sessionId)
73
    {
74
        if(!($session = $this->sessionService->getSession($sessionId)) || $session->opened)
75
        {
76
            $this->notify->error(trans('tontine.session.errors.opened'), trans('common.titles.error'));
77
            return $this->page();
78
        }
79
80
        $this->sessionService->openSession($session);
81
82
        return $this->page();
83
    }
84
85
    public function close(int $sessionId)
86
    {
87
        if(!($session = $this->sessionService->getSession($sessionId)) || !$session->opened)
88
        {
89
            $this->notify->error(trans('tontine.session.errors.not_opened'), trans('common.titles.error'));
90
            return $this->page();
91
        }
92
93
        $this->sessionService->closeSession($session);
94
95
        return $this->page();
96
    }
97
98
    public function resync(int $sessionId)
99
    {
100
        if(!($session = $this->sessionService->getSession($sessionId)) || !$session->opened)
101
        {
102
            $this->notify->error(trans('tontine.session.errors.not_opened'), trans('common.titles.error'));
103
            return $this->page();
104
        }
105
106
        $this->sessionService->resyncSession($session);
107
108
        $this->notify->success(trans('tontine.session.messages.resynced'), trans('common.titles.success'));
109
        return $this->page();
110
    }
111
}
112