コード例 #1
0
 /**
  * updates the internal link ADA-html internal link tag with the new node id to ling to.
  * e.g. <LINK TYPE="INTERNAL" VALUE="8"> will be converted in <LINK TYPE="INTERNAL" VALUE="NEWID">
  *
  * @param int $courseNewID
  *
  * @access private
  */
 private function _updateInternalLinksInNodes($courseNewID)
 {
     $this->_logMessage(__METHOD__ . ' Updating nodes that have an internal link');
     $this->_logMessage(__METHOD__ . ' Timestamp used to select node to update is: ' . $this->_importStartTime);
     $nodesToUpdate = $this->_dh->get_nodes_with_internal_link_for_course($courseNewID, $this->_importStartTime);
     if (!AMA_DB::isError($nodesToUpdate)) {
         $this->_logMessage(__METHOD__ . " Candidates for updating: \n" . print_r($nodesToUpdate, true));
         $this->_logMessage(__METHOD__ . " This is the replacement NODE ids array \n" . print_r($this->_courseNodeIDMapping, true));
         /**
          * build up source and replacements array
          * replacements are going to have a random string as
          * a fake attribute to prevent cyclic substitutions
          * e.g. if we have in text:
          *
          * blablabla... value='1'.... blablabla.... value='7'...blablabla value='1'...
          *
          * and in the mapping array: 1=>7 .... 7=>23....
          *
          * the result will be that all 1 become 7, and all 7 become 23 and at the and
          * all of the three links will point to 23.
          */
         $randomStr = '#' . substr(md5(time()), 0, 8);
         $prefix = '<LINK TYPE="INTERNAL" VALUE="';
         $suffix = '">';
         $suffix2 = '"' . $randomStr . '>';
         $search = array();
         $replace = array();
         foreach ($this->_courseNodeIDMapping as $oldID => $newID) {
             $oldID = str_replace($this->_courseOldID . self::$courseSeparator, '', $oldID);
             $newID = str_replace($courseNewID . self::$courseSeparator, '', $newID);
             $search[] = $prefix . $oldID . $suffix;
             $replace[] = $prefix . $newID . $suffix2;
         }
         foreach ($nodesToUpdate as $arrElem) {
             foreach ($arrElem as $nodeID) {
                 $this->_logMessage(__METHOD__ . ' UPDATING NODE id=' . $nodeID);
                 $nodeInfo = $this->_dh->get_node_info($nodeID);
                 $nodeInfo['text'] = str_ireplace($search, $replace, $nodeInfo['text']);
                 // strip off the random fake attribute
                 $nodeInfo['text'] = str_ireplace($randomStr, '', $nodeInfo['text']);
                 $this->_dh->set_node_text($nodeID, $nodeInfo['text']);
             }
         }
     }
 }