ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
ilPRGMemberExport.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
27 {
28  public const EXPORT_CSV = 1;
29  public const EXPORT_EXCEL = 2;
30 
31  protected int $export_type;
32 
36  protected $writer;
37 
38  protected int $current_row = 0;
39 
40  public function __construct(
41  protected int $prg_ref_id,
42  protected int $prg_obj_id,
43  protected ilStudyProgrammeUserTable $prg_user_table,
44  protected ilUserFormSettings $settings,
45  protected ilLanguage $lng,
46  protected DataFactory $data_factory
47  ) {
48  }
49 
50  public function create(int $type, string $filename)
51  {
52  switch ($type) {
53  case self::EXPORT_CSV:
54  $this->writer = $this->createCSV();
55  $this->write();
56  break;
57  case self::EXPORT_EXCEL:
58  $this->writer = $this->createExcel();
59  $this->write();
60  $this->writer->writeToFile($filename);
61  break;
62  default:
63  throw new Exception('Unknown type for export' . $this->export_type);
64  }
65  }
66 
67  protected function createExcel(): ilExcel
68  {
69  $writer = new ilExcel();
70  $writer->addSheet($this->lng->txt("assignments"));
71  return $writer;
72  }
73 
74  protected function createCSV(): ilCSVWriter
75  {
76  return new ilCSVWriter();
77  }
78 
79  public function getCSVString(): ?string
80  {
81  if ($this->writer instanceof ilCSVWriter) {
82  return $this->writer->getCSVString();
83  }
84  return null;
85  }
86 
87  protected function write(): void
88  {
89  foreach ($this->prg_user_table->getColumns($this->prg_obj_id, true) as $user_table_field) {
90  [$f_id, $f_title] = $user_table_field;
91  if ($this->settings->enabled($f_id)) {
92  $fields[$f_id] = $f_title;
93  }
94  }
95  $this->writeRow(array_values($fields));
96 
97  $order = $this->data_factory->order('login', 'ASC');
98  $data = $this->prg_user_table->fetchData($this->prg_obj_id, null, $order);
99  $this->writeData(array_keys($fields), $data);
100  }
101 
106  protected function writeData(array $fields, array $data): void
107  {
108  foreach ($data as $usr_row) {
109  $row = [];
110  //$usr_data = ilObjUser::_lookupFields($usr_row->getUsrId());
111 
112  foreach ($fields as $f_id) {
113  switch ($f_id) {
114  case 'name':
115  $row[] = $usr_row->getFirstname() . $usr_row->getLastname();
116  break;
117  case 'login':
118  $row[] = $usr_row->getLogin();
119  break;
120  case 'prg_orgus':
121  $row[] = $usr_row->getOrgUs();
122  break;
123  case 'prg_status':
124  $row[] = $usr_row->getStatus();
125  break;
126  case 'prg_completion_date':
127  $row[] = $usr_row->getCompletionDate();
128  break;
129  case 'prg_completion_by':
130  $row[] = $usr_row->getCompletionBy();
131  break;
132  case 'points':
133  $row[] = $usr_row->getPointsReachable();
134  break;
135  case 'points_required':
136  $row[] = $usr_row->getPointsRequired();
137  break;
138  case 'points_current':
139  $row[] = $usr_row->getPointsCurrent();
140  break;
141  case 'prg_custom_plan':
142  $row[] = $usr_row->getCustomPlan();
143  break;
144  case 'prg_belongs_to':
145  $row[] = $usr_row->getBelongsTo();
146  break;
147  case 'prg_assign_date':
148  $row[] = $usr_row->getAssignmentDate();
149  break;
150  case 'prg_assigned_by':
151  $row[] = $usr_row->getAssignmentBy();
152  break;
153  case 'prg_deadline':
154  $row[] = $usr_row->getDeadline();
155  break;
156  case 'prg_expiry_date':
157  $row[] = $usr_row->getExpiryDate();
158  break;
159  case 'prg_validity':
160  $row[] = $usr_row->getValidity();
161  break;
162  case 'active':
163  $row[] = $usr_row->getUserActive();
164  break;
165  default:
166  $row[] = $usr_row->getUserData($f_id);
167  }
168  }
169 
170  $this->writeRow($row);
171  }
172  }
173 
177  protected function writeRow(array $values)
178  {
179  if ($this->writer instanceof ilCSVWriter) {
180  $this->writeCSVRow($values);
181  }
182  if ($this->writer instanceof ilExcel) {
183  $this->writeExcelRow($values);
184  }
185  }
186 
187  protected function writeCSVRow(array $values)
188  {
189  foreach ($values as $val) {
190  $this->writer->addColumn($val);
191  }
192  $this->writer->addRow();
193  }
194 
195  protected function writeExcelRow(array $values)
196  {
197  $this->current_row++;
198  $current_col = 0;
199  foreach ($values as $val) {
200  $this->writer->setCell($this->current_row, $current_col, $val);
201  $current_col++;
202  }
203  }
204 }
writeData(array $fields, array $data)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
writeRow(array $values)
writeCSVRow(array $values)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
create(int $type, string $filename)
__construct(protected int $prg_ref_id, protected int $prg_obj_id, protected ilStudyProgrammeUserTable $prg_user_table, protected ilUserFormSettings $settings, protected ilLanguage $lng, protected DataFactory $data_factory)
export assignments of PRG
$filename
Definition: buildRTE.php:78
ilStudyProgrammeUserTable provides a flattened list of progresses at a programme-node.
global $lng
Definition: privfeed.php:31
writeExcelRow(array $values)