ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilBiblFileReaderBase Class Reference

Class ilBiblFileReaderBase. More...

+ Inheritance diagram for ilBiblFileReaderBase:
+ Collaboration diagram for ilBiblFileReaderBase:

Public Member Functions

 __construct (ilBiblEntryFactoryInterface $entry_factory, ilBiblFieldFactoryInterface $field_factory, ilBiblAttributeFactoryInterface $attribute_factory)
 ilBiblFileReaderBase constructor. More...
 
 readContent (ResourceIdentification $identification)
 
 getFileContent ()
 
 setFileContent (string $file_content)
 
 parseContent ()
 
 parseContentToEntries (ilObjBibliographic $bib)
 
 getEntryFactory ()
 
 getFieldFactory ()
 
 getAttributeFactory ()
 

Data Fields

const ATTRIBUTE_VALUE_MAXIMAL_TEXT_LENGTH = 4000
 
const ENCODING_UTF_8 = 'UTF-8'
 
const ENCODING_ASCII = 'ASCII'
 
const ENCODING_ISO_8859_1 = 'ISO-8859-1'
 

Protected Member Functions

 convertStringToUTF8 (string $string)
 

Protected Attributes

string $file_content = ''
 
string $path_to_file = ''
 
ilBiblEntryFactoryInterface $entry_factory
 
ilBiblFieldFactoryInterface $field_factory
 
ilBiblAttributeFactoryInterface $attribute_factory
 
ILIAS ResourceStorage Services $storage
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilBiblFileReaderBase::__construct ( ilBiblEntryFactoryInterface  $entry_factory,
ilBiblFieldFactoryInterface  $field_factory,
ilBiblAttributeFactoryInterface  $attribute_factory 
)

ilBiblFileReaderBase constructor.

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

References $attribute_factory, $DIC, $entry_factory, and $field_factory.

52  {
53  global $DIC;
54 
55  $this->entry_factory = $entry_factory;
56  $this->field_factory = $field_factory;
57  $this->attribute_factory = $attribute_factory;
58  $this->storage = $DIC["resource_storage"];
59  }
ilBiblAttributeFactoryInterface $attribute_factory
global $DIC
Definition: feed.php:28
ilBiblEntryFactoryInterface $entry_factory
ilBiblFieldFactoryInterface $field_factory

Member Function Documentation

◆ convertStringToUTF8()

ilBiblFileReaderBase::convertStringToUTF8 ( string  $string)
protected

Definition at line 70 of file class.ilBiblFileReaderBase.php.

70  : string
71  {
72  if (!function_exists('mb_detect_encoding') || !function_exists('mb_detect_order')
73  || !function_exists("mb_convert_encoding")
74  ) {
75  return $string;
76  }
77 
78  ob_end_clean();
79 
80  $mb_detect_encoding = mb_detect_encoding($string);
81  mb_detect_order(array(self::ENCODING_UTF_8, self::ENCODING_ISO_8859_1));
82  switch ($mb_detect_encoding) {
83  case self::ENCODING_UTF_8:
84  break;
85  case self::ENCODING_ASCII:
86  $string = utf8_encode(iconv(self::ENCODING_ASCII, 'UTF-8//IGNORE', $string));
87  break;
88  default:
89  $string = mb_convert_encoding($string, self::ENCODING_UTF_8, $mb_detect_encoding);
90  break;
91  }
92 
93  return $string;
94  }

◆ getAttributeFactory()

ilBiblFileReaderBase::getAttributeFactory ( )

Implements ilBiblFileReaderInterface.

Definition at line 190 of file class.ilBiblFileReaderBase.php.

References $attribute_factory.

Referenced by parseContentToEntries().

191  {
193  }
ilBiblAttributeFactoryInterface $attribute_factory
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
+ Here is the caller graph for this function:

◆ getEntryFactory()

ilBiblFileReaderBase::getEntryFactory ( )

Implements ilBiblFileReaderInterface.

Definition at line 174 of file class.ilBiblFileReaderBase.php.

References $entry_factory.

Referenced by parseContentToEntries().

