/** * Saves into the DB all the intrenal links between nodes. * Before adding the row to the DB, it maps the exported * id nodes to the imported ones. That's the reason why * this must be execute AFTER all nodes have been imported. * * @param int $courseNewID */ private function _saveLinks($courseNewID) { if (is_array($this->_linksArray)) { $this->_logMessage(__METHOD__ . ' Saving internal links for course'); foreach ($this->_linksArray as $num => $linkArray) { if (isset($this->_courseNodeIDMapping[$linkArray['id_nodo']]) && isset($this->_courseNodeIDMapping[$linkArray['id_nodo_to']])) { $linkArray['id_nodo'] = $this->_courseNodeIDMapping[$linkArray['id_nodo']]; $linkArray['id_nodo_to'] = $this->_courseNodeIDMapping[$linkArray['id_nodo_to']]; $res = $this->_dh->add_link($linkArray); if (!AMA_DB::isError($res)) { if (!isset($this->_recapArray[$courseNewID]['links'])) { $this->_recapArray[$courseNewID]['links'] = 1; } else { $this->_recapArray[$courseNewID]['links']++; } $this->_logMessage(__METHOD__ . ' link # ' . $num . ' successfully saved. id_nodo=' . $linkArray['id_nodo'] . ' id_nodo_to=' . $linkArray['id_nodo_to']); } else { $this->_logMessage(__METHOD__ . ' link # ' . $num . ' FAILED! id_nodo=' . $linkArray['id_nodo'] . ' id_nodo_to=' . $linkArray['id_nodo_to']); } } else { $this->_logMessage(__METHOD__ . ' could not find a match in the mapping array. id_nodo=' . $linkArray['id_nodo'] . ' id_nodo_to=' . $linkArray['id_nodo_to']); } } } else { $this->_logMessage(__METHOD__ . ' No links to be saved this time'); } $this->_linksArray = null; }
$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') {