ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilAdvancedMDRecordExportFiles.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22*/
23
33{
34 protected $export_dir = '';
35
42 public function __construct($a_obj_id = null)
43 {
44 $this->export_dir = ilUtil::getDataDir().'/ilAdvancedMetaData/export';
45 if($a_obj_id)
46 {
47 $this->export_dir .= "_".$a_obj_id;
48 }
49 $this->init();
50 }
51
58 public function readFilesInfo()
59 {
60 $file_info = array();
61 foreach($this->getFiles() as $name => $data)
62 {
63 if($data['type'] != 'file')
64 {
65 continue;
66 }
67 $file_parts = explode('.',$name);
68 if(!is_numeric($file_parts[0]) or (strcmp('xml',$file_parts[1]) != 0))
69 {
70 continue;
71 }
72 $file_info[$file_parts[0]]['size'] = $data['size'];
73 $file_info[$file_parts[0]]['date'] = $file_parts[0];
74
75 if($xml = simplexml_load_file($this->export_dir.'/'.$name))
76 {
77 $records = array();
78 foreach($xml->xpath('Record/Title') as $title)
79 {
80 $records[] = (string) $title;
81 }
82 $file_info[$file_parts[0]]['name'] = $records;
83 }
84 }
85 return $file_info ? $file_info : array();
86 }
87
94 public function getFiles()
95 {
96 if(!@is_dir($this->export_dir))
97 {
98 return array();
99 }
100 foreach(ilUtil::getDir($this->export_dir) as $file_name => $file_data)
101 {
102 $files[$file_name] = $file_data;
103 }
104 return $files ? $files : array();
105 }
106
114 public function create($a_xml)
115 {
116 global $ilLog,$ilErr;
117
118 if(!$fp = @fopen($this->export_dir.'/'.time().'.xml','w+'))
119 {
120 $ilLog->write(__METHOD__.': Cannot open file '.$this->export_dir.'/'.time().'.xml');
121 $ilErr->raiseError('Cannot write export file.',$ilErr->WARNING);
122 }
123
124 @fwrite($fp,$a_xml);
125 @fclose($fp);
126 }
127
134 public function deleteByFileId($a_timest)
135 {
136 global $ilLog;
137
138 if(!unlink($this->export_dir.'/'.$a_timest.'.xml'))
139 {
140 $ilLog->write(__METHOD__.': Cannot delete file '.$this->export_dir.'/'.$a_timest.'.xml');
141 return false;
142 }
143 return true;
144 }
145
153 public function getAbsolutePathByFileId($a_file_basename)
154 {
155 global $ilLog;
156
157 if(!@file_exists($this->export_dir.'/'.$a_file_basename.'.xml'))
158 {
159 $ilLog->write(__METHOD__.': Cannot find file '.$this->export_dir.'/'.$a_file_basename.'.xml');
160 return false;
161 }
162 return $this->export_dir.'/'.$a_file_basename.'.xml';
163 }
164
171 private function init()
172 {
173 if(!@is_dir($this->export_dir))
174 {
175 ilUtil::makeDirParents($this->export_dir);
176 }
177 }
178}
179?>
create($a_xml)
Create new export file from xml string.
getAbsolutePathByFileId($a_file_basename)
Get absolut path by file id.
static getDataDir()
get data directory (outside webspace)
static getDir($a_dir, $a_rec=false, $a_sub_dir="")
get directory
static makeDirParents($a_dir)
Create a new directory and all parent directories.
$data
$records
Definition: simple_test.php:17