$domtree = new DOMDocument('1.0', ADA_CHARSET); $domtree->preserveWhiteSpace = false; $domtree->formatOutput = true; // generate and add comment, if any if (isset($commentStr)) { $domtree->appendChild($domtree->createComment($commentStr)); unset($commentStr); } // create the root element of the xml tree $xmlRoot = $domtree->createElement("ada_export"); $xmlRoot->setAttribute("exportDate", date('r')); // append it to the document created $xmlRoot = $domtree->appendChild($xmlRoot); foreach ($nodesToExport as $course_id => $nodeList) { // need an Import/Export DataHandler $dh = AMAImpExportDataHandler::instance(MultiPort::getDSN($_SESSION['sess_selected_tester'])); $course_data = $dh->get_course($course_id); if (!empty($course_data) && !AMA_DB::isError($course_data)) { // create node for current course $XMLcourse = $domtree->createElement('modello_corso'); $XMLcourse->setAttribute('exportedId', $course_id); // set course model datas foreach ($course_data as $name => $value) { $name = strtolower($name); if ($name === 'id_autore') { continue; } else { if (in_array($name, exportHelper::$cDataElementNameForCourse)) { $XMLElementForCourse = $exportHelper->buildCDATASection($domtree, $name, $value); } else { if ($name === 'id_lingua') {
/** * runs the actual import * * @return Ambigous AMA_Error on error |array recpArray on success * * @access public */ public function runImport() { $count = 0; $zipFileName = ADA_UPLOAD_PATH . $this->_importFile; $zip = new ZipArchive(); if ($zip->open($zipFileName)) { $XMLfile = $zip->getFromName(XML_EXPORT_FILENAME); $XMLObj = new SimpleXMLElement($XMLfile); $this->_progressResetValues(substr_count($XMLfile, '</nodo>') + substr_count($XMLfile, '<survey ') + substr_count($XMLfile, '</test>')); foreach ($XMLObj as $objName => $course) { // first level object must be 'modello_corso' if ($objName === 'modello_corso') { $count++; // get the attributes as local vars // e.g. attributed exportedId=107 becomes // a local var named $exportedId, initialized to 107 as a string foreach ($course->attributes() as $name => $val) { ${$name} = (string) $val; } // as a result of this foreach we have a php var for any XML object attribute // var_dump ($exportedId); should neither raise an error nor dump a null value. $this->_courseOldID = $exportedId; /** * sets the log file name that will be used from now on! */ $this->_logFile = MODULES_IMPEXPORT_LOGDIR . "import-" . $this->_courseOldID . "_" . date('d-m-Y_His') . ".log"; $this->_logMessage('**** IMPORT STARTED at ' . date('d/m/Y H:i:s') . '(timestamp: ' . $this->_dh->date_to_ts('now') . ') ****'); $this->_progressSetTitle((string) $course->titolo); /** * ADDS THE COURSE TO THE APPROPIATE TABLES */ if (!self::$_DEBUG) { if (is_null($this->_selectedCourseID)) { $courseNewID = $this->_add_course($course); /** * this is a new course you want, first node * is going to be the root of the course (i.e. zero) * Setting selectedNodeID will make the running code * do the trick! */ $this->_selectedNodeID = null; } else { $courseNewID = $this->_selectedCourseID; } if (AMA_DB::isError($courseNewID)) { return $courseNewID; } } else { $courseNewID = 123 * $count; } /** * NOW ADD NODES, TESTS AND SURVEYS */ foreach ($this->_specialNodes as $groupName) { $method = '_import' . ucfirst(strtolower($groupName)); $this->_logMessage(__METHOD__ . ' Saving ' . $groupName . ' by calling method: ' . $method); if ($groupName === 'tests' || $groupName === 'surveys') { // prepares the mapping array by emptying it if ($groupName === 'tests') { if (isset($this->_testNodeIDMapping)) { unset($this->_testNodeIDMapping); } $this->_testNodeIDMapping = array(); } // prepares the test data handler $this->_dh->disconnect(); $this->_dh = AMATestDataHandler::instance(MultiPort::getDSN($this->_selectedTester)); } /** * calls a method named _import<groupName> foreach special node. * e.g. for nodes it will call _importNodi, for tests _importTests.... */ if (method_exists($this, $method) && !empty($course->{$groupName})) { $specialVal = $this->{$method}($course->{$groupName}, $courseNewID); // if it's an error return it right away if (AMA_DB::isError($specialVal)) { $this->_logMessage(__METHOD__ . ' Error saving ' . $groupName . '. DB returned the following:'); $this->_logMessage(print_r($specialVal, true)); return $specialVal; } else { $this->_logMessage(__METHOD__ . ' Saving ' . $groupName . ' successfully ended'); $this->_recapArray[$courseNewID][$groupName] = $specialVal; } } if ($groupName === 'nodi') { // save all the links and clean the array $this->_saveLinks($courseNewID); // after links have been saved, update inernal links pseudo html in proper nodes $this->_updateInternalLinksInNodes($courseNewID); } else { if ($groupName === 'tests' || $groupName === 'surveys') { // restores the import/export data handler $this->_dh->disconnect(); $this->_dh = AMAImpExportDataHandler::instance(MultiPort::getDSN($this->_selectedTester)); if ($groupName === 'tests') { $this->_updateTestLinksInNodes($courseNewID); } } } } // $this->_updateTestLinksInNodes ( $courseNewID ); } // if ($objName === 'modello_corso') $this->_logMessage('**** IMPORT ENDED at ' . date('d/m/Y H:i:s') . '(timestamp: ' . $this->_dh->date_to_ts('now') . ') ****'); $this->_logMessage('If there\'s no zip log below, this is a multi course import: pls find unzip log at the end of the last course log'); } // foreach ($XMLObj as $objName=>$course) // extract the zip files to the appropriate media dir $this->_unzipToMedia($zip); $zip->close(); if (!self::$_DEBUG) { unlink($zipFileName); } } $this->_progressDestroy(); return $this->_recapArray; }