function canSeeEvent($idUser, $idEvent) { if (isEventPublic($idEvent)) { return true; } if (isUserRegisteredInEvent($idUser, $idEvent)) { return true; } if (isUserInvitedToEvent($idUser, $idEvent)) { return true; } return false; }
function inviteUserToEvent($idInviter, $idUser, $idEvent) { if (isUserInvitedToEvent($idUser, $idEvent)) { throw new AlreadyInvitedException("User is already invited to the event."); } if (isUserEventOwner($idUser, $idEvent)) { throw new IllegalUserInvitedException("You cannot invite the event's owner."); } global $db; $stmt = $db->prepare('INSERT INTO EventInvite(idEvent, idInvited, idInviter) VALUES (:idevent, :invitee, :inviter)'); $stmt->bindParam(':invitee', $idUser, PDO::PARAM_INT); $stmt->bindParam(':inviter', $idInviter, PDO::PARAM_INT); $stmt->bindParam(':idevent', $idEvent, PDO::PARAM_INT); return $stmt->execute(); }