/**
  * Write data
  * @return 
  */
 protected function write()
 {
     // Add header line
     $row = 0;
     $col = 0;
     foreach ($all_fields = $this->getOrderedExportableFields() as $field) {
         switch ($field) {
             case 'role':
                 #$this->csv->addColumn($this->lng->txt($this->getType().'_role_status'));
                 $this->addCol($this->lng->txt($this->getType() . '_role_status'), $row, $col++);
                 break;
             case 'agreement':
                 #$this->csv->addColumn($this->lng->txt('ps_agreement_accepted'));
                 $this->addCol($this->lng->txt('ps_agreement_accepted'), $row, $col++);
                 break;
             default:
                 if (substr($field, 0, 4) == 'udf_') {
                     $field_id = explode('_', $field);
                     include_once 'Services/User/classes/class.ilUserDefinedFields.php';
                     $udf = ilUserDefinedFields::_getInstance();
                     $def = $udf->getDefinition($field_id[1]);
                     #$this->csv->addColumn($def['field_name']);
                     $this->addCol($def['field_name'], $row, $col++);
                 } elseif (substr($field, 0, 4) == 'cdf_') {
                     $field_id = explode('_', $field);
                     #$this->csv->addColumn(ilCourseDefinedFieldDefinition::_lookupName($field_id[1]));
                     $this->addCol(ilCourseDefinedFieldDefinition::_lookupName($field_id[1]), $row, $col++);
                 } else {
                     #$this->csv->addColumn($this->lng->txt($field));
                     $this->addCol($this->lng->txt($field), $row, $col++);
                 }
                 break;
         }
     }
     #$this->csv->addRow();
     $this->addRow();
     // Add user data
     foreach ($this->user_ids as $usr_id) {
         $row++;
         $col = 0;
         $udf_data = new ilUserDefinedData($usr_id);
         foreach ($all_fields as $field) {
             // Handle course defined fields
             if ($this->addUserDefinedField($udf_data, $field, $row, $col)) {
                 $col++;
                 continue;
             }
             if ($this->addCourseField($usr_id, $field, $row, $col)) {
                 $col++;
                 continue;
             }
             switch ($field) {
                 case 'role':
                     switch ($this->user_course_data[$usr_id]['role']) {
                         case IL_CRS_ADMIN:
                             #$this->csv->addColumn($this->lng->txt('crs_admin'));
                             $this->addCol($this->lng->txt('crs_admin'), $row, $col++);
                             break;
                         case IL_CRS_TUTOR:
                             #$this->csv->addColumn($this->lng->txt('crs_tutor'));
                             $this->addCol($this->lng->txt('crs_tutor'), $row, $col++);
                             break;
                         case IL_CRS_MEMBER:
                             #$this->csv->addColumn($this->lng->txt('crs_member'));
                             $this->addCol($this->lng->txt('crs_member'), $row, $col++);
                             break;
                         case IL_GRP_ADMIN:
                             #$this->csv->addColumn($this->lng->txt('il_grp_admin'));
                             $this->addCol($this->lng->txt('il_grp_admin'), $row, $col++);
                             break;
                         case IL_GRP_MEMBER:
                             #$this->csv->addColumn($this->lng->txt('il_grp_member'));
                             $this->addCol($this->lng->txt('il_grp_member'), $row, $col++);
                             break;
                         case 'subscriber':
                             #$this->csv->addColumn($this->lng->txt($this->getType().'_subscriber'));
                             $this->addCol($this->lng->txt($this->getType() . '_subscriber'), $row, $col++);
                             break;
                         default:
                             #$this->csv->addColumn($this->lng->txt('crs_waiting_list'));
                             $this->addCol($this->lng->txt('crs_waiting_list'), $row, $col++);
                             break;
                     }
                     break;
                 case 'agreement':
                     if (isset($this->agreement[$usr_id])) {
                         if ($this->agreement[$usr_id]['accepted']) {
                             #$this->csv->addColumn(ilFormat::formatUnixTime($this->agreement[$usr_id]['acceptance_time'],true));
                             $this->addCol(ilFormat::formatUnixTime($this->agreement[$usr_id]['acceptance_time'], true), $row, $col++);
                         } else {
                             #$this->csv->addColumn($this->lng->txt('ps_not_accepted'));
                             $this->addCol($this->lng->txt('ps_not_accepted'), $row, $col++);
                         }
                     } else {
                         #$this->csv->addColumn($this->lng->txt('ps_not_accepted'));
                         $this->addCol($this->lng->txt('ps_not_accepted'), $row, $col++);
                     }
                     break;
                     // These fields are always enabled
                 // These fields are always enabled
                 case 'username':
                     #$this->csv->addColumn($this->user_profile_data[$usr_id]['login']);
                     $this->addCol($this->user_profile_data[$usr_id]['login'], $row, $col++);
                     break;
                 case 'firstname':
                 case 'lastname':
                     #$this->csv->addColumn($this->user_profile_data[$usr_id][$field]);
                     $this->addCol($this->user_profile_data[$usr_id][$field], $row, $col++);
                     break;
                 default:
                     // Check aggreement
                     if (!$this->privacy->courseConfirmationRequired() and !ilCourseDefinedFieldDefinition::_getFields($this->obj_id) or $this->agreement[$usr_id]['accepted']) {
                         #$this->csv->addColumn($this->user_profile_data[$usr_id][$field]);
                         $this->addCol($this->user_profile_data[$usr_id][$field], $row, $col++);
                     } else {
                         #$this->csv->addColumn('');
                         $this->addCol('', $row, $col++);
                     }
                     break;
             }
         }
         #$this->csv->addRow();
         $this->addRow();
     }
 }
