19declare(strict_types=1);
62 public function __construct(
int $a_ref_id,
int $a_type = self::EXPORT_CSV)
66 $ilObjDataCache =
$DIC[
'ilObjDataCache'];
68 $this->
lng = $DIC->language();
69 $this->tree =
$DIC->repositoryTree();
70 $this->
access = $DIC->access();
71 $this->
profile = $DIC[
'user']->getProfile();
73 $this->export_type = $a_type;
74 $this->ref_id = $a_ref_id;
75 $this->obj_id = $ilObjDataCache->lookupObjId($this->ref_id);
92 return $this->
access->filterUserIdsByRbacOrPositionOfCurrentUser(
102 $this->filename = $a_file;
147 return $this->csv->getCSVString();
154 $this->worksheet =
new ilExcel();
155 $this->worksheet->addSheet($this->
lng->txt(
"members"));
158 $this->worksheet->writeToFile($this->
getFilename());
170 protected function addCol(
string $a_value,
int $a_row,
int $a_col): void
174 $this->csv->addColumn($a_value);
178 $this->worksheet->setCell($a_row + 1, $a_col, $a_value);
187 $this->csv->addRow();
198 $field_info->sortExportFields();
203 $fields[] =
'agreement';
206 foreach ($field_info->getExportableFields() as $field) {
207 if ($this->
settings->enabled($field)) {
212 foreach ($this->
profile->getVisibleFields(Context::Course) as $field) {
213 if ($this->
settings->enabled(
'udf_' . $field->getIdentifier())) {
214 $fields[] =
'udf_' . $field->getIdentifier();
220 if ($this->
settings->enabled(
'cdf_' . $field_obj->getId())) {
221 $fields[] =
'cdf_' . $field_obj->getId();
224 if ($this->
settings->enabled(
'group_memberships')) {
225 $fields[] =
'crs_members_groups';
238 $this->
addCol($this->
lng->txt($this->getType() .
'_role_status'), $row, $col++);
241 $this->
addCol($this->
lng->txt(
'ps_agreement_accepted'), $row, $col++);
243 case 'consultation_hour':
244 $this->
lng->loadLanguageModule(
'dateplaner');
245 $this->
addCol($this->
lng->txt(
'cal_ch_field_ch'), $row, $col++);
249 $this->
addCol($this->
lng->txt(
'org_units'), $row, $col++);
253 if (strpos($field,
'udf_') === 0) {
254 $field_id = explode(
'_', $field);
255 $def = $this->
profile->getFieldByIdentifier($field_id[1]);
256 #$this->csv->addColumn($def['field_name']);
257 $this->
addCol($def->getLabel($this->lng), $row, $col++);
258 } elseif (strpos($field,
'cdf_') === 0) {
259 $field_id = explode(
'_', $field);
260 #$this->csv->addColumn(ilCourseDefinedFieldDefinition::_lookupName($field_id[1]));
262 } elseif ($field ===
"username") {
263 $this->
addCol($this->
lng->txt(
"login"), $row, $col++);
265 #$this->csv->addColumn($this->lng->txt($field));
266 $this->
addCol($this->
lng->txt($field), $row, $col++);
273 foreach ($this->user_ids as $usr_id) {
276 $usr_id = (
int) $usr_id;
278 $udf_data = $this->
profile->getDataFor($usr_id);
279 foreach ($all_fields as $field) {
293 switch ($this->user_course_data[$usr_id][
'role'] ??
'') {
295 $this->
addCol($this->
lng->txt(
'crs_admin'), $row, $col++);
299 $this->
addCol($this->
lng->txt(
'crs_tutor'), $row, $col++);
303 $this->
addCol($this->
lng->txt(
'crs_member'), $row, $col++);
307 $this->
addCol($this->
lng->txt(
'il_grp_admin'), $row, $col++);
311 $this->
addCol($this->
lng->txt(
'il_grp_member'), $row, $col++);
315 $this->
addCol($this->
lng->txt($this->getType() .
'_subscriber'), $row, $col++);
319 $this->
addCol($this->
lng->txt(
'crs_waiting_list'), $row, $col++);
325 if (isset($this->agreement[$usr_id])) {
326 if ($this->agreement[$usr_id][
'accepted']) {
330 $this->
addCol($this->
lng->txt(
'ps_not_accepted'), $row, $col++);
333 $this->
addCol($this->
lng->txt(
'ps_not_accepted'), $row, $col++);
339 $this->
addCol($this->user_profile_data[$usr_id][
'login'], $row, $col++);
344 $this->
addCol($this->user_profile_data[$usr_id][$field], $row, $col++);
347 case 'consultation_hour':
354 foreach ((array) $bookings[$usr_id] as $ut) {
360 if (strlen($ut[
'explanation'])) {
361 $tmp .=
' ' . $ut[
'explanation'];
365 $uts_str = implode(
',', $uts);
366 $this->
addCol($uts_str, $row, $col++);
368 case 'crs_members_groups':
371 foreach (array_keys($this->groups) as $grp_ref) {
372 if (in_array($usr_id, $this->groups_participants[$grp_ref])
373 && $this->groups_rights[$grp_ref]) {
374 $groups[] = $this->groups[$grp_ref];
387 !$this->privacy->courseConfirmationRequired() or
388 (isset($this->agreement[$usr_id][
'accepted']) &&
389 $this->agreement[$usr_id][
'accepted'])
391 #$this->csv->addColumn($this->user_profile_data[$usr_id][$field]);
392 $this->
addCol($this->user_profile_data[$usr_id][$field] ??
'', $row, $col++);
394 #$this->csv->addColumn('');
395 $this->
addCol(
'', $row, $col++);
408 if ($this->
settings->enabled(
'admin')) {
409 $this->user_ids = $tmp_ids = $this->members->getAdmins();
412 if ($this->
settings->enabled(
'tutor')) {
413 $this->user_ids = array_merge($tmp_ids = $this->members->getTutors(), $this->user_ids);
416 if ($this->
settings->enabled(
'member')) {
417 $this->user_ids = array_merge($tmp_ids = $this->members->getMembers(), $this->user_ids);
420 if ($this->
settings->enabled(
'subscribers')) {
421 $this->user_ids = array_merge($tmp_ids = $this->members->getSubscribers(), $this->user_ids);
424 if ($this->
settings->enabled(
'waiting_list')) {
426 $this->user_ids = array_merge($waiting_list->getUserIds(), $this->user_ids);
428 $this->user_ids = $this->
filterUsers($this->user_ids);
431 $this->user_ids =
ilUtil::_sortIds($this->user_ids,
'usr_data',
'lastname',
'usr_id');
446 if ($this->members->isAdmin(
$user_id)) {
448 } elseif ($this->members->isTutor(
$user_id)) {
450 } elseif ($this->members->isMember(
$user_id)) {
453 $this->user_course_data[
$user_id][
'role'] =
'subscriber';
466 private function addCourseField(
int $a_usr_id,
string $a_field,
int $row,
int $col): bool
468 if (strpos($a_field,
'cdf_') !== 0) {
472 !$this->privacy->courseConfirmationRequired() ||
473 ($this->agreement[$a_usr_id][
'accepted'] ??
false)
475 $field_info = explode(
'_', $a_field);
476 $field_id = $field_info[1] ?? 0;
478 if (isset($this->user_course_fields[$a_usr_id][$field_id])) {
479 $value = $this->user_course_fields[$a_usr_id][$field_id];
481 $this->
addCol((
string) $value, $row, $col);
484 #$this->csv->addColumn('');
485 $this->
addCol(
'', $row, $col);
494 if (strpos($a_field,
'udf_') !== 0) {
499 !$this->privacy->courseConfirmationRequired() ||
500 (isset($this->agreement[$udf_data->getId()][
'accepted']) &&
501 $this->agreement[$udf_data->getId()][
'accepted'])
503 $field_info = explode(
'_', $a_field);
504 $field_id = $field_info[1];
505 $value = $udf_data->getAdditionalFieldByIdentifier($field_id);
506 $this->
addCol($value, $row, $col);
510 $this->
addCol(
'', $row, $col);
519 if ($this->
getType() ===
'crs') {
522 if ($this->
getType() ===
'grp') {
529 $parent_node = $this->tree->getNodeData($this->ref_id);
530 $groups = $this->tree->getSubTree($parent_node,
true, [
'grp']);
532 $this->groups_rights = [];
533 foreach (
$groups as $idx => $group_data) {
536 $group_data[
"parent"] != $this->ref_id &&
537 $this->tree->checkForParentType((
int) $group_data[
"ref_id"],
"grp",
true)
541 $this->groups[$group_data[
"ref_id"]] = $group_data[
"title"];
543 $this->groups_rights[$group_data[
"ref_id"]] =
544 $this->
access->checkAccess(
"write",
"", (
int) $group_data[
"ref_id"]);
546 $this->groups_participants[$group_data[
"ref_id"]] = $gobj->getParticipants();
static lookupManagedBookingsForObject(int $a_obj_id, int $a_usr_id)
Lookup bookings for own and managed consultation hours of an object.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _getFields(int $a_container_id, $a_sort=self::IL_CDF_SORT_NAME)
Get all fields of a container.
static _lookupName(int $a_field_id)
static _getInstanceByObjId(int $a_obj_id)
static _getValuesByObjId(int $a_obj_id)
static setUseRelativeDates(bool $a_status)
set use relative dates
static formatPeriod(ilDateTime $start, ilDateTime $end, bool $a_skip_starting_day=false, ?ilObjUser $user=null)
Format a period of two dates Shows: 14.
@classDescription Date and time handling
static _getInstanceByType(string $a_type)
Get Singleton Instance.
static _getInstanceByObjId(int $a_obj_id)
Get singleton instance.
static _readByObjId(int $a_obj_id)
Read user data by object id.
Class for generation of member export files.
ilUserFormSettings $settings
__construct(int $a_ref_id, int $a_type=self::EXPORT_CSV)
setFilename(string $a_file)
initMembers()
Init member object.
addCourseField(int $a_usr_id, string $a_field, int $row, int $col)
Fill course specific fields.
filterUsers(array $a_usr_ids)
array $groups_participants
addCol(string $a_value, int $a_row, int $a_col)
Write one column.
readCourseData(array $a_user_ids)
Read All User related course data.
addUserDefinedField(ProfileData $udf_data, string $a_field, int $row, int $col)
Add user defined fields.
readCourseSpecificFieldsData()
array $user_course_fields
ilPrivacySettings $privacy
getOrderedExportableFields()
static lookupOrgUnitsRepresentation(int $a_usr_id)
static _readUsersProfileData(array $a_user_ids)
static _lookupType(int $id, bool $reference=false)
Base class for course and group participants.
Singleton class that stores all privacy settings.
courseConfirmationRequired()
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
static _sortIds(array $a_ids, string $a_table, string $a_field, string $a_id_name)
Function that sorts ids by a given table field using WHERE IN E.g: __sort(array(6,...
Interface ilAccessHandler This interface combines all available interfaces which can be called via gl...