ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilExcCriteriaRating.php
Go to the documentation of this file.
1<?php
2
20
28{
29 protected \ILIAS\HTTP\Services $http;
33
37 public function __construct()
38 {
39 global $DIC;
40
42 $this->tpl = $DIC->ui()->mainTemplate();
43 $this->request = $DIC->exercise()->internal()->gui()->request();
44 $this->http = $DIC->http();
45 }
46
47 public function getType(): string
48 {
49 return "rating";
50 }
51
52
53 // PEER REVIEW
54
55 public function addToPeerReviewForm($a_value = null): void
56 {
58 $ilCtrl = $this->ctrl;
59
60 $tpl->addJavaScript("assets/js/ilExcPeerReview.js");
61 $tpl->addOnLoadCode("il.ExcPeerReview.setAjax('" .
62 $ilCtrl->getLinkTargetByClass("ilExPeerReviewGUI", "updateCritAjax", "", true, false) .
63 "')");
64
65 $field_id = "prccc_rating_" . $this->getId();
66
67 $input = new ilCustomInputGUI($this->getTitle(), $field_id);
68 $input->setInfo($this->getDescription());
69 $input->setRequired($this->isRequired());
70 $input->setHtml($this->renderWidget());
71 $this->form->addItem($input);
72
73 // #16993 - making form checkInput() work
74 if ($this->hasValue("")) {
75 $input->setSkipRequiredCheck(true);
76 }
77
78 $this->form_item = $input;
79 }
80
81 protected function getRatingSubType(): string
82 {
83 return $this->getId()
84 ? "peer_" . $this->getId()
85 : "peer"; // no catalogue / v1
86 }
87
88 protected function renderWidget(bool $a_read_only = false): string
89 {
90 $rating = new ilRatingGUI();
91 $rating->setObject(
92 $this->ass->getId(),
93 "ass",
94 $this->peer_id,
95 $this->getRatingSubType()
96 );
97 $rating->setUserId($this->giver_id);
98
99 $ajax_id = $this->getId()
100 ?: "rating";
101
102 if (!$a_read_only) {
103 $html = '<div class="crit_widget" data-crit-id="' . $ajax_id . '">' .
104 $rating->getHTML(false, true, "il.ExcPeerReview.saveCrit(this, " . $this->peer_id . ", '" . $ajax_id . "', %rating%)") .
105 '</div>';
106 } else {
107 $html = $rating->getHTML(false, false);
108 }
109 return $html;
110 }
111
112 public function importFromPeerReviewForm(): void
113 {
114 // see updateFromAjax()
115 }
116
117 public function updateFromAjax(): string
118 {
119 // save rating
121 $this->ass->getId(),
122 "ass",
123 $this->peer_id,
124 $this->getRatingSubType(),
125 $this->giver_id,
126 $this->request->getRatingValue()
127 );
128
129 // render current rating
130 return $this->renderWidget();
131 }
132
133 public function validate($a_value): bool
134 {
136
137 if ($this->isRequired()) {
138 if (!$this->hasValue($a_value)) {
139 if ($this->form) {
140 $this->form->getItemByPostVar("prccc_rating_" . $this->getId())->setAlert($lng->txt("msg_input_is_required"));
141 }
142 return false;
143 }
144 }
145 return true;
146 }
147
148 public function hasValue($a_value): bool
149 {
151 $this->ass->getId(),
152 "ass",
153 $this->peer_id,
154 $this->getRatingSubType(),
155 $this->giver_id
156 );
157 }
158
159 public function getHTML($a_value): string
160 {
161 return $this->renderWidget(true);
162 }
163
164 public function resetReview(): void
165 {
167 $this->ass->getId(),
168 "ass",
169 $this->peer_id,
170 $this->getRatingSubType(),
171 $this->giver_id
172 );
173 }
174}
Exercise gui request wrapper.
This class represents a custom property in a property form.
Class ilExcCriteriaRating.
renderWidget(bool $a_read_only=false)
ilGlobalTemplateInterface $tpl
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static resetRatingForUserAndObject(int $a_obj_id, string $a_obj_type, int $a_sub_obj_id, string $a_sub_obj_type, int $a_user_id)
Reset rating for a user and an object.
static getRatingForUserAndObject(int $a_obj_id, string $a_obj_type, int $a_sub_obj_id, string $a_sub_obj_type, int $a_user_id, ?int $a_category_id=null)
Get rating for a user and an object.
static writeRatingForUserAndObject(int $a_obj_id, string $a_obj_type, ?int $a_sub_obj_id, ?string $a_sub_obj_type, int $a_user_id, int $a_rating, int $a_category_id=0)
Write rating for a user and an object.
addJavaScript(string $a_js_file, bool $a_add_version_parameter=true, int $a_batch=2)
Add a javascript file that should be included in the header.
addOnLoadCode(string $a_code, int $a_batch=2)
Add on load code.
static http()
Fetches the global http state from ILIAS.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
form( $class_path, string $cmd, string $submit_caption="")
global $DIC
Definition: shib_login.php:26