Response::fail($message, $data); } if ($reserved_by === $currentUser->id) { Response::fail("You've already reserved this {$type}"); } if ($Post->isOverdue()) { $message = "This post was reserved " . Time::tag($Post->reserved_at) . " so anyone's free to reserve it now."; $checkIfUserCanReserve($message, $data, 'overdue'); Response::fail($message, $data); } Users::reservationLimitExceeded(); if (!$Post->isTransferable()) { Response::fail("This {$type} was reserved recently, please allow up to 5 days before asking for a transfer"); } $ReserverLink = Users::get($reserved_by, 'id', 'name')->getProfileLink(); $PreviousAttempts = Posts::getTransferAttempts($Post, $type, $currentUser->id, $reserved_by); if (!empty($PreviousAttempts[0]) && empty($PreviousAttempts[0]['read_at'])) { Response::fail("You already expressed your interest in this post to {$ReserverLink} " . Time::tag($PreviousAttempts[0]['sent_at']) . ', please wait for them to respond.'); } $notifSent = Notifications::send($Post->reserved_by, 'post-passon', array('type' => $type, 'id' => $Post->id, 'user' => $currentUser->id)); Response::success("A notification has been sent to {$ReserverLink}, please wait for them to react.<br>If they don't visit the site often, it'd be a good idea to send them a note asking him to consider your inquiry."); } $isUserReserver = $Post->reserved_by === $currentUser->id; if (!empty($Post->reserved_by)) { switch ($action) { case 'reserve': if ($isUserReserver) { Response::fail("You've already reserved this {$type}", array('li' => Posts::getLi($Post))); } if ($Post->isOverdue()) { $overdue = array('reserved_by' => $Post->reserved_by, 'reserved_at' => $Post->reserved_at);
/** * @param Post $Post * @param string $type * @param string $reason * @param string|null $sent_by * @param string|null $reserved_by */ static function clearTransferAttempts(Post $Post, string $type, string $reason, string $sent_by = null, $reserved_by = null) { global $currentUser, $Database; if (empty(self::TRANSFER_ATTEMPT_CLEAR_REASONS[$reason])) { throw new \Exception("Invalid clear reason {$reason}"); } $Database->where('read_at IS NULL'); $TransferAttempts = Posts::getTransferAttempts($Post, $type, $sent_by, $reserved_by, 'id,data'); if (!empty($TransferAttempts)) { $SentFor = array(); foreach ($TransferAttempts as $n) { Notifications::safeMarkRead($n['id']); $data = JSON::decode($n['data']); if (!empty($SentFor[$data['user']][$reason]["{$data['type']}-{$data['id']}"])) { continue; } Notifications::send($data['user'], "post-pass{$reason}", array('id' => $data['id'], 'type' => $data['type'], 'by' => $currentUser->id)); $SentFor[$data['user']][$reason]["{$data['type']}-{$data['id']}"] = true; } } }