ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
ilTestQuestionPoolImporter Class Reference

Importer class for question pools. More...

+ Inheritance diagram for ilTestQuestionPoolImporter:
+ Collaboration diagram for ilTestQuestionPoolImporter:

Public Member Functions

 importXmlRepresentation ($a_entity, $a_id, $a_xml, $a_mapping)
 Import XML. More...
 
 finalProcessing ($a_mapping)
 Final processing. More...
 
- Public Member Functions inherited from ilXmlImporter
 __construct ()
 Constructor. More...
 
 setImport ($a_val)
 Set import. More...
 
 getImport ()
 Get import. 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...
 
 exportedFromSameInstallation ()
 Is exporting and importing installation identical? More...
 
 importXmlRepresentation ($a_entity, $a_id, $a_xml, $a_mapping)
 Import xml representation. More...
 
 finalProcessing ($a_mapping)
 Final processing. More...
 
 afterContainerImportProcessing (ilImportMapping $mapping)
 Called after all container objects have been implemented. More...
 

Protected Member Functions

 parseXmlFileNames ()
 Create qti and xml file name. More...
 

Private Member Functions

 getImportDirectoryContainer ()
 
 getImportPackageName ()
 

Private Attributes

 $poolOBJ
 

Additional Inherited Members

- Protected Attributes inherited from ilXmlImporter
 $skip_entities = array()
 
 $imp
 

Detailed Description

Importer class for question pools.

Author
Helmut Schottmüller ilias.nosp@m.@aur.nosp@m.ealis.nosp@m..de
Version
$Id$

Definition at line 14 of file class.ilTestQuestionPoolImporter.php.

Member Function Documentation

◆ finalProcessing()

ilTestQuestionPoolImporter::finalProcessing (   $a_mapping)

Final processing.

Parameters
ilImportMapping$a_mapping
Returns

Definition at line 137 of file class.ilTestQuestionPoolImporter.php.

References ilObjTaxonomy\saveUsage().

138  {
139  //echo "<pre>".print_r($a_mapping, true)."</pre>"; exit;
140  // get all glossaries of the import
141  include_once("./Services/Taxonomy/classes/class.ilObjTaxonomy.php");
142  $maps = $a_mapping->getMappingsOfEntity("Modules/TestQuestionPool", "qpl");
143  foreach ($maps as $old => $new)
144  {
145  if ($old != "new_id" && (int) $old > 0)
146  {
147  // get all new taxonomys of this object
148  $new_tax_ids = $a_mapping->getMapping("Services/Taxonomy", "tax_usage_of_obj", $old);
149  if($new_tax_ids !== false)
150  {
151  $tax_ids = explode(":", $new_tax_ids);
152  foreach($tax_ids as $tid)
153  {
154  ilObjTaxonomy::saveUsage($tid, $new);
155  }
156  }
157 
158  $taxMappings = $a_mapping->getMappingsOfEntity('Services/Taxonomy', 'tax');
159  foreach($taxMappings as $oldTaxId => $newTaxId)
160  {
161  if( $oldTaxId == $this->poolOBJ->getNavTaxonomyId() )
162  {
163  $this->poolOBJ->setNavTaxonomyId($newTaxId);
164  $this->poolOBJ->saveToDb();
165  break;
166  }
167  }
168  }
169  }
170  }
static saveUsage($a_tax_id, $a_obj_id)
Save Usage.
+ Here is the call graph for this function:

◆ getImportDirectoryContainer()

ilTestQuestionPoolImporter::getImportDirectoryContainer ( )
private

Definition at line 188 of file class.ilTestQuestionPoolImporter.php.

References ilXmlImporter\getImportDirectory().

Referenced by importXmlRepresentation().

189  {
190  $dir = $this->getImportDirectory();
191  $dir = dirname($dir);
192  return $dir;
193  }
getImportDirectory()
Get import directory.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getImportPackageName()

ilTestQuestionPoolImporter::getImportPackageName ( )
private

Definition at line 195 of file class.ilTestQuestionPoolImporter.php.

References ilXmlImporter\getImportDirectory().

Referenced by importXmlRepresentation().

196  {
197  $dir = $this->getImportDirectory();
198  $name = basename($dir);
199  return $name;
200  }
getImportDirectory()
Get import directory.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ importXmlRepresentation()

ilTestQuestionPoolImporter::importXmlRepresentation (   $a_entity,
  $a_id,
  $a_xml,
  $a_mapping 
)

Import XML.

Parameters

Definition at line 27 of file class.ilTestQuestionPoolImporter.php.

References $_POST, $_SESSION, $GLOBALS, $result, ilObjQuestionPool\_setImportDirectory(), ilXmlImporter\getImportDirectory(), getImportDirectoryContainer(), getImportPackageName(), ilObjectFactory\getInstanceByObjId(), IL_MO_PARSE_QTI, and parseXmlFileNames().

