ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilBibliographicDataSet.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 require_once("./Services/DataSet/classes/class.ilDataSet.php");
4 require_once('class.ilObjBibliographic.php');
12 
16  protected $db;
20  protected $data = array();
26  protected $record_field_ids_2_storage = array();
30  protected $import_bib_object;
34  protected $user;
38  protected $import_temp_refs = array();
42  protected $import_temp_refs_props = array();
43 
44 
45  public function __construct() {
46  global $ilDB, $ilUser;
48  $this->db = $ilDB;
49  $this->user = $ilUser;
50  }
51 
52 
56  public function getSupportedVersions() {
57  return array( '4.5.0' );
58  }
59 
60 
67  public function getXmlNamespace($a_entity, $a_schema_version) {
68  return 'http://www.ilias.de/xml/Modules/Bibliographic/' . $a_entity;
69  }
70 
71 
79  public function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version) {
80  global $ilDB;
81  switch ($a_entity) {
82  case 'bibl':
83  $new_obj = new ilObjBibliographic();
84  $new_obj->setTitle($a_rec['title']);
85  $new_obj->setDescription($a_rec['description']);
86  $new_obj->setFilename($a_rec['fileName']);
87  $new_obj->setOnline(false);
88  $new_obj->create();
89  $this->import_bib_object = $new_obj;
90  $a_mapping->addMapping('Modules/Bibliographic', 'bibl', $a_rec['id'], $new_obj->getId());
91  $this->importLibraryFile($a_mapping);
92  break;
93  }
94  }
95 
96 
105  protected function getTypes($a_entity, $a_version) {
106  switch ($a_entity) {
107  case 'bibl':
108  return array(
109  "id" => "integer",
110  "title" => "text",
111  "description" => "text",
112  "filename" => "text",
113  'is_online' => 'integer',
114  );
115  default:
116  return array();
117  }
118  }
119 
120 
131  protected function getDependencies($a_entity, $a_version, $a_rec, $a_ids) {
132  return false;
133  }
134 
135 
143  public function readData($a_entity, $a_version, $a_ids) {
144  $this->data = array();
145  if (! is_array($a_ids)) {
146  $a_ids = array( $a_ids );
147  }
148  $this->_readData($a_entity, $a_ids);
149  }
150 
151 
158  protected function _readData($a_entity, $a_ids) {
159  switch ($a_entity) {
160  case 'bibl':
161  foreach ($a_ids as $bibl_id) {
162  if (ilObject::_lookupType($bibl_id) == 'bibl') {
163  $obj = new ilObjBibliographic($bibl_id);
164  $data = array(
165  'id' => $bibl_id,
166  'title' => $obj->getTitle(),
167  'description' => $obj->getDescription(),
168  'fileName' => $obj->getFilename(),
169  'is_online' => $obj->getOnline(),
170  );
171  $this->data[] = $data;
172  }
173  }
174  break;
175  default:
176  }
177  }
178 
179 
184  public function exportLibraryFile($a_id) {
185  $obj = new ilObjBibliographic($a_id);
186  copy($obj->getFileAbsolutePath(), $this->absolute_export_dir . "/" . $obj->getFilename());
187  }
188 
189 
193  public function importLibraryFile($a_mapping) {
194  $import_path = $this->getImportDirectory()
195  . "/Modules/Bibliographic/set_1/expDir_1/" . $this->import_bib_object->getFilename();
196  $new_id = $this->import_bib_object->getId();
197  $new_path = ilUtil::getDataDir() . "/bibl/" . $new_id;
198  mkdir($new_path);
199  copy($import_path, $new_path . "/" . $this->import_bib_object->getFilename());
200  $this->import_bib_object->writeSourcefileEntriesToDb();
201  }
202 }