ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilMemberExport Class Reference

Class for generation of member export files. More...

+ Collaboration diagram for ilMemberExport:

Public Member Functions

 __construct ($a_ref_id, $a_type=self::EXPORT_CSV)
 Constructor.
 setFilename ($a_file)
 set filename
 getFilename ()
 get filename
 getRefId ()
 get ref_id
 getType ()
 get obj type
 getExportType ()
 get current export type
 getObjId ()
 Get obj id.
 create ()
 Create Export File.
 getCSVString ()
 toString method
 createExcel ()
 createCSV ()
 Create CSV File.

Data Fields

const EXPORT_CSV = 1
const EXPORT_EXCEL = 2

Protected Member Functions

 addCol ($a_value, $a_row, $a_col)
 Write on column.
 addRow ()
 Add row.
 write ()
 Write data.
 initMembers ()
 Init member object.

Private Member Functions

 fetchUsers ()
 Fetch all users that will be exported.
 readCourseData ($a_user_ids, $a_status= 'member')
 Read All User related course data.
 readCourseSpecificFieldsData ()
 Read course specific fields data.
 addCourseField ($a_usr_id, $a_field, $row, $col)
 fill course specific fields
 addUserDefinedField ($udf_data, $a_field, $row, $col)
 Add user defined fields.

Private Attributes

 $ref_id
 $obj_id
 $type
 $members
 $lng
 $settings
 $export_type = null
 $filename = null
 $user_ids = array()
 $user_course_data = array()
 $user_course_fields = array()
 $user_profile_data = array()
 $privacy

Detailed Description

Class for generation of member export files.

Author
Stefan Meyer meyer.nosp@m.@lei.nosp@m.fos.c.nosp@m.om
Version
$Id$

/

Definition at line 42 of file class.ilMemberExport.php.

Constructor & Destructor Documentation

ilMemberExport::__construct (   $a_ref_id,
  $a_type = self::EXPORT_CSV 
)

Constructor.

public

Definition at line 72 of file class.ilMemberExport.php.

References $lng, $obj_id, ilPrivacySettings\_getInstance(), ilObject\_lookupType(), ilMemberAgreement\_readByObjId(), and initMembers().

{
global $ilUser,$ilObjDataCache,$lng;
$this->lng = $lng;
$this->export_type = $a_type;
$this->ref_id = $a_ref_id;
$this->obj_id = $ilObjDataCache->lookupObjId($this->ref_id);
$this->type = ilObject::_lookupType($this->obj_id);
$this->initMembers();
$this->agreement = ilMemberAgreement::_readByObjId($this->obj_id);
$this->settings = new ilExportUserSettings($ilUser->getId(),$this->obj_id);
$this->privacy = ilPrivacySettings::_getInstance();
}

+ Here is the call graph for this function:

Member Function Documentation

ilMemberExport::addCol (   $a_value,
  $a_row,
  $a_col 
)
protected

Write on column.

Parameters
object$a_value
object$a_row
object$a_col
Returns

Definition at line 220 of file class.ilMemberExport.php.

References getExportType().

Referenced by addCourseField(), addUserDefinedField(), and write().

