ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
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
 

Private Attributes

ILIAS Refinery Factory $refinery
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

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

ilBiblFileReaderBase constructor.

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

References $attribute_factory, $DIC, $entry_factory, $field_factory, and ILIAS\Repository\refinery().

53  {
54  global $DIC;
55 
56  $this->entry_factory = $entry_factory;
57  $this->refinery = $DIC->refinery();
58  $this->field_factory = $field_factory;
59  $this->attribute_factory = $attribute_factory;
60  $this->storage = $DIC["resource_storage"];
61  }
ilBiblAttributeFactoryInterface $attribute_factory
global $DIC
Definition: feed.php:28
ilBiblEntryFactoryInterface $entry_factory
ilBiblFieldFactoryInterface $field_factory
+ Here is the call graph for this function:

Member Function Documentation

◆ convertStringToUTF8()

ilBiblFileReaderBase::convertStringToUTF8 ( string  $string)
protected

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

References ILIAS\Repository\refinery().

72  : string
73  {
74  return $this->refinery->string()
75  ->encoding()
76  ->latin1ToUtf8()
77  ->transform($string);
78  }
+ Here is the call graph for this function:

◆ getAttributeFactory()

ilBiblFileReaderBase::getAttributeFactory ( )

Implements ilBiblFileReaderInterface.

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

References $attribute_factory.

Referenced by parseContentToEntries().

175  {
177  }
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 158 of file class.ilBiblFileReaderBase.php.

References $entry_factory.

Referenced by parseContentToEntries().

159  {
160  return $this->entry_factory;
161  }
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 166 of file class.ilBiblFileReaderBase.php.

References $field_factory.

167  {
168  return $this->field_factory;
169  }
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 80 of file class.ilBiblFileReaderBase.php.

References $file_content.

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

80  : string
81  {
82  return $this->file_content;
83  }
+ 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 95 of file class.ilBiblFileReaderBase.php.

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

95  : array
96  {
97  $this->entry_factory->deleteEntriesById($bib->getId());
98 
99  $entries_from_file = $this->parseContent();
100  $entry_instances = [];
101  //fill each entry into a ilBibliographicEntry object and then write it to DB by executing doCreate()
102 
103  foreach ($entries_from_file as $file_entry) {
104  $type = null;
105  $x = 0;
106  $parsed_entry = array();
107  foreach ($file_entry as $key => $attribute) {
108  $key = $this->secure($key);
109  if (is_string($attribute)) {
110  $attribute = $this->secure($attribute);
111  }
112  // if the attribute is an array, make a comma separated string out of it
113  if (is_array($attribute)) {
114  $attribute = array_map(function (string $a): string {
115  return $this->secure($a);
116  }, $attribute);
117  $attribute = implode(", ", $attribute);
118  }
119  // reduce the attribute strings to a maximum of 4000 (ATTRIBUTE_VALUE_MAXIMAL_TEXT_LENGTH) characters, in order to fit in the database
120  //if (mb_strlen($attribute, 'UTF-8') > self::ATTRIBUTE_VALUE_MAXIMAL_TEXT_LENGTH) {
121  if (ilStr::strLen($attribute) > self::ATTRIBUTE_VALUE_MAXIMAL_TEXT_LENGTH) {
122  // $attribute = mb_substr($attribute, 0, self::ATTRIBUTE_VALUE_MAXIMAL_TEXT_LENGTH - 3, 'UTF-8') . '...';
123  $attribute = ilStr::subStr($attribute, 0, self::ATTRIBUTE_VALUE_MAXIMAL_TEXT_LENGTH - 3) . '...';
124  }
125  // ty (RIS) or entryType (BIB) is the type and is treated seperately
126  if (strtolower($key) === 'ty' || strtolower($key) === 'entrytype') {
127  $type = $attribute;
128  continue;
129  }
130  //TODO - Refactoring for ILIAS 4.5 - get rid off array restructuring
131  //change array structure (name not as the key, but under the key "name")
132  $parsed_entry[$x]['name'] = $key;
133  $parsed_entry[$x]['value'] = $attribute;
134  $x++;
135  }
136 
137  if ($type === null) {
138  continue;
139  }
140  //create the entry and fill data into database by executing doCreate()
141  $entry_factory = $this->getEntryFactory();
142  $entry_model = $entry_factory->getEmptyInstance();
143  $entry_model->setType($type);
144  $entry_model->setDataId($bib->getId());
145  $entry_model->store();
146  foreach ($parsed_entry as $entry) {
147  $this->getAttributeFactory()->createAttribute($entry['name'], $entry['value'], $entry_model->getId());
148  }
149  $entry_instances[] = $entry_model;
150  }
151 
152  return $entry_instances;
153  }
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 64 of file class.ilBiblFileReaderBase.php.

References setFileContent().

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

◆ setFileContent()

ilBiblFileReaderBase::setFileContent ( string  $file_content)

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

References $file_content, and parseContent().

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

85  : void
86  {
87  $this->file_content = $file_content;
88  }
+ 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 41 of file class.ilBiblFileReaderBase.php.

Referenced by __construct(), and getAttributeFactory().

◆ $entry_factory

ilBiblEntryFactoryInterface ilBiblFileReaderBase::$entry_factory
protected

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

Referenced by __construct(), and getEntryFactory().

◆ $field_factory

ilBiblFieldFactoryInterface ilBiblFileReaderBase::$field_factory
protected

Definition at line 40 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.

◆ $refinery

ILIAS Refinery Factory ilBiblFileReaderBase::$refinery
private

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

◆ $storage

ILIAS ResourceStorage Services ilBiblFileReaderBase::$storage
protected

Definition at line 43 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: