ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilSurveyImporter.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once("./Services/Export/classes/class.ilXmlImporter.php");
5 
14 {
21  function importXmlRepresentation($a_entity, $a_id, $a_xml, $a_mapping)
22  {
23  // Container import => test object already created
24  if($new_id = $a_mapping->getMapping('Services/Container','objs',$a_id))
25  {
26  $newObj = ilObjectFactory::getInstanceByObjId($new_id,false);
27  #$newObj->setImportDirectory(dirname(rtrim($this->getImportDirectory(),'/')));
28  }
29  else // case ii, non container
30  {
31  // Shouldn't happen
32  $GLOBALS['ilLog']->write(__METHOD__.': Called in non container mode');
33  return false;
34  }
35 
36 
37  include_once "./Services/Survey/classes/class.SurveyImportParser.php";
38  include_once "./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
39 
40  list($xml_file) = $this->parseXmlFileNames();
41 
42  if(!@file_exists($xml_file))
43  {
44  $GLOBALS['ilLog']->write(__METHOD__.': Cannot find xml definition: '. $xml_file);
45  return false;
46  }
47 
48  $pool_ref = $a_mapping->getMapping('Services/Container','spl',$newObj->getId());
49  $pool_obj = ilObject::_lookupObjId($pool_ref);
50 
51  $spl = new ilObjSurveyQuestionPool($pool_obj, FALSE);
52  $import = new SurveyImportParser($spl, $xml_file, TRUE);
53  $import->setSurveyObject($newObj);
54  $import->startParsing();
55 
56  // Finally delete tmp question pool
57  if($spl->getType() == 'spl')
58  {
59  $spl->delete();
60  }
61 
62  $a_mapping->addMapping("Modules/Survey", "svy", $a_id, $newObj->getId());
63 
64  return true;
65 
66  }
67 
68 
73  protected function parseXmlFileNames()
74  {
75  $GLOBALS['ilLog']->write(__METHOD__.': '.$this->getImportDirectory());
76 
77  $basename = basename($this->getImportDirectory());
78  $xml = $this->getImportDirectory().'/'.$basename.'.xml';
79 
80  return array($xml);
81  }
82 }
83 
84 ?>