ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilBiblFileReaderBase Class Reference

Class ilBiblFileReaderBase. More...

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

Public Member Functions

 __construct (protected \ilBiblEntryFactoryInterface $entry_factory, protected \ilBiblFieldFactoryInterface $field_factory, protected \ilBiblAttributeFactoryInterface $attribute_factory)
 ilBiblFileReaderBase constructor. More...
 
 readContent (ResourceIdentification $identification)
 
 getFileContent ()
 
 setFileContent (string $file_content)
 
 parseContent ()
 
 parseContentToEntries (ilObjBibliographic $bib)
 @inheritDoc More...
 
 getEntryFactory ()
 
 getFieldFactory ()
 
 getAttributeFactory ()
 @inheritDoc More...
 
 readContent (ResourceIdentification $identification)
 
 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 = ''
 
Services $storage
 

Private Attributes

Factory $refinery
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

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

ilBiblFileReaderBase constructor.

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

52 {
53 global $DIC;
54 $this->refinery = $DIC->refinery();
55 $this->storage = $DIC["resource_storage"];
56 }
global $DIC
Definition: shib_login.php:26

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

+ Here is the call graph for this function:

Member Function Documentation

◆ convertStringToUTF8()

ilBiblFileReaderBase::convertStringToUTF8 ( string  $string)
protected

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

67 : string
68 {
69 return $this->refinery->string()
70 ->encoding()
71 ->latin1ToUtf8()
72 ->transform($string);
73 }

References ILIAS\Repository\refinery().

+ Here is the call graph for this function:

◆ getAttributeFactory()

ilBiblFileReaderBase::getAttributeFactory ( )

@inheritDoc

Implements ilBiblFileReaderInterface.

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

168 {
169 return $this->attribute_factory;
170 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

Referenced by parseContentToEntries().

+ Here is the caller graph for this function:

◆ getEntryFactory()

ilBiblFileReaderBase::getEntryFactory ( )

Implements ilBiblFileReaderInterface.

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

152 {
153 return $this->entry_factory;
154 }
Interface ilBiblEntryFactoryInterface.

Referenced by parseContentToEntries().

+ Here is the caller graph for this function:

◆ getFieldFactory()

ilBiblFileReaderBase::getFieldFactory ( )

Implements ilBiblFileReaderInterface.

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

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

◆ getFileContent()

ilBiblFileReaderBase::getFileContent ( )

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

75 : string
76 {
78 }

References $file_content.

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

+ Here is the caller graph for this function:

◆ parseContent()

ilBiblFileReaderBase::parseContent ( )
abstract

Reimplemented in ilBiblTexFileReader, and ilBiblRisFileReader.

Referenced by parseContentToEntries().

+ Here is the caller graph for this function:

◆ parseContentToEntries()

ilBiblFileReaderBase::parseContentToEntries ( ilObjBibliographic  $bib)

@inheritDoc

Implements ilBiblFileReaderInterface.

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

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

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

+ Here is the call graph for this function:

◆ readContent()

ilBiblFileReaderBase::readContent ( ResourceIdentification  $identification)

Implements ilBiblFileReaderInterface.

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

59 : bool
60 {
61 $stream = $this->storage->consume()->stream($identification)->getStream();
62 $this->setFileContent($stream->getContents());
63
64 return true;
65 }
setFileContent(string $file_content)

References setFileContent().

+ Here is the call graph for this function:

◆ setFileContent()

ilBiblFileReaderBase::setFileContent ( string  $file_content)

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

80 : void
81 {
82 $this->file_content = $file_content;
83 }

References $file_content.

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

+ Here is the caller graph for this function:

Field Documentation

◆ $file_content

string ilBiblFileReaderBase::$file_content = ''
protected

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

Referenced by getFileContent(), and setFileContent().

◆ $path_to_file

string ilBiblFileReaderBase::$path_to_file = ''
protected

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

◆ $refinery

Factory ilBiblFileReaderBase::$refinery
private

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

◆ $storage

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 34 of file class.ilBiblFileReaderBase.php.

◆ ENCODING_ASCII

const ilBiblFileReaderBase::ENCODING_ASCII = 'ASCII'

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

◆ ENCODING_ISO_8859_1

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

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

◆ ENCODING_UTF_8

const ilBiblFileReaderBase::ENCODING_UTF_8 = 'UTF-8'

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


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