Passed
Push — main ( 7be313...891842 )
by Thierry
19:01 queued 53s
created

Session::home()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 9
rs 10
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
class Session extends CallableClass
12
{
13
    /**
14
     * @param SessionService $sessionService
15
     */
16
    public function __construct(protected SessionService $sessionService)
17
    {}
18
19
    /**
20
     * @before checkRoundSessions
21
     * @after hideMenuOnMobile
22
     */
23
    public function home()
24
    {
25
        $this->response->html('section-title', trans('tontine.menus.meeting'));
26
        $html = $this->render('pages.meeting.session.list.home');
27
        $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

27
        $this->response->html('content-home', /** @scrutinizer ignore-type */ $html);
Loading history...
28
29
        $this->jq('#btn-sessions-refresh')->click($this->rq()->page());
30
31
        return $this->page();
32
    }
33
34
    public function page(int $pageNumber = 0)
35
    {
36
        $sessionCount = $this->sessionService->getSessionCount();
37
        [$pageNumber, $perPage] = $this->pageNumber($pageNumber, $sessionCount, 'session', 'page');
38
        $sessions = $this->sessionService->getSessions($pageNumber);
39
        $pagination = $this->rq()->page()->paginate($pageNumber, $perPage, $sessionCount);
40
41
        $html = $this->render('pages.meeting.session.list.page', [
42
            'sessions' => $sessions,
43
            'statuses' => $this->sessionService->getSessionStatuses(),
44
            'pagination' => $pagination
45
        ]);
46
        $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

46
        $this->response->html('content-page', /** @scrutinizer ignore-type */ $html);
Loading history...
47
48
        $sessionId = jq()->parent()->attr('data-session-id')->toInt();
49
        $this->jq('.btn-session-show')->click($this->rq(Session\Home::class)->home($sessionId));
50
        $this->jq('.btn-session-resync')->click($this->rq()->resync($sessionId)
51
            ->confirm(trans('tontine.session.questions.resync')));
52
53
        return $this->response;
54
    }
55
56
    public function resync(int $sessionId)
57
    {
58
        if(!($session = $this->sessionService->getSession($sessionId)) || !$session->opened)
59
        {
60
            $this->notify->error(trans('tontine.session.errors.not_opened'), trans('common.titles.error'));
61
            return $this->page();
62
        }
63
64
        $this->sessionService->resyncSession($session);
65
66
        $this->notify->success(trans('tontine.session.messages.resynced'), trans('common.titles.success'));
67
        return $this->page();
68
    }
69
}
70