Пример #1
0
         exit;
     }
 }
 //end addition of repertorie
 $arrayCategories = array();
 $list = array();
 $cat_tree = array();
 $arrSelectedBox = array();
 $arrSelectedDetails = array();
 $resultAll = $modelGeneral->fetchAll($queryAll, array($_SESSION['user']['id'], $_GET['id']), $t);
 if (!empty($resultAll)) {
     foreach ($resultAll as $k => $v) {
         $mid = $v['move_id'];
         $cat_parent_id = $v['parent_id'];
         $arrayCategories[$mid] = array("parent_id" => $cat_parent_id, "name" => $v['move'], "details" => $v);
         $cat_tree = chess_tree_add($cat_tree, $cat_parent_id, $v, $mid);
     }
     if (!empty($move_id)) {
         list($arrSelectedBox, $arrSelectedDetails) = display_parent_nodes($move_id, $arrayCategories);
     }
 }
 if (!empty($_GET['del'])) {
     $queryDel = "DELETE FROM chess_repertorie_moves WHERE move_id = ? AND repertory_id = ? AND uid = ?";
     $modelGeneral->deleteDetails($queryDel, array($_GET['del'], $_GET['id'], $_SESSION['user']['id']));
     delete_child_nodes($_GET['del'], $arrayCategories, $modelGeneral, $_GET['id'], $_SESSION['user']['id']);
     $modelGeneral->clearCache($query, array($_SESSION['user']['id'], $_GET['id']));
     $modelGeneral->clearCache($queryChessMoves, array($_SESSION['user']['id'], $_GET['id'], $parent_id));
     $modelGeneral->clearCache($queryChessCurrentMove, array($_SESSION['user']['id'], $_GET['id'], $move_id));
     $modelGeneral->clearCache($queryAll, array($_SESSION['user']['id'], $_GET['id']));
     header("Location: " . HTTPPATH . "/chess/repertorie/{$pageUrl}?id=" . $_GET['id'] . "&move_id=" . $move_id . "&parent_id=" . $move_id);
     exit;
Пример #2
0
function chess_tree_add($tree, $parent_id, $object, $move_id)
{
    if ($parent_id == 0 and $object['move_id'] == $move_id) {
        $tree[$object['move_id']] = $object;
        return $tree;
    }
    if ($tree) {
        foreach ($tree as $key => $value) {
            $current = $tree[$key];
            // If this is the parent, add the object to it's children array
            if ($current['move_id'] == $parent_id) {
                $tree[$key]['children'][$object['move_id']] = $object;
            } else {
                // If it's not in this level, look a level deeper on the current object.
                $tree[$key]['children'] = chess_tree_add($current['children'], $parent_id, $object, $move_id);
            }
        }
    }
    return $tree;
}