ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilTestSkillQuestionAssignmentsTableGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once 'Services/Table/classes/class.ilTable2GUI.php';
5 
13 {
18 
20  {
21  $this->skillQuestionAssignmentList = $assignmentList;
22  }
23 
24  public function __construct($parentOBJ, $parentCmd, ilCtrl $ctrl, ilLanguage $lng)
25  {
26  parent::__construct($parentOBJ, $parentCmd);
27 
28  $this->lng = $lng;
29  $this->ctrl = $ctrl;
30 
31  $this->setId('assQstSkl');
32  $this->getPrefix('assQstSkl');
33 
34  $this->setStyle('table', 'fullwidth');
35 
36  $this->setRowTemplate("tpl.tst_skl_qst_assignment_row.html", "Modules/Test");
37 
38  $this->enable('header');
39  $this->disable('sort');
40  $this->disable('select_all');
41 
42  $this->initColumns();
43 
44  $this->setFormAction($ctrl->getFormAction($parentOBJ));
45 
46  $this->addCommandButton(
47  ilTestSkillQuestionAssignmentsGUI::CMD_SAVE_SKILL_POINTS, $this->lng->txt('tst_save_comp_points')
48  );
49  }
50 
51  private function initColumns()
52  {
53  $this->addColumn($this->lng->txt('tst_question'),'question', '25%');
54  $this->addColumn($this->lng->txt('tst_competence'),'competence', '55%');
55  $this->addColumn($this->lng->txt('tst_comp_points'),'points', '');
56  $this->addColumn($this->lng->txt('actions') ,'actions', '');
57  }
58 
59  public function fillRow($question)
60  {
61  $assignments = $this->skillQuestionAssignmentList->getAssignmentsByQuestionId($question['question_id']);
62 
63  $this->ctrl->setParameter($this->parent_obj, 'question_id', $question['question_id']);
64 
65  $this->tpl->setCurrentBlock('question_title');
66  $this->tpl->setVariable('ROWSPAN', $this->getRowspan($assignments));
67  $this->tpl->setVariable('QUESTION', $question['title']);
68  $this->tpl->parseCurrentBlock();
69 
70  $this->tpl->setCurrentBlock('tbl_content');
71 
72  for($i = 0, $max = count($assignments); $i < $max; $i++)
73  {
74  $assignment = $assignments[$i];
75 
76  $this->tpl->setVariable('COMPETENCE', $assignment->getSkillTitle());
77  $this->tpl->setVariable('COMPETENCE_PATH', $assignment->getSkillPath());
78  $this->tpl->setVariable('QUANTIFIER', $this->buildQuantifierInput($assignment));
79  $this->tpl->setVariable('ACTION', $this->getRemoveCompetenceActionLink($assignment));
80 
81  $this->tpl->parseCurrentBlock();
82  $this->tpl->setVariable("CSS_ROW", $this->css_row);
83  $this->tpl->setVariable("CSS_NO_BORDER", 'ilBorderlessRow');
84  }
85 
86  $this->tpl->setVariable('ACTION', $this->getAddCompetenceActionLink());
87  }
88 
89  private function getRowspan($assignments)
90  {
91  $cnt = count($assignments);
92 
93  if( $cnt == 0 )
94  {
95  return 1;
96  }
97 
98  return $cnt + 1;
99  }
100 
102  {
103  $assignmentKey = implode(':', array(
104  $assignment->getSkillBaseId(), $assignment->getSkillTrefId(), $assignment->getQuestionId()
105  ));
106 
107  return "<input type\"text\" size=\"2\" name=\"quantifiers[{$assignmentKey}]\" value=\"{$assignment->getSkillPoints()}\" />";
108  }
109 
110  private function getAddCompetenceActionLink()
111  {
112  $href = $this->ctrl->getLinkTarget(
114  );
115 
116  $label = $this->lng->txt('tst_assign_competence');
117 
118  return $this->buildActionLink($href, $label);
119  }
120 
122  {
123  $this->ctrl->setParameter($this->parent_obj, 'skill_base_id', $assignment->getSkillBaseId());
124  $this->ctrl->setParameter($this->parent_obj, 'skill_tref_id', $assignment->getSkillTrefId());
125 
126  $href = $this->ctrl->getLinkTarget(
128  );
129 
130  $label = $this->lng->txt('tst_remove_competence');
131 
132  $this->ctrl->setParameter($this->parent_obj, 'skill_base_id', null);
133  $this->ctrl->setParameter($this->parent_obj, 'skill_tref_id', null);
134 
135  return $this->buildActionLink($href, $label);
136  }
137 
138  private function buildActionLink($href, $label)
139  {
140  return "<a href=\"{$href}\" title=\"{$label}\">{$label}</a>";
141  }
142 
143  private function buildActionColumnHTML($assignments)
144  {
145  $actions = array();
146 
147  foreach($assignments as $assignment)
148  {
149  $this->ctrl->setParameter($this->parent_obj, 'skill_base_id', $assignment->getSkillBaseId());
150  $this->ctrl->setParameter($this->parent_obj, 'skill_tref_id', $assignment->getSkillTrefId());
151 
152  $href = $this->ctrl->getLinkTarget(
154  );
155 
156  $label = $this->lng->txt('tst_remove_competence');
157 
158  $actions[] = $this->buildActionLink($href, $label);
159  }
160 
161  $href = $this->ctrl->getLinkTarget(
163  );
164 
165  $label = $this->lng->txt('tst_assign_competence');
166  $actions[] = $this->buildActionLink($href, $label);
167 
168  return implode('<br />', $actions);
169  }
170 }