コード例 #1
0
 /**
  * updates the links to the test nodes inside the testo fields of the node
  * the id of the test MUST be substituted with the generated ones
  *
  * @param int $courseNewID
  *
  * @access private
  */
 private function _updateTestLinksInNodes($courseNewID)
 {
     $this->_logMessage(__METHOD__ . ' Updating nodes that have a link to a test:');
     $nodesToUpdate = $this->_dh->get_nodes_with_test_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 TEST ids array \n" . print_r($this->_testNodeIDMapping, true));
         $delimiter = '#';
         $regExp = '/' . preg_quote('id_test=', '/') . '(\\d+)' . '/';
         $search = array();
         $replace = array();
         foreach ($this->_testNodeIDMapping as $oldID => $newID) {
             $search[] = 'id_test=' . $oldID . $delimiter;
             $replace[] = 'id_test=' . $newID;
         }
         foreach ($nodesToUpdate as $arrElem) {
             foreach ($arrElem as $nodeID) {
                 $this->_logMessage(__METHOD__ . ' UPDATING NODE id=' . $nodeID);
                 $nodeInfo = $this->_dh->get_node_info($nodeID);
                 /**
                  * First put a delimiter just after the linked id_test to prevent
                  * this situation:
                  * 	id_test=2 ..blablabla... id_test=24
                  * without an end delimiter, how can you subsitute id_test=2
                  * BUT NOT id_test=24 ???
                  * 
                  * NOTE: This is done in the 3rd argument of str_ireplace
                  */
                 $nodeInfo['text'] = str_ireplace($search, $replace, preg_replace($regExp, 'id_test=$1' . $delimiter, $nodeInfo['text']));
                 $this->_dh->set_node_text($nodeID, $nodeInfo['text']);
             }
         }
     } else {
         $this->_logMessage(__METHOD__ . ' Error in retreiving nodes to be updated: ' . $nodesToUpdate->getMessage());
     }
 }