Exemple #1
0
function calcNewPortfolioSort($currentSort, $up)
{
    $sorts = array_map("extractSort", readPortfolioDb());
    array_unshift($sorts, 0);
    //in case move to the top
    array_push($sorts, end($sorts) + 10000);
    //in case move to the bottom
    $currentLoc = array_search($currentSort, $sorts);
    $nearLoc = min(max($currentLoc + ($up ? -1 : 1), 1), count($sorts) - 2);
    $farLoc = min(max($currentLoc + ($up ? -2 : 2), 0), count($sorts) - 1);
    logEvent("move-image", $currentLoc - 1, $currentSort);
    return floor(($sorts[$nearLoc] + $sorts[$farLoc]) / 2);
}
Exemple #2
0
function restRequestPortfolio($action, $id)
{
    $actions = array("create" => function ($id) {
        return restError(400);
    }, "get" => function ($id) {
        return restError(501);
    }, "update" => function ($id) {
        return updatePortfolio($id);
    }, "delete" => function ($id) {
        return deletePortfolio($id);
    }, "list" => function ($id) {
        return readPortfolioDb();
    });
    return $actions[$action]($id);
}