public function testBuildTreePrunesAndInserts() { $tree = array(array('id' => 1, 'name' => 'A'), array('id' => 2, 'name' => 'B'), array('id' => 3, 'name' => 'C', 'children' => array(array('id' => 4, 'name' => 'C.1', 'children' => array(array('id' => 5, 'name' => 'C.1.1'), array('id' => 6, 'name' => 'C.1.2'))), array('id' => 7, 'name' => 'C.2'), array('id' => 8, 'name' => 'C.3'))), array('id' => 9, 'name' => 'D')); $this->assertTrue(Category::buildTree($tree)); $this->assertTrue(Category::isValidNestedSet()); // Postgres fix if (DB::connection()->getDriverName() === 'pgsql') { $tablePrefix = DB::connection()->getTablePrefix(); $sequenceName = $tablePrefix . 'categories_id_seq'; DB::connection()->statement('ALTER SEQUENCE ' . $sequenceName . ' RESTART WITH 10'); } $updated = array(array('id' => 1, 'name' => 'A'), array('id' => 2, 'name' => 'B'), array('id' => 3, 'name' => 'C', 'children' => array(array('id' => 4, 'name' => 'C.1', 'children' => array(array('id' => 5, 'name' => 'C.1.1'), array('id' => 6, 'name' => 'C.1.2'))), array('id' => 7, 'name' => 'C.2', 'children' => array(array('name' => 'C.2.1'), array('name' => 'C.2.2'))))), array('id' => 9, 'name' => 'D')); $this->assertTrue(Category::buildTree($updated)); $this->assertTrue(Category::isValidNestedSet()); $expected = array(array('id' => 1, 'name' => 'A'), array('id' => 2, 'name' => 'B'), array('id' => 3, 'name' => 'C', 'children' => array(array('id' => 4, 'name' => 'C.1', 'children' => array(array('id' => 5, 'name' => 'C.1.1'), array('id' => 6, 'name' => 'C.1.2'))), array('id' => 7, 'name' => 'C.2', 'children' => array(array('id' => 10, 'name' => 'C.2.1'), array('id' => 11, 'name' => 'C.2.2'))))), array('id' => 9, 'name' => 'D')); $hierarchy = Category::all()->toHierarchy()->toArray(); $this->assertArraysAreEqual($expected, array_ints_keys(hmap($hierarchy, array('id', 'name')))); }
$query_relations = sprintf("DELETE FROM %sfaqcategoryrelations WHERE category_id = %d AND category_lang = '%s'", SQLPREFIX, $id, $lang); if ($db->query($query_cateories) && $db->query($query_relations)) { printf('<p>%s</p>', $PMF_LANG['ad_categ_deleted']); } else { printf('<p>%s</p>', $db->error()); } } // Lists all categories if (isset($_POST['language'])) { $lang = $_POST['language']; } else { $lang = $LANGCODE; } $currentLink = $_SERVER['PHP_SELF'] . $linkext; $tree = new Category($lang); $tree->buildTree(); foreach ($tree->catTree as $cat) { $indent = ''; for ($i = 0; $i < $cat['indent']; $i++) { $indent .= ' '; } printf("%s<strong style=\"vertical-align: top;\">· %s</strong> ", $indent, $cat["name"]); printf('<a href="%s&aktion=addcategory&cat=%s" title="%s"><img src="images/add.gif" width="17" height="18" alt="%s" title="%s" border="0" /></a>', $currentLink, $cat['id'], $PMF_LANG['ad_kateg_add'], $PMF_LANG['ad_kateg_add'], $PMF_LANG['ad_kateg_add']); printf('<a href="%s&aktion=editcategory&cat=%s" title="%s"><img src="images/edit.gif" width="18" height="18" border="0" title="%s" alt="%s" /></a>', $currentLink, $cat['id'], $PMF_LANG['ad_kateg_rename'], $PMF_LANG['ad_kateg_rename'], $PMF_LANG['ad_kateg_rename']); if (count($tree->getChildren($cat['id'])) == 0) { printf('<a href="%s&aktion=deletecategory&cat=%s&lang=%s" title="%s"><img src="images/delete.gif" width="17" height="18" alt="%s" title="%s" border="0" /></a>', $currentLink, $cat['id'], $cat['lang'], $PMF_LANG['ad_categ_delete'], $PMF_LANG['ad_categ_delete'], $PMF_LANG['ad_categ_delete']); } printf('<a href="%s&aktion=cutcategory&cat=%s" title="%s"><img src="images/cut.gif" width="16" height="16" alt="%s" border="0" title="%s" /></a>', $currentLink, $cat['id'], $PMF_LANG['ad_categ_cut'], $PMF_LANG['ad_categ_cut'], $PMF_LANG['ad_categ_cut']); printf('<a href="%s&aktion=movecategory&cat=%s&parent_id=%s" title="%s"><img src="images/move.gif" width="16" height="16" alt="%s" border="0" title="%s" /></a>', $currentLink, $cat['id'], $cat['parent_id'], $PMF_LANG['ad_categ_move'], $PMF_LANG['ad_categ_move'], $PMF_LANG['ad_categ_move']); print "<br />"; }