28  {
29  include_once "./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php";
31 
32  // Container import => pool object already created
33  if($new_id = $a_mapping->getMapping('Services/Container','objs',$a_id))
34  {
35  $newObj = ilObjectFactory::getInstanceByObjId($new_id,false);
36  $newObj->setOnline(true);
37 
38  $_SESSION['qpl_import_subdir'] = $this->getImportPackageName();
39  }
40  else if ($new_id = $a_mapping->getMapping('Modules/TestQuestionPool','qpl', "new_id"))
41  {
42  $newObj = ilObjectFactory::getInstanceByObjId($new_id,false);
43  }
44  else
45  {
46  // Shouldn't happen
47  $GLOBALS['ilLog']->write(__METHOD__.': non container and no tax mapping, perhaps old qpl export' );
48  return false;
49  }
50 
51 
52 
53  list($xml_file,$qti_file) = $this->parseXmlFileNames();
54 
55  if(!@file_exists($xml_file))
56  {
57  $GLOBALS['ilLog']->write(__METHOD__.': Cannot find xml definition: '. $xml_file);
58  return false;
59  }
60  if(!@file_exists($qti_file))
61  {
62  $GLOBALS['ilLog']->write(__METHOD__.': Cannot find qti definition: '. $qti_file);
63  return false;
64  }
65 
66  $newObj->fromXML($xml_file);
67 
68  // set another question pool name (if possible)
69  if( isset($_POST["qpl_new"]) && strlen($_POST["qpl_new"]) )
70  {
71  $newObj->setTitle($_POST["qpl_new"]);
72  }
73 
74  $newObj->update();
75  $newObj->saveToDb();
76 
77  // FIXME: Copied from ilObjQuestionPoolGUI::importVerifiedFileObject
78  // TODO: move all logic to ilObjQuestionPoolGUI::importVerifiedFile and call
79  // this method from ilObjQuestionPoolGUI and ilTestImporter
80 
81  $GLOBALS['ilLog']->write(__METHOD__.': xml file: '. $xml_file . ", qti file:" . $qti_file);
82 
83  if( isset($_SESSION["qpl_import_idents"]) )
84  {
85  $idents = $_SESSION["qpl_import_idents"];
86  unset($_SESSION["qpl_import_idents"]);
87  }
88  else
89  {
90  $idents = null;
91  }
92 
93  // start parsing of QTI files
94  include_once "./Services/QTI/classes/class.ilQTIParser.php";
95  $qtiParser = new ilQTIParser($qti_file, IL_MO_PARSE_QTI, $newObj->getId(), $idents);
96  $result = $qtiParser->startParsing();
97 
98  // import page data
99  if (strlen($xml_file))
100  {
101  include_once ("./Modules/LearningModule/classes/class.ilContObjParser.php");
102  $contParser = new ilContObjParser($newObj, $xml_file, basename($this->getImportDirectory()));
103  $contParser->setQuestionMapping($qtiParser->getImportMapping());
104  $contParser->startParsing();
105 
106  foreach ($qtiParser->getImportMapping() as $k => $v)
107  {
108  $oldQuestionId = substr($k, strpos($k, 'qst_')+strlen('qst_'));
109  $newQuestionId = $v['pool']; // yes, this is the new question id ^^
110 
111  $a_mapping->addMapping(
112  "Services/Taxonomy", "tax_item", "qpl:quest:$oldQuestionId", $newQuestionId
113  );
114 
115  $a_mapping->addMapping(
116  "Services/Taxonomy", "tax_item_obj_id", "qpl:quest:$oldQuestionId", $newObj->getId()
117  );
118 
119  $a_mapping->addMapping(
120  "Modules/TestQuestionPool", "quest", $oldQuestionId, $newQuestionId
121  );
122  }
123  }
124 
125  $a_mapping->addMapping("Modules/TestQuestionPool", "qpl", $a_id, $newObj->getId());
127 
128  $this->poolOBJ = $newObj;
129  }
Content Object Parser.
$_POST['username']
Definition: cron.php:12
$_SESSION["AccountId"]
$result
getImportDirectory()
Get import directory.
_setImportDirectory($a_import_dir=null)
set import directory
const IL_MO_PARSE_QTI
parseXmlFileNames()
Create qti and xml file name.
getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276
+ Here is the call graph for this function:

◆ parseXmlFileNames()

ilTestQuestionPoolImporter::parseXmlFileNames ( )
protected

Create qti and xml file name.

Returns
array

Definition at line 176 of file class.ilTestQuestionPoolImporter.php.

References $GLOBALS, and ilXmlImporter\getImportDirectory().

Referenced by importXmlRepresentation().

177  {
178  $GLOBALS['ilLog']->write(__METHOD__.': '.$this->getImportDirectory());
179 
180  $basename = basename($this->getImportDirectory());
181 
182  $xml = $this->getImportDirectory().'/'.$basename.'.xml';
183  $qti = $this->getImportDirectory().'/'.preg_replace('/qpl/', 'qti', $basename).'.xml';
184 
185  return array($xml,$qti);
186  }
getImportDirectory()
Get import directory.
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $poolOBJ

ilTestQuestionPoolImporter::$poolOBJ
private

Definition at line 19 of file class.ilTestQuestionPoolImporter.php.


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