ILIAS  release_8 Revision v8.24
ilAdvancedMDRecordExportFiles Class Reference
+ Collaboration diagram for ilAdvancedMDRecordExportFiles:

Public Member Functions

 __construct (int $a_obj_id=null)
 
 readFilesInfo ()
 Read files info @access public. More...
 
 getFiles ()
 Get files. More...
 
 create (string $a_xml)
 Create new export file from xml string. More...
 
 deleteByFileId (int $a_timest)
 
 getAbsolutePathByFileId (int $a_file_basename)
 

Protected Attributes

string $export_dir = ''
 

Private Member Functions

 init ()
 init export directory @access private More...
 

Detailed Description

Author
Stefan Meyer meyer.nosp@m.@lei.nosp@m.fos.c.nosp@m.om
Todo:
use logger and filestorage

Definition at line 31 of file class.ilAdvancedMDRecordExportFiles.php.

Constructor & Destructor Documentation

◆ __construct()

ilAdvancedMDRecordExportFiles::__construct ( int  $a_obj_id = null)

Definition at line 35 of file class.ilAdvancedMDRecordExportFiles.php.

36 {
37 $this->export_dir = ilFileUtils::getDataDir() . '/ilAdvancedMetaData/export';
38 if ($a_obj_id) {
39 $this->export_dir .= "_" . $a_obj_id;
40 }
41 $this->init();
42 }
init()
init export directory @access private
static getDataDir()
get data directory (outside webspace)

References ilFileUtils\getDataDir(), and init().

+ Here is the call graph for this function:

Member Function Documentation

◆ create()

ilAdvancedMDRecordExportFiles::create ( string  $a_xml)

Create new export file from xml string.

Definition at line 94 of file class.ilAdvancedMDRecordExportFiles.php.

94 : void
95 {
96 global $DIC;
97
98 $ilLog = $DIC['ilLog'];
99
100 if (!$fp = fopen($this->export_dir . '/' . time() . '.xml', 'w+')) {
101 $ilLog->write(__METHOD__ . ': Cannot open file ' . $this->export_dir . '/' . time() . '.xml');
102 throw new ilException('Cannot write export file.');
103 }
104
105 fwrite($fp, $a_xml);
106 fclose($fp);
107 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28

References $DIC.

◆ deleteByFileId()

ilAdvancedMDRecordExportFiles::deleteByFileId ( int  $a_timest)

Definition at line 109 of file class.ilAdvancedMDRecordExportFiles.php.

109 : bool
110 {
111 global $DIC;
112
113 $ilLog = $DIC['ilLog'];
114
115 if (!unlink($this->export_dir . '/' . $a_timest . '.xml')) {
116 $ilLog->write(__METHOD__ . ': Cannot delete file ' . $this->export_dir . '/' . $a_timest . '.xml');
117 return false;
118 }
119 return true;
120 }

References $DIC.

◆ getAbsolutePathByFileId()

ilAdvancedMDRecordExportFiles::getAbsolutePathByFileId ( int  $a_file_basename)

Definition at line 122 of file class.ilAdvancedMDRecordExportFiles.php.

122 : string
123 {
124 global $DIC;
125
126 $ilLog = $DIC['ilLog'];
127
128 $a_file_basename = (string) $a_file_basename;
129 if (!file_exists($this->export_dir . '/' . $a_file_basename . '.xml')) {
130 $ilLog->write(__METHOD__ . ': Cannot find file ' . $this->export_dir . '/' . $a_file_basename . '.xml');
131 return '';
132 }
133 return $this->export_dir . '/' . $a_file_basename . '.xml';
134 }

References $DIC.

◆ getFiles()

ilAdvancedMDRecordExportFiles::getFiles ( )

Get files.

Returns
array<int, array{type: string, size: string}>

Definition at line 79 of file class.ilAdvancedMDRecordExportFiles.php.

79 : array
80 {
81 if (!is_dir($this->export_dir)) {
82 return array();
83 }
84 $files = [];
85 foreach (ilFileUtils::getDir($this->export_dir) as $file_name => $file_data) {
86 $files[$file_name] = $file_data;
87 }
88 return $files;
89 }
static getDir(string $a_dir, bool $a_rec=false, ?string $a_sub_dir="")
get directory

References ilFileUtils\getDir().

Referenced by readFilesInfo().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ init()

ilAdvancedMDRecordExportFiles::init ( )
private

init export directory @access private

Definition at line 140 of file class.ilAdvancedMDRecordExportFiles.php.

140 : void
141 {
142 if (!is_dir($this->export_dir)) {
143 ilFileUtils::makeDirParents($this->export_dir);
144 }
145 }
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.

References ilFileUtils\makeDirParents().

Referenced by __construct().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ readFilesInfo()

ilAdvancedMDRecordExportFiles::readFilesInfo ( )

Read files info @access public.

Returns
array array e.g array(records => 'ECS-Server',size => '123',created' => 121212)

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

49 : array
50 {
51 $file_info = array();
52 foreach ($this->getFiles() as $name => $data) {
53 if ($data['type'] != 'file') {
54 continue;
55 }
56 $file_parts = explode('.', $name);
57 if (!is_numeric($file_parts[0]) or (strcmp('xml', $file_parts[1]) != 0)) {
58 continue;
59 }
60 $file_info = [];
61 $file_info[$file_parts[0]]['size'] = $data['size'];
62 $file_info[$file_parts[0]]['date'] = $file_parts[0];
63
64 if ($xml = simplexml_load_file($this->export_dir . '/' . $name)) {
65 $records = array();
66 foreach ($xml->xpath('Record/Title') as $title) {
67 $records[] = (string) $title;
68 }
69 $file_info[$file_parts[0]]['name'] = $records;
70 }
71 }
72 return $file_info;
73 }
if($format !==null) $name
Definition: metadata.php:247
$xml
Definition: metadata.php:351

References $data, $name, $xml, and getFiles().

+ Here is the call graph for this function:

Field Documentation

◆ $export_dir

string ilAdvancedMDRecordExportFiles::$export_dir = ''
protected

Definition at line 33 of file class.ilAdvancedMDRecordExportFiles.php.


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