Esempio n. 1
0
 /**
  * @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;
         }
     }
 }
Esempio n. 2
0
            switch ($Notif['type']) {
                case "post-passon":
                    $Post = $Database->where('id', $data['id'])->getOne("{$data['type']}s");
                    if (empty($Post)) {
                        Posts::clearTransferAttempts($Post, $data['type'], 'del');
                        Response::fail("The {$data['type']} doesn't exist or has been deleted");
                    }
                    if ($read_action === 'true') {
                        if ($Post['reserved_by'] !== $currentUser->id) {
                            Posts::clearTransferAttempts($Post, $data['type'], 'perm', null, $currentUser->id);
                            Response::fail('You are not allowed to transfer this reservation');
                        }
                        Notifications::safeMarkRead($Notif['id'], $read_action);
                        Notifications::send($data['user'], "post-passallow", array('id' => $data['id'], 'type' => $data['type'], 'by' => $currentUser->id));
                        $Database->where('id', $data['id'])->update("{$data['type']}s", array('reserved_by' => $data['user'], 'reserved_at' => date('c')));
                        Posts::clearTransferAttempts($Post, $data['type'], 'deny');
                        Logs::action('res_transfer', array('id' => $data['id'], 'type' => $data['type'], 'to' => $data['user']));
                    } else {
                        Notifications::safeMarkRead($Notif['id'], $read_action);
                        Notifications::send($data['user'], "post-passdeny", array('id' => $data['id'], 'type' => $data['type'], 'by' => $currentUser->id));
                    }
                    Response::done();
                    break;
                default:
                    Notifications::safeMarkRead($Notif['id'], $read_action);
            }
        } else {
            Notifications::safeMarkRead($Notif['id']);
        }
        Response::done();
}