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

Group Import Parser. More...

+ Inheritance diagram for ilCategoryXmlParser:
+ Collaboration diagram for ilCategoryXmlParser:

Public Member Functions

 __construct (string $a_xml, int $a_parent_id)
 
 getParentId ()
 
 setHandlers ($a_xml_parser)
 
 startParsing ()
 
 handlerBeginTag ($a_xml_parser, string $a_name, array $a_attribs)
 
 handlerEndTag ($a_xml_parser, string $a_name)
 
 handlerCharacterData ($a_xml_parser, string $a_data)
 
 setMode (int $mode)
 
 setCategory (ilObjCategory $cat)
 
 getCategory ()
 
- Public Member Functions inherited from ilSaxParser
 __construct (?string $path_to_file='', ?bool $throw_exception=false)
 
 setXMLContent (string $a_xml_content)
 
 getXMLContent ()
 
 getInputType ()
 
 startParsing ()
 stores xml data in array More...
 
 createParser ()
 
 setHandlers ($a_xml_parser)
 
 parse ($a_xml_parser, $a_fp=null)
 

Data Fields

const MODE_CREATE = 1
 
const MODE_UPDATE = 2
 
- Data Fields inherited from ilSaxParser
string $xml_file
 
bool $throw_exception = false
 

Protected Member Functions

 getCurrentTranslation ()
 
 save ()
 
- Protected Member Functions inherited from ilContainerBaseXmlParser
 trimAndStripAttribs (array $attribs)
 
 trimAndStrip (string $input)
 
- Protected Member Functions inherited from ilSaxParser
 openXMLFile ()
 
 handleError (string $message)
 
 setThrowException (bool $throw_exception)
 

Protected Attributes

ilLogger $cat_log
 
int $mode
 
string $cdata = ""
 
- Protected Attributes inherited from ilSaxParser
ilLanguage $lng = null
 

Private Attributes

ilObjCategory $cat = null
 
int $parent_id = 0
 
array $current_translation = []
 
string $current_container_setting
 

Detailed Description

Group Import Parser.

Author
Stefan Meyer meyer.nosp@m.@lei.nosp@m.fos.c.nosp@m.om

Definition at line 23 of file class.ilCategoryXmlParser.php.

Constructor & Destructor Documentation

◆ __construct()

ilCategoryXmlParser::__construct ( string  $a_xml,
int  $a_parent_id 
)

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

References ILIAS\GlobalScreen\Provider\__construct(), ilLoggerFactory\getLogger(), and ilSaxParser\setXMLContent().

37  {
38  parent::__construct(null);
39 
40  $this->mode = self::MODE_CREATE;
41  $this->parent_id = $a_parent_id;
42  $this->setXMLContent($a_xml);
43 
44  $this->cat_log = ilLoggerFactory::getLogger("cat");
45  }
static getLogger(string $a_component_id)
Get component logger.
__construct(Container $dic, ilPlugin $plugin)
setXMLContent(string $a_xml_content)
+ Here is the call graph for this function:

Member Function Documentation

◆ getCategory()

ilCategoryXmlParser::getCategory ( )

Definition at line 208 of file class.ilCategoryXmlParser.php.

References $cat.

Referenced by handlerBeginTag(), handlerEndTag(), and save().

208  : ?ilObjCategory
209  {
210  return $this->cat;
211  }
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:

◆ getCurrentTranslation()

ilCategoryXmlParser::getCurrentTranslation ( )
protected
Returns
array

Definition at line 55 of file class.ilCategoryXmlParser.php.

References $current_translation.

55  : array
56  {
58  }

◆ getParentId()

ilCategoryXmlParser::getParentId ( )

Definition at line 47 of file class.ilCategoryXmlParser.php.

References $parent_id.

Referenced by save().

47  : int
48  {
49  return $this->parent_id;
50  }
+ Here is the caller graph for this function:

◆ handlerBeginTag()

ilCategoryXmlParser::handlerBeginTag (   $a_xml_parser,
string  $a_name,
array  $a_attribs 
)
Parameters
XMLParser | resource$a_xml_parser
string$a_name
array$a_attribs
Returns
void

Definition at line 82 of file class.ilCategoryXmlParser.php.

References ilContainerSortingSettings\_importContainerSortingSettings(), getCategory(), ILIAS\Survey\Mode\getId(), and ilContainerBaseXmlParser\trimAndStripAttribs().

82  : void
83  {
84  $a_attribs = $this->trimAndStripAttribs($a_attribs);
85  switch ($a_name) {
86  case "Category":
87  break;
88 
89  case 'Translations':
90  $this->getCategory()->removeTranslations();
91  break;
92 
93  case 'Translation':
94  $this->current_translation = [];
95  $this->current_translation['default'] = $a_attribs['default'] ? 1 : 0;
96  $this->current_translation['lang'] = $a_attribs['language'];
97  break;
98 
99  case 'Sorting':
100  case 'Sort':
102  break;
103 
104  case 'ContainerSetting':
105  $this->current_container_setting = $a_attribs['id'];
106  break;
107  }
108  }
static _importContainerSortingSettings(array $attibs, int $obj_id)
sorting import for all container objects
+ Here is the call graph for this function:

◆ handlerCharacterData()

ilCategoryXmlParser::handlerCharacterData (   $a_xml_parser,
string  $a_data 
)
Parameters
XMLParser | resource$a_xml_parser
string$a_data
Returns
void