{
switch($this->getExportType())
{
case self::EXPORT_CSV:
$this->csv->addColumn($a_value);
break;
case self::EXPORT_EXCEL:
$this->worksheet->write($a_row,$a_col,$a_value);
break;
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilMemberExport::addCourseField (   $a_usr_id,
  $a_field,
  $row,
  $col 
)
private

fill course specific fields

private

Parameters
intusr_id
stringfield
Returns
bool

Definition at line 517 of file class.ilMemberExport.php.

References $row, ilCourseDefinedFieldDefinition\_getFields(), and addCol().

Referenced by write().

{
if(substr($a_field,0,4) != 'cdf_')
{
return false;
}
if((!$this->privacy->courseConfirmationRequired() and ilCourseDefinedFieldDefinition::_getFields($this->obj_id))
or $this->agreement[$a_usr_id]['accepted'])
{
$field_info = explode('_',$a_field);
$field_id = $field_info[1];
$value = $this->user_course_fields[$a_usr_id][$field_id];
#$this->csv->addColumn($value);
$this->addCol($value, $row, $col);
return true;
}
#$this->csv->addColumn('');
$this->addCol('', $row, $col);
return true;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilMemberExport::addRow ( )
protected

Add row.

Returns

Definition at line 238 of file class.ilMemberExport.php.

References getExportType().

Referenced by write().

{
switch($this->getExportType())
{
case self::EXPORT_CSV:
$this->csv->addRow();
break;
case self::EXPORT_EXCEL:
break;
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilMemberExport::addUserDefinedField (   $udf_data,
  $a_field,
  $row,
  $col 
)
private

Add user defined fields.

private

Parameters
objectuser defined data object
intfield

Definition at line 547 of file class.ilMemberExport.php.

References $row, and addCol().

Referenced by write().

{
if(substr($a_field,0,4) != 'udf_')
{
return false;
}
if(!$this->privacy->courseConfirmationRequired() or $this->agreement[$udf_data->getUserId()]['accepted'])
{
$field_info = explode('_',$a_field);
$field_id = $field_info[1];
$value = $udf_data->get('f_'.$field_id);
#$this->csv->addColumn($value);
$this->addCol($value, $row, $col);
return true;
}
#$this->csv->addColumn('');
$this->addCol('', $row, $col);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilMemberExport::create ( )

Create Export File.

public

Definition at line 152 of file class.ilMemberExport.php.

References createCSV(), createExcel(), fetchUsers(), and getExportType().

{
$this->fetchUsers();
// DONE: Switch different export types
switch($this->getExportType())
{
case self::EXPORT_CSV:
$this->createCSV();
break;
case self::EXPORT_EXCEL:
$this->createExcel();
break;
}
}

+ Here is the call graph for this function:

ilMemberExport::createCSV ( )

Create CSV File.

public

Definition at line 203 of file class.ilMemberExport.php.

References write().

Referenced by create().

{
include_once('Services/Utilities/classes/class.ilCSVWriter.php');
$this->csv = new ilCSVWriter();
$this->write();
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilMemberExport::createExcel ( )
Returns

Definition at line 186 of file class.ilMemberExport.php.

References getFilename(), and write().

Referenced by create().

{
include_once "./Services/Excel/classes/class.ilExcelUtils.php";
include_once "./Services/Excel/classes/class.ilExcelWriterAdapter.php";
$adapter = new ilExcelWriterAdapter($this->getFilename(), false);
$workbook = $adapter->getWorkbook();
$this->worksheet = $workbook->addWorksheet();
$this->write();
$workbook->close();
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilMemberExport::fetchUsers ( )
private

Fetch all users that will be exported.

private

Definition at line 427 of file class.ilMemberExport.php.

References $user_ids, ilObjUser\_readUsersProfileData(), ilUtil\_sortIds(), readCourseData(), and readCourseSpecificFieldsData().

Referenced by create().

{
if($this->settings->enabled('admin'))
{
$this->user_ids = $tmp_ids = $this->members->getAdmins();
$this->readCourseData($tmp_ids);
}
if($this->settings->enabled('tutor'))
{
$this->user_ids = array_merge($tmp_ids = $this->members->getTutors(),$this->user_ids);
$this->readCourseData($tmp_ids);
}
if($this->settings->enabled('member'))
{
$this->user_ids = array_merge($tmp_ids = $this->members->getMembers(),$this->user_ids);
$this->readCourseData($tmp_ids);
}
if($this->settings->enabled('subscribers'))
{
$this->user_ids = array_merge($tmp_ids = $this->members->getSubscribers(),$this->user_ids);
$this->readCourseData($tmp_ids,'subscriber');
}
if($this->settings->enabled('waiting_list'))
{
include_once('Modules/Course/classes/class.ilCourseWaitingList.php');
$waiting_list = new ilCourseWaitingList($this->obj_id);
$this->user_ids = array_merge($waiting_list->getUserIds(),$this->user_ids);
}
// Sort by lastname
$this->user_ids = ilUtil::_sortIds($this->user_ids,'usr_data','lastname','usr_id');
// Finally read user profile data
$this->user_profile_data = ilObjUser::_readUsersProfileData($this->user_ids);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilMemberExport::getCSVString ( )

toString method

public

Parameters

Definition at line 176 of file class.ilMemberExport.php.

{
return $this->csv->getCSVString();
}
ilMemberExport::getExportType ( )

get current export type

Returns

Definition at line 132 of file class.ilMemberExport.php.

References $export_type.

Referenced by addCol(), addRow(), and create().

{
}

+ Here is the caller graph for this function:

ilMemberExport::getFilename ( )

get filename

Returns

Definition at line 105 of file class.ilMemberExport.php.

References $filename.

Referenced by createExcel().

{
}

+ Here is the caller graph for this function:

ilMemberExport::getObjId ( )

Get obj id.

Returns

Definition at line 141 of file class.ilMemberExport.php.

References $obj_id.

Referenced by initMembers().

{
return $this->obj_id;
}

+ Here is the caller graph for this function:

ilMemberExport::getRefId ( )

get ref_id

Returns

Definition at line 114 of file class.ilMemberExport.php.

References $ref_id.

{
return $this->ref_id;
}
ilMemberExport::getType ( )

get obj type

Returns

Definition at line 123 of file class.ilMemberExport.php.

References $type.

Referenced by initMembers(), and readCourseData().

{
return $this->type;
}

+ Here is the caller graph for this function:

ilMemberExport::initMembers ( )
protected

Init member object.

Returns

Definition at line 570 of file class.ilMemberExport.php.

References ilGroupParticipants\_getInstanceByObjId(), ilCourseParticipants\_getInstanceByObjId(), getObjId(), and getType().

Referenced by __construct().

{
if($this->getType() == 'crs')
{
}
if($this->getType() == 'grp')
{
}
return true;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilMemberExport::readCourseData (   $a_user_ids,
  $a_status = 'member' 
)
private

Read All User related course data.

private

Definition at line 471 of file class.ilMemberExport.php.

References getType(), IL_CRS_ADMIN, IL_CRS_MEMBER, IL_CRS_TUTOR, IL_GRP_ADMIN, and IL_GRP_MEMBER.

Referenced by fetchUsers().

{
foreach($a_user_ids as $user_id)
{
// Read course related data
if($this->members->isAdmin($user_id))
{
$this->user_course_data[$user_id]['role'] = $this->getType() == 'crs' ? IL_CRS_ADMIN : IL_GRP_ADMIN;
}
elseif($this->members->isTutor($user_id))
{
$this->user_course_data[$user_id]['role'] = IL_CRS_TUTOR;
}
elseif($this->members->isMember($user_id))
{
$this->user_course_data[$user_id]['role'] = $this->getType() == 'crs' ? IL_CRS_MEMBER : IL_GRP_MEMBER;
}
else
{
$this->user_course_data[$user_id]['role'] = 'subscriber';
}
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilMemberExport::readCourseSpecificFieldsData ( )
private

Read course specific fields data.

private

Parameters

Definition at line 502 of file class.ilMemberExport.php.

References ilCourseUserData\_getValuesByObjId().

Referenced by fetchUsers().

{
include_once('Modules/Course/classes/Export/class.ilCourseUserData.php');
$this->user_course_fields = ilCourseUserData::_getValuesByObjId($this->obj_id);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilMemberExport::setFilename (   $a_file)

set filename

Parameters
object$a_file
Returns

Definition at line 96 of file class.ilMemberExport.php.

{
$this->filename = $a_file;
}
ilMemberExport::write ( )
protected

Write data.

Returns

Definition at line 255 of file class.ilMemberExport.php.

References $row, $usr_id, ilCourseDefinedFieldDefinition\_getFields(), ilUserDefinedFields\_getInstance(), ilCourseDefinedFieldDefinition\_lookupName(), addCol(), addCourseField(), addRow(), addUserDefinedField(), ilFormat\formatUnixTime(), IL_CRS_ADMIN, IL_CRS_MEMBER, IL_CRS_TUTOR, IL_GRP_ADMIN, and IL_GRP_MEMBER.

Referenced by createCSV(), and createExcel().

{
// Add header line
$row = 0;
$col = 0;
foreach($all_fields = $this->settings->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');
$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]));
}
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'])
{
#$this->csv->addColumn($this->lng->txt('crs_admin'));
$this->addCol($this->lng->txt('crs_admin'), $row, $col++);
break;
#$this->csv->addColumn($this->lng->txt('crs_tutor'));
$this->addCol($this->lng->txt('crs_tutor'), $row, $col++);
break;
#$this->csv->addColumn($this->lng->txt('crs_member'));
$this->addCol($this->lng->txt('crs_member'), $row, $col++);
break;
#$this->csv->addColumn($this->lng->txt('il_grp_admin'));
$this->addCol($this->lng->txt('il_grp_admin'), $row, $col++);
break;
#$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
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();
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Field Documentation

ilMemberExport::$export_type = null
private

Definition at line 57 of file class.ilMemberExport.php.

Referenced by getExportType().

ilMemberExport::$filename = null
private

Definition at line 58 of file class.ilMemberExport.php.

Referenced by getFilename().

ilMemberExport::$lng
private

Definition at line 53 of file class.ilMemberExport.php.

Referenced by __construct().

ilMemberExport::$members
private

Definition at line 51 of file class.ilMemberExport.php.

ilMemberExport::$obj_id
private

Definition at line 49 of file class.ilMemberExport.php.

Referenced by __construct(), and getObjId().

ilMemberExport::$privacy
private

Definition at line 64 of file class.ilMemberExport.php.

ilMemberExport::$ref_id
private

Definition at line 48 of file class.ilMemberExport.php.

Referenced by getRefId().

ilMemberExport::$settings
private

Definition at line 55 of file class.ilMemberExport.php.

ilMemberExport::$type
private

Definition at line 50 of file class.ilMemberExport.php.

Referenced by getType().

ilMemberExport::$user_course_data = array()
private

Definition at line 61 of file class.ilMemberExport.php.

ilMemberExport::$user_course_fields = array()
private

Definition at line 62 of file class.ilMemberExport.php.

ilMemberExport::$user_ids = array()
private

Definition at line 60 of file class.ilMemberExport.php.

Referenced by fetchUsers().

ilMemberExport::$user_profile_data = array()
private

Definition at line 63 of file class.ilMemberExport.php.

const ilMemberExport::EXPORT_CSV = 1

Definition at line 44 of file class.ilMemberExport.php.

const ilMemberExport::EXPORT_EXCEL = 2

Definition at line 45 of file class.ilMemberExport.php.

Referenced by ilMemberExportGUI\exportExcel().


The documentation for this class was generated from the following file: