ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
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 
12 {
16  protected $tpl;
17 
21  protected $ctrl;
22 
26  protected $lng;
27 
28 
32  public function __construct()
33  {
34  global $DIC;
35 
37  $this->tpl = $DIC["tpl"];
38  $this->ctrl = $DIC->ctrl();
39  $this->lng = $DIC->language();
40  }
41 
42  public function getType()
43  {
44  return "rating";
45  }
46 
47 
48  // PEER REVIEW
49 
50  public function addToPeerReviewForm($a_value = null)
51  {
52  $tpl = $this->tpl;
54 
55  $tpl->addJavaScript("Modules/Exercise/js/ilExcPeerReview.js");
56  $tpl->addOnLoadCode("il.ExcPeerReview.setAjax('" .
57  $ilCtrl->getLinkTargetByClass("ilExPeerReviewGUI", "updateCritAjax", "", true, false) .
58  "')");
59 
60  $field_id = "prccc_rating_" . $this->getId();
61 
62  $input = new ilCustomInputGUI($this->getTitle(), $field_id);
63  $input->setInfo($this->getDescription());
64  $input->setRequired($this->isRequired());
65  $input->setHtml($this->renderWidget());
66  $this->form->addItem($input);
67 
68  // #16993 - making form checkInput() work
69  if (is_array($_POST) &&
70  array_key_exists("cmd", $_POST)) {
71  $_POST[$field_id] = $this->hasValue($a_value);
72  }
73 
74  $this->form_item = $input;
75  }
76 
77  protected function getRatingSubType()
78  {
79  return $this->getId()
80  ? "peer_" . (int) $this->getId()
81  : "peer"; // no catalogue / v1
82  }
83 
84  protected function renderWidget($a_read_only = false)
85  {
86  $rating = new ilRatingGUI();
87  $rating->setObject(
88  $this->ass->getId(),
89  "ass",
91  $this->getRatingSubType()
92  );
93  $rating->setUserId($this->giver_id);
94 
95  $ajax_id = $this->getId()
96  ? (int) $this->getId()
97  : "'rating'";
98 
99  if (!(bool) $a_read_only) {
100  $html = '<div class="crit_widget">' .
101  $rating->getHTML(false, true, "il.ExcPeerReview.saveCrit(this, " . $this->peer_id . ", " . $ajax_id . ", %rating%)") .
102  '</div>';
103  } else {
104  $html = $rating->getHTML(false, false);
105  }
106 
107  return $html;
108  }
109 
110  public function importFromPeerReviewForm()
111  {
112  // see updateFromAjax()
113  }
114 
115  public function updateFromAjax()
116  {
117  // save rating
119  $this->ass->getId(),
120  "ass",
122  $this->getRatingSubType(),
124  $_POST["value"]
125  );
126 
127  // render current rating
128  // $ilCtrl->setParameter($this->parent_obj, "peer_id", $peer_id);
129  return $this->renderWidget($a_ass, $a_giver_id, $a_peer_id);
130  }
131 
132  public function validate($a_value)
133  {
134  $lng = $this->lng;
135 
136  if ($this->isRequired()) {
137  if (!$this->hasValue($a_value)) {
138  if ($this->form) {
139  $this->form->getItemByPostVar("prccc_rating_" . $this->getId())->setAlert($lng->txt("msg_input_is_required"));
140  }
141  return false;
142  }
143  }
144  return true;
145  }
146 
147  public function hasValue($a_value)
148  {
150  $this->ass->getId(),
151  "ass",
153  $this->getRatingSubType(),
155  );
156  }
157 
158  public function getHTML($a_value)
159  {
160  return $this->renderWidget($this->ass, $this->giver_id, $this->peer_id, true);
161  }
162 
163  public function resetReview()
164  {
166  $this->ass->getId(),
167  "ass",
169  $this->getRatingSubType(),
171  );
172  }
173 }
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.
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.
__construct(Container $dic, ilPlugin $plugin)
$DIC
Definition: xapitoken.php:46
$_POST["username"]