Definition at line 175 of file class.ilCategoryXmlParser.php.

175  : void
176  {
177  if (!empty($a_data)) {
178  $this->cdata .= $a_data;
179  }
180  }

◆ handlerEndTag()

ilCategoryXmlParser::handlerEndTag (   $a_xml_parser,
string  $a_name 
)
Parameters
XMLParser | resource$a_xml_parser
string$a_name
Returns
void

Definition at line 115 of file class.ilCategoryXmlParser.php.

References ilContainer\_writeContainerSetting(), getCategory(), ILIAS\Survey\Mode\getId(), save(), and ilContainerBaseXmlParser\trimAndStrip().

115  : void
116  {
117  $this->cdata = $this->trimAndStrip($this->cdata);
118  switch ($a_name) {
119  case "Category":
120  $this->save();
121  break;
122 
123  case 'Title':
124  $this->current_translation['title'] = trim($this->cdata);
125 
126  if ($this->current_translation['default']) {
127  $this->getCategory()->setTitle(trim($this->cdata));
128  }
129 
130  break;
131 
132  case 'Description':
133  $this->current_translation['description'] = trim($this->cdata);
134 
135  if ($this->current_translation['default']) {
136  $this->getCategory()->setDescription(trim($this->cdata));
137  }
138 
139  break;
140 
141  case 'Translation':
142  // Add translation
143  $this->getCategory()->addTranslation(
144  (string) $this->current_translation['title'],
145  (string) $this->current_translation['description'],
146  (string) $this->current_translation['lang'],
147  (string) ((int) $this->current_translation['default'])
148  );
149  break;
150 
151  case 'ContainerSetting':
152  if ($this->current_container_setting) {
153  $this->cat_log->debug("Write container Setting, ID: " . $this->getCategory()->getId() . ", setting: " .
154  $this->current_container_setting . ", data: " . $this->cdata);
156  $this->getCategory()->getId(),
157  $this->current_container_setting,
158  $this->cdata
159  );
160  }
161  break;
162 
163  case 'ContainerSettings':
164  $this->cat->readContainerSettings(); // read container settings to member vars (call getter/setter), see #0019870
165  break;
166  }
167  $this->cdata = '';
168  }
static _writeContainerSetting(int $a_id, string $a_keyword, string $a_value)
+ Here is the call graph for this function:

◆ save()

ilCategoryXmlParser::save ( )
protected

mode can be create or update

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

References getCategory(), and getParentId().

Referenced by handlerEndTag().

182  : bool
183  {
184 
188  if ($this->mode === self::MODE_CREATE) {
189  $this->getCategory()->create();
190  $this->getCategory()->createReference();
191  $this->getCategory()->putInTree($this->getParentId());
192  $this->getCategory()->setPermissions($this->getParentId());
193  }
194  $this->getCategory()->update();
195  return true;
196  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setCategory()

ilCategoryXmlParser::setCategory ( ilObjCategory  $cat)

Definition at line 203 of file class.ilCategoryXmlParser.php.

References $cat.

203  : void
204  {
205  $this->cat = $cat;
206  }

◆ setHandlers()

ilCategoryXmlParser::setHandlers (   $a_xml_parser)

Definition at line 60 of file class.ilCategoryXmlParser.php.

60  : void
61  {
62  xml_set_object($a_xml_parser, $this);
63  xml_set_element_handler($a_xml_parser, 'handlerBeginTag', 'handlerEndTag');
64  xml_set_character_data_handler($a_xml_parser, 'handlerCharacterData');
65  }

◆ setMode()

ilCategoryXmlParser::setMode ( int  $mode)

Definition at line 198 of file class.ilCategoryXmlParser.php.

References $mode.

198  : void
199  {
200  $this->mode = $mode;
201  }

◆ startParsing()

ilCategoryXmlParser::startParsing ( )

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

67  : void
68  {
69  parent::startParsing();
70 
71  if ($this->mode !== self::MODE_CREATE) {
72  $this->cat->update();
73  }
74  }

Field Documentation

◆ $cat

ilObjCategory ilCategoryXmlParser::$cat = null
private

Definition at line 28 of file class.ilCategoryXmlParser.php.

Referenced by getCategory(), and setCategory().

◆ $cat_log

ilLogger ilCategoryXmlParser::$cat_log
protected

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

◆ $cdata

string ilCategoryXmlParser::$cdata = ""
protected

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

◆ $current_container_setting

string ilCategoryXmlParser::$current_container_setting
private

Definition at line 31 of file class.ilCategoryXmlParser.php.

◆ $current_translation

array ilCategoryXmlParser::$current_translation = []
private

Definition at line 30 of file class.ilCategoryXmlParser.php.

Referenced by getCurrentTranslation().

◆ $mode

int ilCategoryXmlParser::$mode
protected

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

Referenced by setMode().

◆ $parent_id

int ilCategoryXmlParser::$parent_id = 0
private

Definition at line 29 of file class.ilCategoryXmlParser.php.

Referenced by getParentId().

◆ MODE_CREATE

const ilCategoryXmlParser::MODE_CREATE = 1

Definition at line 25 of file class.ilCategoryXmlParser.php.

Referenced by ilContainerReferenceXmlParser\save().

◆ MODE_UPDATE

const ilCategoryXmlParser::MODE_UPDATE = 2

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