ILIAS  release_4-4 Revision
All Data Structures Namespaces Files Functions Variables Modules Pages
ilOrgUnitSimpleImport Class Reference

Class ilOrgUnitSimpleImport. More...

+ Inheritance diagram for ilOrgUnitSimpleImport:
+ Collaboration diagram for ilOrgUnitSimpleImport:

Public Member Functions

 simpleImport ($file_path)
 
 simpleImportElement (SimpleXMLElement $o)
 
- Public Member Functions inherited from ilOrgUnitImporter
 hasErrors ()
 
 hasWarnings ()
 
 addWarning ($lang_var, $import_id, $action=null)
 
 addError ($lang_var, $import_id, $action=null)
 
 getErrors ()
 
 getWarnings ()
 
 getStats ()
 
 importXmlRepresentation ($a_entity, $a_id, $a_xml, $a_mapping)
 Import XML. More...
 
- Public Member Functions inherited from ilXmlImporter
 __construct ()
 Constructor. More...
 
 init ()
 Init. More...
 
 setInstallId ($a_val)
 Set installation id. More...
 
 getInstallId ()
 Get installation id. More...
 
 setInstallUrl ($a_val)
 Set installation url. More...
 
 getInstallUrl ()
 Get installation url. More...
 
 setSchemaVersion ($a_val)
 Set schema version. More...
 
 getSchemaVersion ()
 Get schema version. More...
 
 setImportDirectory ($a_val)
 Set import directory. More...
 
 getImportDirectory ()
 Get import directory. More...
 
 setSkipEntities ($a_val)
 Set skip entities. More...
 
 getSkipEntities ()
 Get skip entities. More...
 
 importXmlRepresentation ($a_entity, $a_id, $a_xml, $a_mapping)
 Import xml representation. More...
 
 finalProcessing ($a_mapping)
 Final processing. More...
 

Additional Inherited Members

- Data Fields inherited from ilOrgUnitImporter
 $errors
 
 $warnings
 
 $stats
 
- Protected Member Functions inherited from ilOrgUnitImporter
 buildRef ($id, $type)
 
- Protected Attributes inherited from ilXmlImporter
 $skip_entities = array()
 

Detailed Description

Member Function Documentation

◆ simpleImport()

ilOrgUnitSimpleImport::simpleImport (   $file_path)

Definition at line 13 of file class.ilOrgUnitSimpleImport.php.

References $lng, ilOrgUnitImporter\addError(), and simpleImportElement().

13  {
14  global $lng;
15  $this->stats = array("created" => 0, "updated" => 0, "deleted" => 0);
16  $a = file_get_contents($file_path, "r");
17  $xml = new SimpleXMLElement($a);
18 
19  if(!count($xml->OrgUnit)) {
20  $this->addError("no_orgunit",null,null);
21  return;
22  }
23 
24  foreach($xml->OrgUnit as $o){
25  $this->simpleImportElement($o);
26  }
27  }
addError($lang_var, $import_id, $action=null)
global $lng
Definition: privfeed.php:40
simpleImportElement(SimpleXMLElement $o)
+ Here is the call graph for this function:

◆ simpleImportElement()

ilOrgUnitSimpleImport::simpleImportElement ( SimpleXMLElement  $o)

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

References $ilLog, $ilUser, $ref_id, $tpl, ilObject\_lookupObjIdByImportId(), ilOrgUnitImporter\addError(), ilOrgUnitImporter\addWarning(), ilOrgUnitImporter\buildRef(), and ilObjOrgUnit\getRootOrgRefId().

Referenced by simpleImport().

29  {
30  global $tree, $tpl, $ilUser;
31  $title = $o->title;
32  $description = $o->description;
33  $external_id = $o->external_id;
34  $create_mode = true;
35  $attributes = $o->attributes();
36  $action = (string)$attributes->action;
37  $ou_id = (string)$attributes->ou_id;
38  $ou_id_type = (string)$attributes->ou_id_type;
39  $ou_parent_id = (string)$attributes->ou_parent_id;
40  $ou_parent_id_type = (string)$attributes->ou_parent_id_type;
41 
42  if($ou_id == ilObjOrgUnit::getRootOrgRefId()){
43  $this->addWarning("cannot_change_root_node", $ou_id, $action);
44  return;
45  }
46 
47  if($ou_parent_id == "__ILIAS"){
48  $ou_parent_id = ilObjOrgUnit::getRootOrgRefId();
49  $ou_parent_id_type = "reference_id";
50  }
51 
52  $ref_id = $this->buildRef($ou_id, $ou_id_type);
53  $parent_ref_id = $this->buildRef($ou_parent_id, $ou_parent_id_type);
54 
55  if($action == "delete"){
56  if(!$parent_ref_id){
57  $this->addError("ou_parent_id_not_valid", $ou_id, $action);
58  return;
59  }
60  if(!$ref_id){
61  $this->addError("ou_id_not_valid", $ou_id, $action);
62  return;
63  }
64  include_once("./Services/Repository/classes/class.ilRepUtil.php");
65  $ru = new ilRepUtil($this);
66  try{
67  $ru->deleteObjects($parent_ref_id, array($ref_id)) !== false;
68  $this->stats["deleted"]++;
69  }catch(Excpetion $e){
70  $this->addWarning("orgu_already_deleted", $ou_id, $action);
71  }
72  return;
73  }elseif($action == "update"){
74  if(!$parent_ref_id){
75  $this->addError("ou_parent_id_not_valid", $ou_id, $action);
76  return;
77  }
78  if(!$ref_id){
79  $this->addError("ou_id_not_valid", $ou_id, $action);
80  return;
81  }
82  $object = new ilObjOrgUnit($ref_id);
83  $object->setTitle($title);
84 
85  $arrTranslations = $object->getTranslations();
86  $object->updateTranslation($title,$description,$ilUser->getLanguage(),"");
87 
88  $object->setDescription($description);
89  $object->update();
90  $object->setImportId($external_id);
91  if($parent_ref_id != $tree->getParentId($ref_id)){
92  try{
93  $tree->moveTree($ref_id, $parent_ref_id);
94  }catch(Exception $e){
95  global $ilLog;
96  $this->addWarning("not_movable", $ou_id, $action);
97  $ilLog->write($e->getMessage()."\\n".$e->getTraceAsString());
98  }
99  }
100  $this->stats["updated"]++;
101  }elseif($action == "create"){
102  if(!$parent_ref_id){
103  $this->addError("ou_parent_id_not_valid", $ou_id, $action);
104  return;
105  }
106  if($external_id){
107  if(ilObject::_lookupObjIdByImportId($external_id))
108  {
109  $this->addError("ou_external_id_exists", $ou_id, $action);
110  return;
111  }
112  }
113  $object = new ilObjOrgUnit();
114  $object->setTitle($title);
115  $object->setDescription($description);
116  $object->setImportId($external_id);
117  $object->create();
118  $object->createReference();
119  $object->putInTree($parent_ref_id);
120  $object->setPermissions($ou_parent_id);
121  $this->stats["created"]++;
122  }else{
123  $this->addError("no_valid_action_given", $ou_id, $action);
124  }
125  }
Repository Utilities (application layer, put GUI related stuff into ilRepUtilGUI) ...
addWarning($lang_var, $import_id, $action=null)
addError($lang_var, $import_id, $action=null)
Class ilObjOrgUnit.
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
static getRootOrgRefId()
global $ilUser
Definition: imgupload.php:15
$ref_id
Definition: sahs_server.php:39
static _lookupObjIdByImportId($a_import_id)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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