ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilExcCriteriaRating.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 include_once "Modules/Exercise/classes/class.ilExcCriteria.php";
6 
14 {
18  protected $tpl;
19 
23  protected $ctrl;
24 
28  protected $lng;
29 
30 
34  public function __construct()
35  {
36  global $DIC;
37 
38  parent::__construct();
39  $this->tpl = $DIC["tpl"];
40  $this->ctrl = $DIC->ctrl();
41  $this->lng = $DIC->language();
42  }
43 
44  public function getType()
45  {
46  return "rating";
47  }
48 
49 
50  // PEER REVIEW
51 
52  public function addToPeerReviewForm($a_value = null)
53  {
54  $tpl = $this->tpl;
56 
57  $tpl->addJavaScript("Modules/Exercise/js/ilExcPeerReview.js");
58  $tpl->addOnLoadCode("il.ExcPeerReview.setAjax('" .
59  $ilCtrl->getLinkTargetByClass("ilExPeerReviewGUI", "updateCritAjax", "", true, false) .
60  "')");
61 
62  $field_id = "prccc_rating_" . $this->getId();
63 
64  $input = new ilCustomInputGUI($this->getTitle(), $field_id);
65  $input->setInfo($this->getDescription());
66  $input->setRequired($this->isRequired());
67  $input->setHtml($this->renderWidget());
68  $this->form->addItem($input);
69 
70  // #16993 - making form checkInput() work
71  if (is_array($_POST) &&
72  array_key_exists("cmd", $_POST)) {
73  $_POST[$field_id] = $this->hasValue($a_value);
74  }
75 
76  $this->form_item = $input;
77  }
78 
79  protected function getRatingSubType()
80  {
81  return $this->getId()
82  ? "peer_" . (int) $this->getId()
83  : "peer"; // no catalogue / v1
84  }
85 
86  protected function renderWidget($a_read_only = false)
87  {
88  include_once './Services/Rating/classes/class.ilRatingGUI.php';
89  $rating = new ilRatingGUI();
90  $rating->setObject(
91  $this->ass->getId(),
92  "ass",
94  $this->getRatingSubType()
95  );
96  $rating->setUserId($this->giver_id);
97 
98  $ajax_id = $this->getId()
99  ? (int) $this->getId()
100  : "'rating'";
101 
102  if (!(bool) $a_read_only) {
103  $html = '<div class="crit_widget">' .
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 
110  return $html;
111  }
112 
113  public function importFromPeerReviewForm()
114  {
115  // see updateFromAjax()
116  }
117 
118  public function updateFromAjax()
119  {
120  // save rating
121  include_once './Services/Rating/classes/class.ilRating.php';
123  $this->ass->getId(),
124  "ass",
126  $this->getRatingSubType(),
128  $_POST["value"]
129  );
130 
131  // render current rating
132  // $ilCtrl->setParameter($this->parent_obj, "peer_id", $peer_id);
133  return $this->renderWidget($a_ass, $a_giver_id, $a_peer_id);
134  }
135 
136  public function validate($a_value)
137  {
138  $lng = $this->lng;
139 
140  if ($this->isRequired()) {
141  if (!$this->hasValue($a_value)) {
142  if ($this->form) {
143  $this->form->getItemByPostVar("prccc_rating_" . $this->getId())->setAlert($lng->txt("msg_input_is_required"));
144  }
145  return false;
146  }
147  }
148  return true;
149  }
150 
151  public function hasValue($a_value)
152  {
153  include_once './Services/Rating/classes/class.ilRating.php';
155  $this->ass->getId(),
156  "ass",
158  $this->getRatingSubType(),
160  );
161  }
162 
163  public function getHTML($a_value)
164  {
165  return $this->renderWidget($this->ass, $this->giver_id, $this->peer_id, true);
166  }
167 
168  public function resetReview()
169  {
170  include_once './Services/Rating/classes/class.ilRating.php';
172  $this->ass->getId(),
173  "ass",
175  $this->getRatingSubType(),
177  );
178  }
179 }
static writeRatingForUserAndObject( $a_obj_id, $a_obj_type, $a_sub_obj_id, $a_sub_obj_type, $a_user_id, $a_rating, $a_category_id=0)
Write rating for a user and an object.
Class ilExcCriteria.
global $DIC
Definition: saml.php:7
renderWidget($a_read_only=false)
global $ilCtrl
Definition: ilias.php:18
static getRatingForUserAndObject( $a_obj_id, $a_obj_type, $a_sub_obj_id, $a_sub_obj_type, $a_user_id, $a_category_id=null)
Get rating for a user and an object.
Class ilRatingGUI.
static resetRatingForUserAndObject( $a_obj_id, $a_obj_type, $a_sub_obj_id, $a_sub_obj_type, $a_user_id)
Reset rating for a user and an object.
Class ilExcCriteriaRating.
This class represents a custom property in a property form.
$_POST["username"]
$html
Definition: example_001.php:87