public function stack_delete_card($card_id) { $this->stack_will_be_modified(); $next_card_id = null; $this->file_db->beginTransaction(); $stmt = $this->file_db->prepare('SELECT bkgnd_id, card_seq FROM card WHERE card_id=?'); Stack::sl_ok($stmt, $this->file_db, 'Deleting Card (1)'); Stack::sl_ok($stmt->execute(array(intval($card_id))), $this->file_db, 'Deleting Card (2)'); $row = $stmt->fetch(PDO::FETCH_NUM); Stack::sl_ok($row, $this->file_db, 'Deleting Card (3)'); $bkgnd_id = $row[0]; $existing_seq = $row[1]; $stmt = $this->file_db->prepare('SELECT COUNT(card.card_id) FROM card WHERE bkgnd_id=?'); Stack::sl_ok($stmt, $this->file_db, 'Deleting Card (4)'); Stack::sl_ok($stmt->execute(array(intval($bkgnd_id))), $this->file_db, 'Deleting Card (5)'); $row = $stmt->fetch(PDO::FETCH_NUM); Stack::sl_ok($row, $this->file_db, 'Deleting Card (6)'); $bkgnd_count = $row[0]; $cleanup_bkgnd = $bkgnd_count == 1; $stmt = $this->file_db->prepare('SELECT COUNT(card.card_id) FROM card'); Stack::sl_ok($stmt, $this->file_db, 'Deleting Card (7)'); Stack::sl_ok($stmt->execute(), $this->file_db, 'Deleting Card (8)'); $row = $stmt->fetch(PDO::FETCH_NUM); Stack::sl_ok($row, $this->file_db, 'Deleting Card (9)'); $stack_count = $row[0]; if ($stack_count == 1) { Stack::sl_ok(false, null, 'Deleting Card (10); Last Card in Stack'); } $stmt = $this->file_db->prepare('DELETE FROM card WHERE card_id=?'); Stack::sl_ok($stmt, $this->file_db, 'Deleting Card (11)'); $rows = $stmt->execute(array(intval($card_id))); if ($rows === 0) { $rows = false; } Stack::sl_ok($rows, $this->file_db, 'Deleting Card (12)'); $stmt = $this->file_db->prepare('UPDATE card SET card_seq=card_seq-10 WHERE card_seq>?'); Stack::sl_ok($stmt, $this->file_db, 'Deleting Card (13)'); Stack::sl_ok($stmt->execute(array(intval($existing_seq))), $this->file_db, 'Deleting Card (14)'); if ($cleanup_bkgnd) { $stmt = $this->file_db->prepare('DELETE FROM bkgnd WHERE bkgnd_id=?'); Stack::sl_ok($stmt, $this->file_db, 'Deleting Bkgnd (1)'); $rows = $stmt->execute(array($bkgnd_id)); if ($rows === 0) { $rows = false; } Stack::sl_ok($rows, $this->file_db, 'Deleting Bkgnd (2)'); } $stmt = $this->file_db->prepare('SELECT card_id FROM card WHERE card_seq=?'); Stack::sl_ok($stmt, $this->file_db, 'Deleting Card (15)'); Stack::sl_ok($stmt->execute(array(intval($existing_seq))), $this->file_db, 'Deleting Card (16)'); $row = $stmt->fetch(PDO::FETCH_NUM); if ($row) { $next_card_id = $row[0]; } else { $next_card_id = $this->stack_get_first_card_id(); } $this->file_db->commit(); return $next_card_id; }
public function zap_all_cards() { CinsImpError::unimplemented(); // UNTIL REFACTORED, DISABLED $this->stack_will_be_modified(); $stmt = $this->file_db->prepare('DELETE FROM card'); Stack::sl_ok($stmt, $this->file_db, 'Deleting All Cards (1)'); $rows = $stmt->execute(); Stack::sl_ok($rows, $this->file_db, 'Deleting All Cards (2)'); $stmt = $this->file_db->prepare('DELETE FROM bkgnd'); Stack::sl_ok($stmt, $this->file_db, 'Deleting All Cards (3)'); $rows = $stmt->execute(); Stack::sl_ok($rows, $this->file_db, 'Deleting All Cards (4)'); }