ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 {
15  public function getType()
16  {
17  return "rating";
18  }
19 
20 
21  // PEER REVIEW
22 
23  public function addToPeerReviewForm($a_value = null)
24  {
25  global $tpl, $ilCtrl;
26 
27  $tpl->addJavaScript("Modules/Exercise/js/ilExcPeerReview.js");
28  $tpl->addOnLoadCode("il.ExcPeerReview.setAjax('".
29  $ilCtrl->getLinkTargetByClass("ilExPeerReviewGUI", "updateCritAjax", "", true, false).
30  "')");
31 
32  $field_id = "prccc_rating_".$this->getId();
33 
34  $input = new ilCustomInputGUI($this->getTitle(), $field_id);
35  $input->setInfo($this->getDescription());
36  $input->setRequired($this->isRequired());
37  $input->setHtml($this->renderWidget());
38  $this->form->addItem($input);
39 
40  // #16993 - making form checkInput() work
41  if(is_array($_POST) &&
42  array_key_exists("cmd", $_POST))
43  {
44  $_POST[$field_id] = $this->hasValue($a_value);
45  }
46 
47  $this->form_item = $input;
48  }
49 
50  protected function getRatingSubType()
51  {
52  return $this->getId()
53  ? "peer_".(int)$this->getId()
54  : "peer"; // no catalogue / v1
55  }
56 
57  protected function renderWidget($a_read_only = false)
58  {
59  include_once './Services/Rating/classes/class.ilRatingGUI.php';
60  $rating = new ilRatingGUI();
61  $rating->setObject(
62  $this->ass->getId(),
63  "ass",
65  $this->getRatingSubType()
66  );
67  $rating->setUserId($this->giver_id);
68 
69  $ajax_id = $this->getId()
70  ? (int)$this->getId()
71  : "'rating'";
72 
73  if(!(bool)$a_read_only)
74  {
75  $html = '<div class="crit_widget">'.
76  $rating->getHTML(false, true, "il.ExcPeerReview.saveCrit(this, ".$this->peer_id.", ".$ajax_id.", %rating%)").
77  '</div>';
78  }
79  else
80  {
81  $html = $rating->getHTML(false, false);
82  }
83 
84  return $html;
85  }
86 
87  public function importFromPeerReviewForm()
88  {
89  // see updateFromAjax()
90  }
91 
92  public function updateFromAjax()
93  {
94  // save rating
95  include_once './Services/Rating/classes/class.ilRating.php';
97  $this->ass->getId(),
98  "ass",
100  $this->getRatingSubType(),
102  $_POST["value"]
103  );
104 
105  // render current rating
106  // $ilCtrl->setParameter($this->parent_obj, "peer_id", $peer_id);
107  return $this->renderWidget($a_ass, $a_giver_id, $a_peer_id);
108  }
109 
110  public function validate($a_value)
111  {
112  global $lng;
113 
114  if($this->isRequired())
115  {
116  if(!$this->hasValue($a_value))
117  {
118  if($this->form)
119  {
120  $this->form->getItemByPostVar("prccc_rating_".$this->getId())->setAlert($lng->txt("msg_input_is_required"));
121  }
122  return false;
123  }
124  }
125  return true;
126  }
127 
128  public function hasValue($a_value)
129  {
130  include_once './Services/Rating/classes/class.ilRating.php';
132  $this->ass->getId(),
133  "ass",
135  $this->getRatingSubType(),
137  );
138  }
139 
140  public function getHTML($a_value)
141  {
142  return $this->renderWidget($this->ass, $this->giver_id, $this->peer_id, true);
143  }
144 
145  public function resetReview()
146  {
147  include_once './Services/Rating/classes/class.ilRating.php';
149  $this->ass->getId(),
150  "ass",
152  $this->getRatingSubType(),
154  );
155  }
156 
157 }
Class ilExcCriteria.
renderWidget($a_read_only=false)
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.
global $tpl
Definition: ilias.php:8
global $ilCtrl
Definition: ilias.php:18
Class ilRatingGUI.
Class ilExcCriteriaRating.
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.
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.
This class represents a custom property in a property form.
global $lng
Definition: privfeed.php:17
$_POST["username"]
$html
Definition: example_001.php:87