コード例 #1
0
 /**
  * Iterative method saving the surveys entries in the DB
  *
  * @param SimpleXMLElement $xml the element from which the recursion starts (i.e. root node)
  * @param int $courseNewID the generated ID of the imported course
  *
  * @return boolean on debug |AMA_Error on error |int number of imported nodes on success
  *
  * @access private
  */
 private function _importSurveys($xml, $courseNewID)
 {
     $count = 0;
     if (self::$_DEBUG) {
         echo '<pre>' . __METHOD__ . PHP_EOL;
     }
     foreach ($xml->children() as $survey) {
         foreach ($survey->attributes() as $name => $value) {
             // export every xml <survey> tag attribute as a local var
             ${$name} = (string) $value;
         }
         // if the test referenced by the id_nodoTestEsportato is not set
         // there's no corresponding test in the DB and we cannot save :(
         if (isset($this->_testNodeIDMapping[$id_nodoTestEsportato])) {
             if (!self::$_DEBUG) {
                 // saves the survey row in the DB
                 $this->_logMessage(__METHOD__ . ' Saving survey: id_corso=' . $courseNewID . ' id_test=' . $this->_testNodeIDMapping[$id_nodoTestEsportato] . ' id_nodo=' . $courseNewID . self::$courseSeparator . $id_nodo);
                 $surveyResult = $this->_dh->test_addCourseTest($courseNewID, $this->_testNodeIDMapping[$id_nodoTestEsportato], $courseNewID . self::$courseSeparator . $id_nodo);
             } else {
                 // prints out some basic info if in debug mode
                 print_r("id_corso=" . $courseNewID . PHP_EOL);
                 print_r("id_test=" . $this->_testNodeIDMapping[$id_nodoTestEsportato] . PHP_EOL);
                 print_r("id_nodo=" . $courseNewID . self::$courseSeparator . $id_nodo . PHP_EOL);
                 $surveyResult = true;
             }
             // if it's an error return it right away, as usual
             if (AMA_DB::isError($surveyResult)) {
                 $this->_logMessage(__METHOD__ . ' Error saving survey. DB returned the following:');
                 $this->_logMessage(print_r($surveyResult, true));
                 return $surveyResult;
             } else {
                 $count++;
                 $this->_progressIncrement();
                 $this->_logMessage(__METHOD__ . ' Successfully saved survey');
             }
         }
     }
     if (self::$_DEBUG) {
         echo '</pre>';
     }
     return $count;
 }