Example #1
0
File: tag.php Project: rjha/sc
    exit;
}
$postId = Util::getArrayKey($_POST, "postId");
// Action from UI is ADD | REMOVE
// see com\indigloo\sc\ui\Constants file
$action = Util::getArrayKey($_POST, "action");
$postDao = new \com\indigloo\sc\dao\Post();
$message = NULL;
try {
    switch ($action) {
        case UIConstants::FEATURE_POST:
            $postDao->feature($postId);
            $message = sprintf("success! item %s added to featured posts", $postId);
            break;
        case UIConstants::UNFEATURE_POST:
            $postDao->unfeature($postId);
            $message = sprintf("success! item %s removed from featured posts", $postId);
            break;
        default:
            trigger_error("Unknown UI action", E_USER_ERROR);
    }
} catch (DBException $ex) {
    //duplicate entry?
    if ($ex->getCode() == AppConstants::DUPKEY_ERROR_CODE) {
        $html = array("code" => 500, "message" => "Duplicate error: member is already in set!");
        $html = json_encode($html);
        echo $html;
        exit;
    } else {
        throw $ex;
    }