ILIAS  trunk Revision v11.0_alpha-1689-g66c127b4ae8
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilLTIConsumerGradeSynchronizationGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
30 {
32 
34  private \ilGlobalTemplateInterface $main_tpl;
35  private \ILIAS\DI\Container $dic;
36 
37  public function __construct(ilObjLTIConsumer $object)
38  {
39  global $DIC;
40  $this->dic = $DIC;
41  $this->main_tpl = $DIC->ui()->mainTemplate();
42  $this->object = $object;
43 
44  $this->access = ilLTIConsumerAccess::getInstance($this->object);
45  }
46 
50  public function executeCommand(): bool
51  {
52  global $DIC; /* @var \ILIAS\DI\Container $DIC */
53 
54  if (!$this->object->getProvider()->isGradeSynchronization()) {
55  throw new ilLtiConsumerException('access denied!');
56  }
57 
58  switch ($DIC->ctrl()->getNextClass($this)) {
59  default:
60  $cmd = $DIC->ctrl()->getCmd('show') . 'Cmd';
61  $this->{$cmd}();
62  }
63  return true;
64  }
65 
66  protected function resetFilterCmd(): void
67  {
68  $table = $this->buildTableGUI();
69  $table->resetFilter();
70  $table->resetOffset();
71  $this->showCmd();
72  }
73 
74  protected function applyFilterCmd(): void
75  {
76  $table = $this->buildTableGUI();
77  $table->writeFilterToSession();
78  $table->resetOffset();
79  $this->showCmd();
80  }
81 
82  protected function showCmd(): void
83  {
84  global $DIC; /* @var \ILIAS\DI\Container $DIC */
85 
86  $table = $this->buildTableGUI();
87 
88  try {
89  $statementsFilter = new ilLTIConsumerGradeSynchronizationFilter();
90 
91  $this->initLimitingAndOrdering($statementsFilter, $table);
92  $this->initActorFilter($statementsFilter, $table);
93  $this->initActivityProgressFilter($statementsFilter, $table);
94  $this->initGradingProgressFilter($statementsFilter, $table);
95  $this->initPeriodFilter($statementsFilter, $table);
96  $this->initTableData($table, $statementsFilter);
97  } catch (Exception $e) {
98  $this->main_tpl->setOnScreenMessage('failure', $e->getMessage());
99  $table->setData(array());
100  $table->setMaxCount(0);
101  $table->resetOffset();
102  }
103 
104  $DIC->ui()->mainTemplate()->setContent($table->getHTML());
105  }
106 
108  {
109  $table->determineOffsetAndOrder(true);
110 
111  $filter->setLimit($table->getLimit());
112  $filter->setOffset($table->getOffset());
113 
114  $filter->setOrderField($table->getOrderField());
115  $filter->setOrderDirection($table->getOrderDirection());
116  }
117 
119  {
120  global $DIC; /* @var \ILIAS\DI\Container $DIC */
121 
122  if ($this->object->getProvider()->isGradeSynchronization()) {
123  if ($table->getFilterItemByPostVar('actor') !== null) {
124  $actor = $table->getFilterItemByPostVar('actor')->getValue();
125  } else {
126  $actor = $DIC->user()->getLogin();
127  }
128 
129  if (strlen($actor)) {
130  $usrId = ilObjUser::getUserIdByLogin($actor);
131 
132  if ($usrId) {
133  $filter->setActor($usrId);
134  }
135  }
136  } else {
137  $filter->setActor($DIC->user()->getId());
138  }
139  }
140 
142  {
143  $activityProgress = urldecode($table->getFilterItemByPostVar('activity_progress')->getValue());
144 
145  $allowed = ['Initialized', 'Started', 'InProgress', 'Submitted', 'Completed'];
146 
147  if (in_array($activityProgress, $allowed)) {
148  $filter->setActivityProgress($activityProgress);
149  }
150  }
151 
153  {
154  $gradingProgress = urldecode($table->getFilterItemByPostVar('grading_progress')->getValue());
155 
156  $allowed = ['FullyGraded', 'Pending', 'PendingManual', 'Failed', 'NotReady'];
157 
158  if (in_array($gradingProgress, $allowed)) {
159  $filter->setGradingProgress($gradingProgress);
160  }
161  }
162 
164  {
165  $period = $table->getFilterItemByPostVar('period');
166 
167  if ($period->getStart()) {
168  $filter->setStartDate($period->getStart());
169  }
170 
171  if ($period->getEnd()) {
172  $filter->setEndDate($period->getEnd());
173  }
174  }
175 
176  public function asyncUserAutocompleteCmd(): void
177  {
178  $auto = new ilCmiXapiUserAutocomplete($this->object->getId());
179  $auto->setSearchFields(array('login','firstname','lastname','email'));
180  $auto->setResultField('login');
181  $auto->enableFieldSearchableCheck(true);
182  $auto->setMoreLinkAvailable(true);
183 
184  //$auto->setLimit(ilUserAutoComplete::MAX_ENTRIES);
185  $term = '';
186  if ($this->dic->http()->wrapper()->query()->has('term')) {
187  $term = $this->dic->http()->wrapper()->query()->retrieve('term', $this->dic->refinery()->kindlyTo()->string());
188  } elseif ($this->dic->http()->wrapper()->post()->has('term')) {
189  $term = $this->dic->http()->wrapper()->post()->retrieve('term', $this->dic->refinery()->kindlyTo()->string());
190  }
191  if ($term != '') {
192  $result = json_decode($auto->getList(ilUtil::stripSlashes($term)), true);
193  echo json_encode($result);
194  }
195  exit();
196  }
197 
199  {
200  $cUser = null;
201  if (!$this->access->hasOutcomesAccess()) {
202  $cUser = $this->dic->user()->getId();
203  } else {
204  $cUser = $filter->getActor();
205  }
207  $this->object->getId(),
208  $cUser,
209  $filter->getActivityProgress(),
210  $filter->getGradingProgress(),
211  $filter->getStartDate(),
212  $filter->getEndDate()
213  );
214 
215  for ((int) $i = 0; $i < count($data); $i++) {
216  $usr = new ilObjUser((int) $data[$i]['usr_id']);
217  $data[$i]['actor'] = $usr->getFullname();
218  }
219  $sortNum = false;
220  if ($table->getOrderField() == 'score_given') {
221  $sortNum = true;
222  }
223 
225  $data,
226  $table->getOrderField(),
227  $table->getOrderDirection(),
228  $sortNum
229  );
230  $table->setData($data);
231  }
232 
234  {
235  $isMultiActorReport = $this->access->hasOutcomesAccess();
236 
237  $table = new ilLTIConsumerGradeSynchronizationTableGUI($this, 'show', $isMultiActorReport);
238  $table->setFilterCommand('applyFilter');
239  $table->setResetCommand('resetFilter');
240  return $table;
241  }
242 }
setData(array $a_data)
initTableData(ilLTIConsumerGradeSynchronizationTableGUI $table, ilLTIConsumerGradeSynchronizationFilter $filter)
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
initLimitingAndOrdering(ilLTIConsumerGradeSynchronizationFilter $filter, ilLTIConsumerGradeSynchronizationTableGUI $table)
static getInstance(ilObjLTIConsumer $object)
getFilterItemByPostVar(string $a_post_var)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
initPeriodFilter(ilLTIConsumerGradeSynchronizationFilter $filter, ilLTIConsumerGradeSynchronizationTableGUI $table)
static getUserIdByLogin(string $a_login)
initActorFilter(ilLTIConsumerGradeSynchronizationFilter $filter, ilLTIConsumerGradeSynchronizationTableGUI $table)
global $DIC
Definition: shib_login.php:22
initActivityProgressFilter(ilLTIConsumerGradeSynchronizationFilter $filter, ilLTIConsumerGradeSynchronizationTableGUI $table)
setSearchFields(array $a_fields)
Set searchable fields.
static getGradesForObject(int $objId, ?int $usrID=null, ?string $activity_progress=null, ?string $grading_progress=null, ?ilDateTime $startDate=null, ?ilDateTime $endDate=null)
initGradingProgressFilter(ilLTIConsumerGradeSynchronizationFilter $filter, ilLTIConsumerGradeSynchronizationTableGUI $table)
exit
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
determineOffsetAndOrder(bool $a_omit_offset=false)
static sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)