Beispiel #1
0
function theme_AddMyIdeaWithLimit($idea, $node, $user, $limit)
{
    db_Connect();
    // Only because we're doing native DB ops, call connect //
    global $db;
    $db->begin_transaction();
    $count = 0;
    try {
        $count = theme_CountMyIdeas($node, $user, " FOR UPDATE");
        if ($count === false) {
            throw new Exception();
        }
        if ($count >= $limit) {
            throw new Exception();
        }
        $result = db_DoInsert("INSERT INTO " . CMW_TABLE_THEME_IDEA . " (\n\t\t\t\ttheme, node, user, `timestamp`\n\t\t\t)\n\t\t\tVALUES ( \n\t\t\t\t?, ?, ?, NOW()\n\t\t\t)", $idea, $node, $user);
        if (empty($result)) {
            throw new Exception();
        }
        $count = theme_CountMyIdeas($node, $user);
        if ($count === false) {
            throw new Exception();
        }
        if ($count > $limit) {
            throw new Exception();
        }
        // We're good! Commit! We're finished //
        $db->commit();
        return ["id" => $result, "count" => $count];
    } catch (Exception $ex) {
        // Bad! Do a rollback! //
        $db->rollback();
        return ["id" => 0, "count" => $count];
    }
}
Beispiel #2
0
         $response = theme_AddMyIdeaWithLimit($idea, $EVENT_NODE, $user_id, $max_themes);
         if ($response['id'] !== 0) {
             $response['idea'] = $idea;
         }
     } else {
         $response['id'] = 0;
     }
 } else {
     if ($action == "REMOVE" && IsThemeSuggestionsOpen()) {
         $theme_id = intval($_POST['id']);
         if ($theme_id > 0) {
             $ret = theme_RemoveMyIdea($theme_id, $user_id);
             if ($ret) {
                 $response['id'] = $theme_id;
             }
             $response['count'] = theme_CountMyIdeas($EVENT_NODE, $user_id);
         } else {
             $response['id'] = 0;
         }
     } else {
         if ($action == "IDEA" && IsThemeSlaughterOpen()) {
             $theme_id = intval($_POST['id']);
             $value = intval($_POST['value']);
             if ($theme_id > 0 && $value <= 1 && $value >= -1) {
                 $id_list = theme_GetIdeaList($EVENT_NODE);
                 // Confirm theme is on the list //
                 if (isset($id_list[$theme_id])) {
                     $response['id'] = theme_AddIdeaVote($theme_id, $value, $user_id);
                     $response['idea_id'] = $theme_id;
                 } else {
                     $response['id'] = 0;