ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilPollCommentsHandler.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22use ILIAS\Refinery\Factory as Refinery;
23use ILIAS\Notes\Service as NotesService;
24
26{
27 protected NotesService $notes;
29 protected Refinery $refinery;
30
31 protected string $redraw_url;
32
33 public function __construct(
34 NotesService $notes,
36 Refinery $refinery,
37 string $redraw_url
38 ) {
39 $this->notes = $notes;
40 $this->http = $http;
41 $this->refinery = $refinery;
42 $this->redraw_url = $redraw_url;
43 }
44
45 public function getRedrawURL(): string
46 {
47 return $this->redraw_url;
48 }
49
53 public function commentJSCall(int $ref_id): string
54 {
55 $obj_id = $this->lookupObjectId($ref_id);
56 $ajax_hash = $this->buildAjaxHashForPoll($ref_id, $obj_id);
57
58
59 return $this->getListCommentsJSCallForPoll($ajax_hash, $ref_id);
60 }
61
62 public function getNumberOfCommentsForRedraw(): void
63 {
64 $poll_id = 0;
65 if ($this->http->wrapper()->query()->has('poll_id')) {
66 $poll_id = $this->http->wrapper()->query()->retrieve(
67 'poll_id',
68 $this->refinery->kindlyTo()->int()
69 );
70 }
71
72 $number = $this->getNumberOfComments($poll_id);
73
74 if ($number > 0) {
75 echo "(" . $number . ")";
76 } else {
77 echo "";
78 }
79
80 exit();
81 }
82
83 public function getNumberOfComments(int $ref_id): int
84 {
85 $obj_id = $this->lookupObjectId($ref_id);
86 $context = $this->notes->data()->context($obj_id, 0, 'poll');
87 return $this->notes->domain()->getNrOfCommentsForContext($context);
88 }
89
90 protected function lookupObjectId(int $ref_id): int
91 {
93 }
94
95 protected function buildAjaxHashForPoll(int $ref_id, int $obj_id): string
96 {
99 $ref_id,
100 'poll',
101 $obj_id
102 );
103 }
104
106 string $ajax_hash,
107 int $ref_id
108 ): string {
109 return ilNoteGUI::getListCommentsJSCall(
110 $ajax_hash,
111 "ilPoll.redrawComments(" . $ref_id . ");"
112 );
113 }
114}
Builds data types.
Definition: Factory.php:36
static buildAjaxHash(int $node_type, ?int $node_id, string $obj_type, int $obj_id, ?string $sub_type=null, ?int $sub_id=null, int $news_id=0)
Build ajax hash.
@ilCtrl_Calls ilNoteGUI: ilCommentGUI
static _lookupObjectId(int $ref_id)
getListCommentsJSCallForPoll(string $ajax_hash, int $ref_id)
__construct(NotesService $notes, GlobalHttpState $http, Refinery $refinery, string $redraw_url)
buildAjaxHashForPoll(int $ref_id, int $obj_id)
commentJSCall(int $ref_id)
Builds JavaScript Call to open CommentLayer via html link.
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
exit
Interface GlobalHttpState.
$ref_id
Definition: ltiauth.php:66
static http()
Fetches the global http state from ILIAS.
$context
Definition: webdav.php:31