ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilStudyProgrammeProgressListGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 2015 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4 
12 require_once('./Modules/StudyProgramme/classes/class.ilObjStudyProgrammeAdmin.php');
14  protected static $tpl_file = "tpl.progress_list_item.html";
15 
16  const SUCCESSFUL_PROGRESS_CSS_CLASS = "ilCourseObjectiveProgressBarCompleted";
17  const NON_SUCCESSFUL_PROGRESS_CSS_CLASS = "ilCourseObjectiveProgressBarNeutral";
18 
22  protected $il_lng;
23 
27  protected $il_ctrl;
28 
32  protected $progress;
33 
37  protected $html;
38 
42  protected $show_info_mesage;
43 
48 
52  protected $only_relevant = false;
53 
54  function __construct(ilStudyProgrammeUserProgress $a_progress) {
55  global $lng, $ilCtrl;
56  $this->il_lng = $lng;
57  $this->il_lng->loadLanguageModule("prg");
58  $this->il_ctrl = $ilCtrl;
59 
60  $this->progress = $a_progress;
61  $this->tpl = null;
62  $this->html = null;
63  $this->show_info_mesage = false;
64  $this->visible_on_pd_mode = "read";
65  }
66 
67  public function getHTML() {
68  if ($this->html === null) {
69  $tpl = $this->getTemplate("Modules/StudyProgramme", static::$tpl_file, true, true);
70  $this->fillTemplate($tpl);
71  $this->html = $tpl->get();
72  }
73  return $this->html;
74  }
75 
76  protected function fillTemplate($tpl) {
77  $programme = $this->progress->getStudyProgramme();
78  $title_and_icon_target = $this->getTitleAndIconTarget($this->progress);
79 
80  if ($title_and_icon_target) {
81  $tpl->setCurrentBlock("linked_icon");
82  $tpl->setVariable("SRC_ICON", $this->getIconPath($programme->getId()));
83  $tpl->setVariable("ALT_ICON", $this->getAltIcon($programme->getId()));
84  $tpl->setVariable("ICON_HREF", $title_and_icon_target);
85  $tpl->parseCurrentBlock();
86 
87  $tpl->setCurrentBlock("linked_title");
88  $tpl->setVariable("TXT_TITLE", $this->getTitleForItem($programme));
89  $tpl->setVariable("HREF_TITLE", $title_and_icon_target);
90  $tpl->parseCurrentBlock();
91  }
92  else {
93  $tpl->setCurrentBlock("not_linked_icon");
94  $tpl->setVariable("SRC_ICON", $this->getIconPath($programme->getId()));
95  $tpl->setVariable("ALT_ICON", $this->getAltIcon($programme->getId()));
96  $tpl->parseCurrentBlock();
97 
98  $tpl->setCurrentBlock("not_linked_title");
99  $tpl->setVariable("TXT_TITLE", $this->getTitleForItem($programme));
100  $tpl->parseCurrentBlock();
101  }
102 
103  if($this->show_info_mesage) {
104  if($this->showMoreObjectsInfo($programme)) {
105  $tpl->setVariable("MORE_OBJECTS",$this->il_lng->txt("prg_more_objects_without_read_permission"));
106  }
107  }
108  $tpl->setVariable("TXT_DESC", $programme->getDescription());
109  $tpl->setVariable("PROGRESS_BAR", $this->buildProgressBar($this->progress));
110  }
111 
112  protected function getTitleForItem(ilObjStudyProgramme $a_programme) {
113  return $a_programme->getTitle();
114  }
115 
116  protected function getTemplate($a_component, $a_file, $a_remove_unknown_vars, $a_remove_empty_blocks) {
117  return new ilTemplate($a_file, $a_remove_unknown_vars, $a_remove_empty_blocks, $a_component);
118  }
119 
120  protected function getIconPath($a_obj_id) {
121  return ilObject::_getIcon($a_obj_id, "small", "prg");
122  }
123 
124  protected function getAltIcon($a_obj_id) {
125  return $this->il_lng->txt("icon")." ".$this->il_lng->txt("obj_prg");
126  }
127 
128  protected function getTitleAndIconTarget(ilStudyProgrammeUserProgress $a_progress) {
129  $this->il_ctrl->setParameterByClass("ilPersonalDesktopGUI", "prg_progress_id", $a_progress->getId());
130  $this->il_ctrl->setParameterByClass("ilPersonalDesktopGUI", "expand", 1);
131  $link = $this->il_ctrl->getLinkTargetByClass("ilPersonalDesktopGUI", "jumpToSelectedItems");
132  $this->il_ctrl->setParameterByClass("ilPersonalDesktopGUI", "prg_progress_id", null);
133  $this->il_ctrl->setParameterByClass("ilPersonalDesktopGUI", "expand", null);
134  return $link;
135  }
136 
137  protected function buildProgressBar(ilStudyProgrammeUserProgress $a_progress) {
138  $tooltip_id = "prg_".$a_progress->getId();
139 
140  $required_amount_of_points = $a_progress->getAmountOfPoints();
141  $maximum_possible_amount_of_points = $a_progress->getMaximumPossibleAmountOfPoints(true);
142  $current_amount_of_points = $a_progress->getCurrentAmountOfPoints();
143 
144  if ($maximum_possible_amount_of_points > 0) {
145  $current_percent = (int)($current_amount_of_points * 100 / $maximum_possible_amount_of_points);
146  $required_percent = (int)($required_amount_of_points * 100 / $maximum_possible_amount_of_points);
147  }
148  else {
149  if ($a_progress->isSuccessful()) {
150  $current_percent = 100;
151  $required_percent = 100;
152  }
153  else {
154  $current_percent = 0;
155  $required_percent = 0;
156  }
157  }
158 
159  //required to dodge bug in ilContainerObjectiveGUI::renderProgressBar
160  if($required_percent == 0) {
161  $required_percent = 0.1;
162  }
163 
164  $tooltip_txt = $this->buildToolTip($a_progress);
165  $progress_status = $this->buildProgressStatus($a_progress);
166 
167  if ($a_progress->isSuccessful()) {
168  $css_class = self::SUCCESSFUL_PROGRESS_CSS_CLASS;
169  }
170  else {
171  $css_class = self::NON_SUCCESSFUL_PROGRESS_CSS_CLASS;
172  }
173 
174  require_once("Services/Container/classes/class.ilContainerObjectiveGUI.php");
175  return ilContainerObjectiveGUI::renderProgressBar($current_percent, $required_percent, $css_class
176  , $progress_status, null, $tooltip_id, $tooltip_txt);
177  }
178 
179  protected function buildToolTip(ilStudyProgrammeUserProgress $a_progress) {
180  return sprintf( $this->il_lng->txt("prg_progress_info")
181  , $a_progress->getCurrentAmountOfPoints()
182  , $a_progress->getAmountOfPoints()
183  );
184  }
185 
186  protected function buildProgressStatus(ilStudyProgrammeUserProgress $a_progress) {
187  $lang_val = "prg_progress_status";
188  $max_points = $a_progress->getAmountOfPoints();
189  $study_programm = $a_progress->getStudyProgramme();
190 
191  if($study_programm->hasChildren() && !$study_programm->hasLPChildren()) {
192  $lang_val = "prg_progress_status_with_child_sp";
193  }
194 
195  if($a_progress->getStudyProgramme()->hasChildren()) {
196  $max_points = $a_progress->getMaximumPossibleAmountOfPoints($this->only_relevant);
197  }
198  return sprintf( $this->il_lng->txt($lang_val)
199  , $a_progress->getCurrentAmountOfPoints()
200  , $max_points
201  );
202  }
203 
205  $this->show_info_mesage = $show_info_mesage;
206  }
207 
209  $this->visible_on_pd_mode = $visible_on_pd_mode;
210  }
211 
212  public function setOnlyRelevant($only_relevant) {
213  $this->only_relevant = $only_relevant;
214  }
215 
216  protected function showMoreObjectsInfo($programme) {
217  $children = $programme->getChildren();
218  foreach ($children as $key => $child) {
219  $read = $this->il_access->checkAccess("read", "", $child->getRefId(), "prg", $child->getId());
220  if(!$read && $this->visible_on_pd_mode != ilObjStudyProgrammeAdmin::SETTING_VISIBLE_ON_PD_ALLWAYS) {
221  return true;
222  }
223  }
224 
225  return false;
226  }
227 }
228 
229 
230 ?>
buildProgressStatus(ilStudyProgrammeUserProgress $a_progress)
static _getIcon($a_obj_id="", $a_size="big", $a_type="", $a_offline=false)
Get icon for repository item.
getCurrentAmountOfPoints()
Get the amount of points the user currently achieved.
buildProgressBar(ilStudyProgrammeUserProgress $a_progress)
getStudyProgramme()
Get the program node where this progress belongs to was made.
isSuccessful()
Check whether the user was successful on this node.
global $tpl
Definition: ilias.php:8
global $ilCtrl
Definition: ilias.php:18
__construct(ilStudyProgrammeUserProgress $a_progress)
getTitleAndIconTarget(ilStudyProgrammeUserProgress $a_progress)
Class ilObjStudyProgramme.
special template class to simplify handling of ITX/PEAR
getTitle()
get object title public
getAmountOfPoints()
Get the amount of points needed to complete the node.
buildToolTip(ilStudyProgrammeUserProgress $a_progress)
global $lng
Definition: privfeed.php:40
getMaximumPossibleAmountOfPoints($only_relevant=false)
Get the maximum possible amount of points a user can achieve for the completion of this node...
Class ilStudyProgrammeProgressListGUI.
getTemplate($a_component, $a_file, $a_remove_unknown_vars, $a_remove_empty_blocks)
static renderProgressBar($a_perc_result=null, $a_perc_limit=null, $a_css=null, $a_caption=null, $a_url=null, $a_tt_id=null, $a_tt_txt=null, $a_next_step=null, $a_sub=false, $a_sub_style=30)
Render progress bar(s)
Represents the progress of a user at one node of a study programme.