ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
ilPRGAssignmentFilter.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 {
23  protected ilLanguage $lng;
24  protected array $values = [];
25 
26  public function __construct(
27  ilLanguage $lng
28  ) {
29  $this->lng = $lng;
30  }
31 
32  public function withValues(array $values): self
33  {
34  $clone = clone $this;
35  $clone->values = $values;
36  return $clone;
37  }
38 
39  public function toConditions(): array
40  {
41  $conditions = [];
42  foreach ($this->getCleanedValues() as $field => $value) {
43  switch ($field) {
44  case 'status':
45  if ($value) {
46  $conditions[] = ilPRGAssignmentDBRepository::PROGRESS_FIELD_STATUS . '=' . $value;
47  }
48  break;
49  case 'prg_status_hide_irrelevant':
51  break;
52  case 'name':
53  $conditions[] = '('
54  . 'memberdata.firstname LIKE \'%' . $value . '%\' OR' . PHP_EOL
55  . 'memberdata.lastname LIKE \'%' . $value . '%\' OR' . PHP_EOL
56  . 'memberdata.login LIKE \'%' . $value . '%\'' . PHP_EOL
57  . ')';
58  break;
59  case 'invalidated':
62  }
65  $conditions[] = '('
67  . ' OR '
69  . ')';
70  }
71  break;
72 
73  case 'usr_active':
74  if ((int) $value === ilStudyProgrammeUserTable::OPTION_USR_ACTIVE) {
75  $conditions[] = 'memberdata.active = 1';
76  }
78  $conditions[] = 'memberdata.active = 0';
79  }
80  break;
81  case 'vq_date':
82  list($from, $to) = array_values($value);
83  if ($from) {
84  $from = $from->get(IL_CAL_DATE);
85  $conditions[] = 'vq_date >= \'' . $from . ' 00:00:00\'';
86  }
87  if ($to) {
88  $to = $to->get(IL_CAL_DATE);
89  $conditions[] = 'vq_date <= \'' . $to . ' 23:59:59\'';
90  }
91  break;
92  case 'deadline':
93  list($from, $to) = array_values($value);
94  if ($to || $from) {
95  $conditions[] = 'deadline IS NOT NULL';
97  . ' NOT IN (' .
100  . ')';
101  }
102  if ($from) {
103  $from = $from->get(IL_CAL_DATE);
104  $conditions[] = 'deadline >= \'' . $from . '\'';
105  }
106  if ($to) {
107  $to = $to->get(IL_CAL_DATE);
108  $conditions[] = 'deadline <= \'' . $to . '\'';
109  }
110  break;
111  default:
112  throw new ilException("missing field in filter (to condition): " . $field, 1);
113  }
114  }
115  return $conditions;
116  }
117 
118  protected function getCleanedValues(): array
119  {
120  $ret = [];
121  foreach ($this->getItemConfig() as list($id, $type, $options)) {
122  if (array_key_exists($id, $this->values)) {
123  if ($type === ilTable2GUI::FILTER_SELECT
124  && (
126  || $this->values[$id] === false
127  )
128  ) {
129  continue;
130  }
131  if ($type === ilTable2GUI::FILTER_TEXT
132  && $this->values[$id] == ''
133  ) {
134  continue;
135  }
136  if ($type === ilTable2GUI::FILTER_CHECKBOX
137  && ($this->values[$id] == false || is_null($this->values[$id]))
138  ) {
139  continue;
140  }
141  if ($type === ilTable2GUI::FILTER_DATE_RANGE
142  && $this->values[$id]['from'] == []
143  && $this->values[$id]['to'] == []
144  ) {
145  continue;
146  }
147  $ret[$id] = $this->values[$id];
148  }
149  };
150  return $ret;
151  }
152 
156  public function getItemConfig(): array
157  {
158  $items = [];
159 
160  $items[] = [
163  [
164  ilStudyProgrammeUserTable::OPTION_ALL => $this->lng->txt("all"),
165  ilStudyProgrammeUserTable::VALIDITY_OPTION_VALID => $this->lng->txt("prg_still_valid"),
166  ilStudyProgrammeUserTable::VALIDITY_OPTION_INVALID => $this->lng->txt("prg_not_valid")
167  ],
168  $this->lng->txt('prg_validity')
169  ];
170 
171  $items[] = [
174  [
175  ilStudyProgrammeUserTable::OPTION_ALL => $this->lng->txt("all"),
176  ilPRGProgress::STATUS_IN_PROGRESS => $this->lng->txt("prg_status_in_progress"),
177  ilPRGProgress::STATUS_COMPLETED => $this->lng->txt("prg_status_completed"),
178  ilPRGProgress::STATUS_ACCREDITED => $this->lng->txt("prg_status_accredited"),
179  ilPRGProgress::STATUS_NOT_RELEVANT => $this->lng->txt("prg_status_not_relevant"),
180  ilPRGProgress::STATUS_FAILED => $this->lng->txt("prg_status_failed")
181  ],
182  ''
183  ];
184 
185  $items[] = ['prg_status_hide_irrelevant', ilTable2GUI::FILTER_CHECKBOX, null, ''];
186 
187  $items[] = [
188  'usr_active',
190  [
191  ilStudyProgrammeUserTable::OPTION_ALL => $this->lng->txt("all"),
192  ilStudyProgrammeUserTable::OPTION_USR_ACTIVE => $this->lng->txt("active_only"),
193  ilStudyProgrammeUserTable::OPTION_USR_INACTIVE => $this->lng->txt("inactive_only")
194  ],
195  ''
196  ];
197 
198  $items[] = ['name', ilTable2GUI::FILTER_TEXT, null, ''];
199 
200  $items[] = [
203  null,
204  ''
205  ];
206 
207  $items[] = [
210  null,
211  ''
212  ];
213 
214  return $items;
215  }
216 }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
const IL_CAL_DATE
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23