ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5
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;
47  parent::__construct();
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  if($new_id = $a_mapping->getMapping('Services/Container','objs',$a_rec['id']))
84  {
85  // container content
86  $new_obj = ilObjectFactory::getInstanceByObjId($new_id,false);
87  } else {
88  $new_obj = new ilObjBibliographic();
89  }
90  $new_obj->setTitle($a_rec['title']);
91  $new_obj->setDescription($a_rec['description']);
92  $new_obj->setFilename($a_rec['fileName']);
93  $new_obj->setOnline(false);
94  if (!$new_obj->getId()) {
95  $new_obj->create();
96  }
97  $this->import_bib_object = $new_obj;
98  $a_mapping->addMapping('Modules/Bibliographic', 'bibl', $a_rec['id'], $new_obj->getId());
99  $this->importLibraryFile($a_mapping);
100  break;
101  }
102  }
103 
104 
113  protected function getTypes($a_entity, $a_version) {
114  switch ($a_entity) {
115  case 'bibl':
116  return array(
117  "id" => "integer",
118  "title" => "text",
119  "description" => "text",
120  "filename" => "text",
121  'is_online' => 'integer',
122  );
123  default:
124  return array();
125  }
126  }
127 
128 
139  protected function getDependencies($a_entity, $a_version, $a_rec, $a_ids) {
140  return false;
141  }
142 
143 
151  public function readData($a_entity, $a_version, $a_ids) {
152  $this->data = array();
153  if (! is_array($a_ids)) {
154  $a_ids = array( $a_ids );
155  }
156  $this->_readData($a_entity, $a_ids);
157  }
158 
159 
166  protected function _readData($a_entity, $a_ids) {
167  switch ($a_entity) {
168  case 'bibl':
169  foreach ($a_ids as $bibl_id) {
170  if (ilObject::_lookupType($bibl_id) == 'bibl') {
171  $obj = new ilObjBibliographic($bibl_id);
172  $data = array(
173  'id' => $bibl_id,
174  'title' => $obj->getTitle(),
175  'description' => $obj->getDescription(),
176  'fileName' => $obj->getFilename(),
177  'is_online' => $obj->getOnline(),
178  );
179  $this->data[] = $data;
180  }
181  }
182  break;
183  default:
184  }
185  }
186 
187 
192  public function exportLibraryFile($a_id) {
193  $obj = new ilObjBibliographic($a_id);
194  copy($obj->getFileAbsolutePath(), $this->absolute_export_dir . "/" . $obj->getFilename());
195  }
196 
197 
201  public function importLibraryFile($a_mapping) {
202  $import_path = $this->getImportDirectory()
203  . "/Modules/Bibliographic/set_1/expDir_1/" . $this->import_bib_object->getFilename();
204  $new_id = $this->import_bib_object->getId();
205  $new_path = ilUtil::getDataDir() . "/bibl/" . $new_id;
206  mkdir($new_path);
207  copy($import_path, $new_path . "/" . $this->import_bib_object->getFilename());
208  // this will write the source file entry to db
209  $this->import_bib_object->update();
210  }
211 }
getDependencies($a_entity, $a_version, $a_rec, $a_ids)
Return dependencies form entities to other entities (in our case these are all the DB relations) ...
Bibliographic dataset class.
getXmlNamespace($a_entity, $a_schema_version)
_readData($a_entity, $a_ids)
Build data array, data is read from cache except bibl object itself.
getImportDirectory()
Get import directory.
readData($a_entity, $a_version, $a_ids)
Read data from Cache for a given entity and ID(s)
getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
getTypes($a_entity, $a_version)
Map XML attributes of entities to datatypes (text, integer...)
static _lookupType($a_id, $a_reference=false)
lookup object type
static getDataDir()
get data directory (outside webspace)
global $ilUser
Definition: imgupload.php:15
global $ilDB
Class ilObjBibliographic.
A dataset contains in data in a common structure that can be shared and transformed for different pur...
importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)