function importTopicTree($lines, $language) { debug("START import topic tree", $language); // read in topic tree definition reset($lines); $more = true; while ($more) { $line = array_shift($lines); if (preg_match('/^\\s*$/', $line) || preg_match('/^#/', $line)) { $more = false; } else { if (preg_match('/^\\s*([\\w_]+)\\s*=\\s*(.*)/', $line, $items)) { $treedata[$items[1]] = trim($items[2]); } else { logError("Bad line: {$line}"); } } } debug("tree data", $treedata); if (!$treedata['tree_id'] || !$treedata['name']) { raiseError("bad topic tree definition"); } $treeId = $treedata['tree_id']; // create tree def $td =& new sotf_NodeObject("sotf_topic_trees"); $td->setID(sotf_NodeObject::makeId($treeId, $td->tablename, 0)); $td->find(); $td->set('tree_id', $treeId); $td->set('name', $treedata['shortname']); if ($td->exists()) { $langs = $td->get('languages'); if (strpos($langs, $language) === FALSE) { $td->set('languages', $langs . ",{$language}"); $td->update(); } } else { $td->set('languages', $language); $td->create(); } // create root description $x = new sotf_NodeObject("sotf_topic_tree_defs"); $x->setID(sotf_NodeObject::makeId($treeId, $x->tablename, 0)); $x->find(); if (!$x->exists()) { $x->set('supertopic', 0); $x->set('name', $treedata['name']); $x->set('tree_id', $treeId); $x->create(); } $rootId = $x->getID(); // create root translation $y = new sotf_NodeObject("sotf_topics"); $y->setID(sotf_NodeObject::makeId($treeId, $y->tablename, '0' . $language)); $y->find(); if (!$y->exists()) { $y->set('topic_id', $rootId); $y->set('language', $language); $y->set('topic_name', $treedata['name']); $y->set('description', $treedata['description']); $y->create(); } $parentId = $rootId; $prevId = $rootId; $level = 0; reset($lines); while (list(, $line) = each($lines)) { if (preg_match('/^\\s*$/', $line) || preg_match('/^#/', $line)) { continue; } if (!preg_match('/^\\s*(\\d+)\\s+(\\d+)\\s+(.*)/', $line, $items)) { logError("bad line syntax: {$line}"); continue; } //$items = preg_split('/\s+/', $line, PREG_SPLIT_NO_EMPTY); debug("tree items", $items); $id = $items[1]; $l = $items[2]; $name = trim($items[3]); if ($level < $l) { $roots[] = $parentId; $parentId = $prevId; } if ($level > $l) { $parentId = array_pop($roots); } $level = $l; debug("", "LEVEL: {$level}, PARENT: {$parentId}, ROOTS: " . join(",", $roots)); $x = new sotf_NodeObject("sotf_topic_tree_defs"); $x->setID(sotf_NodeObject::makeId($treeId, $x->tablename, $id)); $x->find(); if (!$x->exists()) { $x->set('supertopic', $parentId); $x->set('name', $name); $x->set('tree_id', $treeId); $x->create(); } $tid = $x->getID(); $y = new sotf_NodeObject("sotf_topics"); $y->setID(sotf_NodeObject::makeId($treeId, $y->tablename, $id . $language)); //$y->find(); $y->set('topic_id', $tid); $y->set('language', $language); $y->set('topic_name', $name); $y->create(); $prevId = $tid; } debug("END import topic tree", $language); }
$find = sotf_Utils::getParameter('find'); $add = sotf_Utils::getParameter('add'); if ($name != "") { $x = new sotf_NodeObject("sotf_topic_tree_defs"); $x->set('supertopic', $parent); $x->set('name', $name); $x->create(); $id = $x->getID(); } if ($topic_name != "") { $x = new sotf_NodeObject("sotf_topics"); $x->set('topic_id', $topic_id); $x->set('language', "en"); $x->set('topic_name', $topic_name); $x->create(); $id = $x->getID(); print $id; } if ($topic_counter != "") { $x = new sotf_Object("sotf_topics_counter"); $x->set('topic_id', $topic_id); $x->set('number', $topic_counter); $x->create(); $id = $x->getID(); print $id; } $query = "SELECT sotf_topic_tree_defs.*, sotf_topics.topic_name, sotf_topics_counter.number from sotf_topic_tree_defs" . " LEFT JOIN sotf_topics ON sotf_topics.topic_id = sotf_topic_tree_defs.id" . " LEFT JOIN sotf_topics_counter ON sotf_topics_counter.topic_id = sotf_topic_tree_defs.id"; $result = $db->getAll($query); usort($result, "SORTIT"); $parentid; $counter = 0;
function addChild($parent, $name, $topic_name = "", $lang = "en", $treeId = 2) { $x = new sotf_NodeObject("sotf_topic_tree_defs"); $x->set('supertopic', $parent); $x->set('name', $name); $x->set('tree_id', $treeId); $x->create(); $id = $x->getID(); if ($topic_name != "") { $y = new sotf_NodeObject("sotf_topics"); $y->set('topic_id', $id); $y->set('language', $lang); $y->set('topic_name', $topic_name); $y->create(); //print($id); } return $x->getID(); }