Ejemplo n.º 2
0
 /**
  * Write data
  * @return 
  */
 protected function write()
 {
     // Add header line
     $row = 0;
     $col = 0;
     foreach ($all_fields = $this->getOrderedExportableFields() as $field) {
         switch ($field) {
             case 'role':
                 #$this->csv->addColumn($this->lng->txt($this->getType().'_role_status'));
                 $this->addCol($this->lng->txt($this->getType() . '_role_status'), $row, $col++);
                 break;
             case 'agreement':
                 #$this->csv->addColumn($this->lng->txt('ps_agreement_accepted'));
                 $this->addCol($this->lng->txt('ps_agreement_accepted'), $row, $col++);
                 break;
             case 'consultation_hour':
                 $this->lng->loadLanguageModule('dateplaner');
                 $this->addCol($this->lng->txt('cal_ch_field_ch'), $row, $col++);
                 break;
             default:
                 if (substr($field, 0, 4) == 'udf_') {
                     $field_id = explode('_', $field);
                     include_once 'Services/User/classes/class.ilUserDefinedFields.php';
                     $udf = ilUserDefinedFields::_getInstance();
                     $def = $udf->getDefinition($field_id[1]);
                     #$this->csv->addColumn($def['field_name']);
                     $this->addCol($def['field_name'], $row, $col++);
                 } elseif (substr($field, 0, 4) == 'cdf_') {
                     $field_id = explode('_', $field);
                     #$this->csv->addColumn(ilCourseDefinedFieldDefinition::_lookupName($field_id[1]));
                     $this->addCol(ilCourseDefinedFieldDefinition::_lookupName($field_id[1]), $row, $col++);
                 } else {
                     #$this->csv->addColumn($this->lng->txt($field));
                     $this->addCol($this->lng->txt($field), $row, $col++);
                 }
                 break;
         }
     }
     #$this->csv->addRow();
     $this->addRow();
     // Add user data
     foreach ($this->user_ids as $usr_id) {
         $row++;
         $col = 0;
         $udf_data = new ilUserDefinedData($usr_id);
         foreach ($all_fields as $field) {
             // Handle course defined fields
             if ($this->addUserDefinedField($udf_data, $field, $row, $col)) {
                 $col++;
                 continue;
             }
             if ($this->addCourseField($usr_id, $field, $row, $col)) {
                 $col++;
                 continue;
             }
             switch ($field) {
                 case 'role':
                     switch ($this->user_course_data[$usr_id]['role']) {
                         case IL_CRS_ADMIN:
                             #$this->csv->addColumn($this->lng->txt('crs_admin'));
                             $this->addCol($this->lng->txt('crs_admin'), $row, $col++);
                             break;
                         case IL_CRS_TUTOR:
                             #$this->csv->addColumn($this->lng->txt('crs_tutor'));
                             $this->addCol($this->lng->txt('crs_tutor'), $row, $col++);
                             break;
                         case IL_CRS_MEMBER:
                             #$this->csv->addColumn($this->lng->txt('crs_member'));
                             $this->addCol($this->lng->txt('crs_member'), $row, $col++);
                             break;
                         case IL_GRP_ADMIN:
                             #$this->csv->addColumn($this->lng->txt('il_grp_admin'));
                             $this->addCol($this->lng->txt('il_grp_admin'), $row, $col++);
                             break;
                         case IL_GRP_MEMBER:
                             #$this->csv->addColumn($this->lng->txt('il_grp_member'));
                             $this->addCol($this->lng->txt('il_grp_member'), $row, $col++);
                             break;
                         case 'subscriber':
                             #$this->csv->addColumn($this->lng->txt($this->getType().'_subscriber'));
                             $this->addCol($this->lng->txt($this->getType() . '_subscriber'), $row, $col++);
                             break;
                         default:
                             #$this->csv->addColumn($this->lng->txt('crs_waiting_list'));
                             $this->addCol($this->lng->txt('crs_waiting_list'), $row, $col++);
                             break;
                     }
                     break;
                 case 'agreement':
                     if (isset($this->agreement[$usr_id])) {
                         if ($this->agreement[$usr_id]['accepted']) {
                             #$this->csv->addColumn(ilFormat::formatUnixTime($this->agreement[$usr_id]['acceptance_time'],true));
                             $this->addCol(ilFormat::formatUnixTime($this->agreement[$usr_id]['acceptance_time'], true), $row, $col++);
                         } else {
                             #$this->csv->addColumn($this->lng->txt('ps_not_accepted'));
                             $this->addCol($this->lng->txt('ps_not_accepted'), $row, $col++);
                         }
                     } else {
                         #$this->csv->addColumn($this->lng->txt('ps_not_accepted'));
                         $this->addCol($this->lng->txt('ps_not_accepted'), $row, $col++);
                     }
                     break;
                     // These fields are always enabled
                 // These fields are always enabled
                 case 'username':
                     #$this->csv->addColumn($this->user_profile_data[$usr_id]['login']);
                     $this->addCol($this->user_profile_data[$usr_id]['login'], $row, $col++);
                     break;
                 case 'firstname':
                 case 'lastname':
                     #$this->csv->addColumn($this->user_profile_data[$usr_id][$field]);
                     $this->addCol($this->user_profile_data[$usr_id][$field], $row, $col++);
                     break;
                 case 'consultation_hour':
                     include_once './Services/Booking/classes/class.ilBookingEntry.php';
                     $bookings = ilBookingEntry::lookupManagedBookingsForObject($this->obj_id, $GLOBALS['ilUser']->getId());
                     $uts = array();
                     foreach ((array) $bookings[$usr_id] as $ut) {
                         ilDatePresentation::setUseRelativeDates(false);
                         $tmp = ilDatePresentation::formatPeriod(new ilDateTime($ut['dt'], IL_CAL_UNIX), new ilDateTime($ut['dtend'], IL_CAL_UNIX));
                         if (strlen($ut['explanation'])) {
                             $tmp .= ' ' . $ut['explanation'];
                         }
                         $uts[] = $tmp;
                     }
                     $uts_str = implode(',', $uts);
                     $this->addCol($uts_str, $row, $col++);
                     break;
                 default:
                     // Check aggreement
                     if (!$this->privacy->courseConfirmationRequired() and !ilCourseDefinedFieldDefinition::_getFields($this->obj_id) or $this->agreement[$usr_id]['accepted']) {
                         #$this->csv->addColumn($this->user_profile_data[$usr_id][$field]);
                         $this->addCol($this->user_profile_data[$usr_id][$field], $row, $col++);
                     } else {
                         #$this->csv->addColumn('');
                         $this->addCol('', $row, $col++);
                     }
                     break;
             }
         }
         #$this->csv->addRow();
         $this->addRow();
     }
 }