ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilPollCommentsHandler.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
25 
27 {
28  protected NotesService $notes;
30  protected Refinery $refinery;
31 
32  protected string $redraw_url;
33 
34  public function __construct(
35  NotesService $notes,
36  GlobalHttpState $http,
37  Refinery $refinery,
38  string $redraw_url
39  ) {
40  $this->notes = $notes;
41  $this->http = $http;
42  $this->refinery = $refinery;
43  $this->redraw_url = $redraw_url;
44  }
45 
46  public function getRedrawURL(): string
47  {
48  return $this->redraw_url;
49  }
50 
54  public function commentJSCall(int $ref_id): string
55  {
56  $obj_id = $this->lookupObjectId($ref_id);
57  $ajax_hash = $this->buildAjaxHashForPoll($ref_id, $obj_id);
58 
59 
60  return $this->getListCommentsJSCallForPoll($ajax_hash, $ref_id);
61  }
62 
63  public function getNumberOfCommentsForRedraw(): void
64  {
65  $poll_id = 0;
66  if ($this->http->wrapper()->query()->has('poll_id')) {
67  $poll_id = $this->http->wrapper()->query()->retrieve(
68  'poll_id',
69  $this->refinery->kindlyTo()->int()
70  );
71  }
72 
73  $number = $this->getNumberOfComments($poll_id);
74 
75  if ($number > 0) {
76  echo "(" . $number . ")";
77  } else {
78  echo "";
79  }
80 
81  exit();
82  }
83 
84  public function getNumberOfComments(int $ref_id): int
85  {
86  $obj_id = $this->lookupObjectId($ref_id);
87  $context = $this->notes->data()->context($obj_id, 0, 'poll');
88  return $this->notes->domain()->getNrOfCommentsForContext($context);
89  }
90 
91  protected function lookupObjectId(int $ref_id): int
92  {
93  return ilObject2::_lookupObjectId($ref_id);
94  }
95 
96  protected function buildAjaxHashForPoll(int $ref_id, int $obj_id): string
97  {
100  $ref_id,
101  'poll',
102  $obj_id
103  );
104  }
105 
106  protected function getListCommentsJSCallForPoll(
107  string $ajax_hash,
108  int $ref_id
109  ): string {
111  $ajax_hash,
112  "ilPoll.redrawComments(" . $ref_id . ");"
113  );
114  }
115 }
$context
Definition: webdav.php:31
commentJSCall(int $ref_id)
Builds JavaScript Call to open CommentLayer via html link.
getListCommentsJSCallForPoll(string $ajax_hash, int $ref_id)
__construct(NotesService $notes, GlobalHttpState $http, Refinery $refinery, string $redraw_url)
buildAjaxHashForPoll(int $ref_id, int $obj_id)
$ref_id
Definition: ltiauth.php:66
static http()
Fetches the global http state from ILIAS.
static _lookupObjectId(int $ref_id)
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.
static getListCommentsJSCall(string $a_hash, string $a_update_code=null)
Get list comments js call.