175  {
176  return $this->entry_factory;
177  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilBiblEntryFactoryInterface $entry_factory
+ Here is the caller graph for this function:

◆ getFieldFactory()

ilBiblFileReaderBase::getFieldFactory ( )

Implements ilBiblFileReaderInterface.

Definition at line 182 of file class.ilBiblFileReaderBase.php.

References $field_factory.

183  {
184  return $this->field_factory;
185  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilBiblFieldFactoryInterface $field_factory

◆ getFileContent()

ilBiblFileReaderBase::getFileContent ( )

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

References $file_content.

Referenced by ilBiblTexFileReader\convertBibSpecialChars(), ilBiblTexFileReader\normalizeContent(), and ilBiblTexFileReader\parseContent().

96  : string
97  {
98  return $this->file_content;
99  }
+ Here is the caller graph for this function:

◆ parseContent()

ilBiblFileReaderBase::parseContent ( )
abstract

Referenced by parseContentToEntries(), and setFileContent().

+ Here is the caller graph for this function:

◆ parseContentToEntries()

ilBiblFileReaderBase::parseContentToEntries ( ilObjBibliographic  $bib)

Implements ilBiblFileReaderInterface.

Definition at line 111 of file class.ilBiblFileReaderBase.php.

References Vendor\Package\$a, ILIAS\LTI\ToolProvider\$key, $type, getAttributeFactory(), getEntryFactory(), ilObject\getId(), parseContent(), ilStr\strLen(), and ilStr\subStr().

111  : array
112  {
113  $this->entry_factory->deleteEntriesById($bib->getId());
114 
115  $entries_from_file = $this->parseContent();
116  $entry_instances = [];
117  //fill each entry into a ilBibliographicEntry object and then write it to DB by executing doCreate()
118 
119  foreach ($entries_from_file as $file_entry) {
120  $type = null;
121  $x = 0;
122  $parsed_entry = array();
123  foreach ($file_entry as $key => $attribute) {
124  $key = $this->secure($key);
125  if (is_string($attribute)) {
126  $attribute = $this->secure($attribute);
127  }
128  // if the attribute is an array, make a comma separated string out of it
129  if (is_array($attribute)) {
130  $attribute = array_map(function (string $a): string {
131  return $this->secure($a);
132  }, $attribute);
133  $attribute = implode(", ", $attribute);
134  }
135  // reduce the attribute strings to a maximum of 4000 (ATTRIBUTE_VALUE_MAXIMAL_TEXT_LENGTH) characters, in order to fit in the database
136  //if (mb_strlen($attribute, 'UTF-8') > self::ATTRIBUTE_VALUE_MAXIMAL_TEXT_LENGTH) {
137  if (ilStr::strLen($attribute) > self::ATTRIBUTE_VALUE_MAXIMAL_TEXT_LENGTH) {
138  // $attribute = mb_substr($attribute, 0, self::ATTRIBUTE_VALUE_MAXIMAL_TEXT_LENGTH - 3, 'UTF-8') . '...';
139  $attribute = ilStr::subStr($attribute, 0, self::ATTRIBUTE_VALUE_MAXIMAL_TEXT_LENGTH - 3) . '...';
140  }
141  // ty (RIS) or entryType (BIB) is the type and is treated seperately
142  if (strtolower($key) === 'ty' || strtolower($key) === 'entrytype') {
143  $type = $attribute;
144  continue;
145  }
146  //TODO - Refactoring for ILIAS 4.5 - get rid off array restructuring
147  //change array structure (name not as the key, but under the key "name")
148  $parsed_entry[$x]['name'] = $key;
149  $parsed_entry[$x]['value'] = $attribute;
150  $x++;
151  }
152 
153  if ($type === null) {
154  continue;
155  }
156  //create the entry and fill data into database by executing doCreate()
157  $entry_factory = $this->getEntryFactory();
158  $entry_model = $entry_factory->getEmptyInstance();
159  $entry_model->setType($type);
160  $entry_model->setDataId($bib->getId());
161  $entry_model->store();
162  foreach ($parsed_entry as $entry) {
163  $this->getAttributeFactory()->createAttribute($entry['name'], $entry['value'], $entry_model->getId());
164  }
165  $entry_instances[] = $entry_model;
166  }
167 
168  return $entry_instances;
169  }
$type
static subStr(string $a_str, int $a_start, ?int $a_length=null)
Definition: class.ilStr.php:24
static strLen(string $a_string)
Definition: class.ilStr.php:63
string $key
Consumer key/client ID value.
Definition: System.php:193
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
ilBiblEntryFactoryInterface $entry_factory
+ Here is the call graph for this function:

◆ readContent()

ilBiblFileReaderBase::readContent ( ResourceIdentification  $identification)

Implements ilBiblFileReaderInterface.

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

References setFileContent().

62  : bool
63  {
64  $stream = $this->storage->consume()->stream($identification)->getStream();
65  $this->setFileContent($stream->getContents());
66 
67  return true;
68  }
setFileContent(string $file_content)
+ Here is the call graph for this function:

◆ setFileContent()

ilBiblFileReaderBase::setFileContent ( string  $file_content)

Definition at line 101 of file class.ilBiblFileReaderBase.php.

References $file_content, and parseContent().

Referenced by ilBiblTexFileReader\convertBibSpecialChars(), ilBiblTexFileReader\normalizeContent(), and readContent().

101  : void
102  {
103  $this->file_content = $file_content;
104  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $attribute_factory

ilBiblAttributeFactoryInterface ilBiblFileReaderBase::$attribute_factory
protected

Definition at line 40 of file class.ilBiblFileReaderBase.php.

Referenced by __construct(), and getAttributeFactory().

◆ $entry_factory

ilBiblEntryFactoryInterface ilBiblFileReaderBase::$entry_factory
protected

Definition at line 38 of file class.ilBiblFileReaderBase.php.

Referenced by __construct(), and getEntryFactory().

◆ $field_factory

ilBiblFieldFactoryInterface ilBiblFileReaderBase::$field_factory
protected

Definition at line 39 of file class.ilBiblFileReaderBase.php.

Referenced by __construct(), and getFieldFactory().

◆ $file_content

string ilBiblFileReaderBase::$file_content = ''
protected

Definition at line 36 of file class.ilBiblFileReaderBase.php.

Referenced by getFileContent(), and setFileContent().

◆ $path_to_file

string ilBiblFileReaderBase::$path_to_file = ''
protected

Definition at line 37 of file class.ilBiblFileReaderBase.php.

◆ $storage

ILIAS ResourceStorage Services ilBiblFileReaderBase::$storage
protected

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

◆ ATTRIBUTE_VALUE_MAXIMAL_TEXT_LENGTH

const ilBiblFileReaderBase::ATTRIBUTE_VALUE_MAXIMAL_TEXT_LENGTH = 4000

Definition at line 32 of file class.ilBiblFileReaderBase.php.

◆ ENCODING_ASCII

const ilBiblFileReaderBase::ENCODING_ASCII = 'ASCII'

Definition at line 34 of file class.ilBiblFileReaderBase.php.

◆ ENCODING_ISO_8859_1

const ilBiblFileReaderBase::ENCODING_ISO_8859_1 = 'ISO-8859-1'

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

◆ ENCODING_UTF_8

const ilBiblFileReaderBase::ENCODING_UTF_8 = 'UTF-8'

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


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