function del_todo($todoId)
{
    global $todosDB;
    init_todos_db();
    $data = $todosDB;
    //map
    for ($i = 0; $i < count($data['todos']); $i++) {
        if ($data['todos'][$i]['id'] == $todoId) {
            array_splice($data['todos'], $i, 1);
        }
    }
    //var_dump($data);
    //die();
    $filename = __DIR__ . "/../data/" . $_SESSION['CURRENT_USER'] . ".json";
    file_put_contents($filename, json_encode($data));
}
Exemplo n.º 2
0
function generate_todo_id()
{
    global $todosDB;
    //ensure db is initialized and available
    init_todos_db();
    $id = $todosDB["nextId"];
    todolog("json_data_access.php | pulled todo id: {$id}");
    return $id;
}
Exemplo n.º 3
0
function update_todo_list($taskId, $desc, $status)
{
    global $todosDB;
    init_todos_db();
    $data = $todosDB;
    //find the resord and update it's inforamtion
    for ($i = 0; $i < count($data['todos']); $i++) {
        if ($data['todos'][$i]['id'] == $taskId) {
            $data['todos'][$i]['desc'] = $desc;
            $data['todos'][$i]['status'] = $status;
        }
    }
    //update the josn file
    $currentUserId = get_current_user_id();
    $filename = __DIR__ . "/../data/{$currentUserId}.json";
    file_put_contents($filename, json_encode($data));
}