ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 $DIC;
56  $lng = $DIC['lng'];
57  $ilCtrl = $DIC['ilCtrl'];
58  $this->il_lng = $lng;
59  $this->il_lng->loadLanguageModule("prg");
60  $this->il_ctrl = $ilCtrl;
61 
62  $this->progress = $a_progress;
63  $this->tpl = null;
64  $this->html = null;
65  $this->show_info_mesage = false;
66  $this->visible_on_pd_mode = "read";
67  }
68 
69  public function getHTML() {
70  if ($this->html === null) {
71  $tpl = $this->getTemplate("Modules/StudyProgramme", static::$tpl_file, true, true);
72  $this->fillTemplate($tpl);
73  $this->html = $tpl->get();
74  }
75  return $this->html;
76  }
77 
78  protected function fillTemplate($tpl) {
79  $programme = $this->progress->getStudyProgramme();
80  $title_and_icon_target = $this->getTitleAndIconTarget($this->progress);
81 
82  if ($title_and_icon_target) {
83  $tpl->setCurrentBlock("linked_icon");
84  $tpl->setVariable("SRC_ICON", $this->getIconPath($programme->getId()));
85  $tpl->setVariable("ALT_ICON", $this->getAltIcon($programme->getId()));
86  $tpl->setVariable("ICON_HREF", $title_and_icon_target);
87  $tpl->parseCurrentBlock();
88 
89  $tpl->setCurrentBlock("linked_title");
90  $tpl->setVariable("TXT_TITLE", $this->getTitleForItem($programme));
91  $tpl->setVariable("HREF_TITLE", $title_and_icon_target);
92  $tpl->parseCurrentBlock();
93  }
94  else {
95  $tpl->setCurrentBlock("not_linked_icon");
96  $tpl->setVariable("SRC_ICON", $this->getIconPath($programme->getId()));
97  $tpl->setVariable("ALT_ICON", $this->getAltIcon($programme->getId()));
98  $tpl->parseCurrentBlock();
99 
100  $tpl->setCurrentBlock("not_linked_title");
101  $tpl->setVariable("TXT_TITLE", $this->getTitleForItem($programme));
102  $tpl->parseCurrentBlock();
103  }
104 
105  if($this->show_info_mesage) {
106  if($this->showMoreObjectsInfo($programme)) {
107  $tpl->setVariable("MORE_OBJECTS",$this->il_lng->txt("prg_more_objects_without_read_permission"));
108  }
109  }
110  $tpl->setVariable("TXT_DESC", $programme->getDescription());
111  $tpl->setVariable("PROGRESS_BAR", $this->buildProgressBar($this->progress));
112  }
113 
114  protected function getTitleForItem(ilObjStudyProgramme $a_programme) {
115  return $a_programme->getTitle();
116  }
117 
118  protected function getTemplate($a_component, $a_file, $a_remove_unknown_vars, $a_remove_empty_blocks) {
119  return new ilTemplate($a_file, $a_remove_unknown_vars, $a_remove_empty_blocks, $a_component);
120  }
121 
122  protected function getIconPath($a_obj_id) {
123  return ilObject::_getIcon($a_obj_id, "small", "prg");
124  }
125 
126  protected function getAltIcon($a_obj_id) {
127  return $this->il_lng->txt("icon")." ".$this->il_lng->txt("obj_prg");
128  }
129 
130  protected function getTitleAndIconTarget(ilStudyProgrammeUserProgress $a_progress) {
131  $this->il_ctrl->setParameterByClass("ilPersonalDesktopGUI", "prg_progress_id", $a_progress->getId());
132  $this->il_ctrl->setParameterByClass("ilPersonalDesktopGUI", "expand", 1);
133  $link = $this->il_ctrl->getLinkTargetByClass("ilPersonalDesktopGUI", "jumpToSelectedItems");
134  $this->il_ctrl->setParameterByClass("ilPersonalDesktopGUI", "prg_progress_id", null);
135  $this->il_ctrl->setParameterByClass("ilPersonalDesktopGUI", "expand", null);
136  return $link;
137  }
138 
139  protected function buildProgressBar(ilStudyProgrammeUserProgress $a_progress) {
140  $tooltip_id = "prg_".$a_progress->getId();
141 
142  $required_amount_of_points = $a_progress->getAmountOfPoints();
143  $maximum_possible_amount_of_points = $a_progress->getMaximumPossibleAmountOfPoints(true);
144  $current_amount_of_points = $a_progress->getCurrentAmountOfPoints();
145 
146  if ($maximum_possible_amount_of_points > 0) {
147  $current_percent = (int)($current_amount_of_points * 100 / $maximum_possible_amount_of_points);
148  $required_percent = (int)($required_amount_of_points * 100 / $maximum_possible_amount_of_points);
149  }
150  else {
151  if ($a_progress->isSuccessful()) {
152  $current_percent = 100;
153  $required_percent = 100;
154  }
155  else {
156  $current_percent = 0;
157  $required_percent = 0;
158  }
159  }
160 
161  //required to dodge bug in ilContainerObjectiveGUI::renderProgressBar
162  if($required_percent == 0) {
163  $required_percent = 0.1;
164  }
165 
166  $tooltip_txt = $this->buildToolTip($a_progress);
167  $progress_status = $this->buildProgressStatus($a_progress);
168 
169  if ($a_progress->isSuccessful()) {
170  $css_class = self::SUCCESSFUL_PROGRESS_CSS_CLASS;
171  }
172  else {
173  $css_class = self::NON_SUCCESSFUL_PROGRESS_CSS_CLASS;
174  }
175 
176  require_once("Services/Container/classes/class.ilContainerObjectiveGUI.php");
177  return ilContainerObjectiveGUI::renderProgressBar($current_percent, $required_percent, $css_class
178  , $progress_status, null, $tooltip_id, $tooltip_txt);
179  }
180 
181  protected function buildToolTip(ilStudyProgrammeUserProgress $a_progress) {
182  return sprintf( $this->il_lng->txt("prg_progress_info")
183  , $a_progress->getCurrentAmountOfPoints()
184  , $a_progress->getAmountOfPoints()
185  );
186  }
187 
188  protected function buildProgressStatus(ilStudyProgrammeUserProgress $a_progress) {
189  $lang_val = "prg_progress_status";
190  $max_points = $a_progress->getAmountOfPoints();
191  $study_programm = $a_progress->getStudyProgramme();
192 
193  if($study_programm->hasChildren() && !$study_programm->hasLPChildren()) {
194  $lang_val = "prg_progress_status_with_child_sp";
195  }
196 
197  if($a_progress->getStudyProgramme()->hasChildren()) {
198  $max_points = $a_progress->getMaximumPossibleAmountOfPoints($this->only_relevant);
199  }
200  return sprintf( $this->il_lng->txt($lang_val)
201  , $a_progress->getCurrentAmountOfPoints()
202  , $max_points
203  );
204  }
205 
207  $this->show_info_mesage = $show_info_mesage;
208  }
209 
211  $this->visible_on_pd_mode = $visible_on_pd_mode;
212  }
213 
214  public function setOnlyRelevant($only_relevant) {
215  $this->only_relevant = $only_relevant;
216  }
217 
218  protected function showMoreObjectsInfo($programme) {
219  $children = $programme->getChildren();
220  foreach ($children as $key => $child) {
221  $read = $this->il_access->checkAccess("read", "", $child->getRefId(), "prg", $child->getId());
222  if(!$read && $this->visible_on_pd_mode != ilObjStudyProgrammeAdmin::SETTING_VISIBLE_ON_PD_ALLWAYS) {
223  return true;
224  }
225  }
226 
227  return false;
228  }
229 }
230 
231 
232 ?>
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:17
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)
global $DIC
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.