Skip to content

Instantly share code, notes, and snippets.

@craig-davis
Last active April 15, 2017 20:08
Show Gist options
  • Save craig-davis/ffdb8083b4becfd3be67ef892bbeca57 to your computer and use it in GitHub Desktop.
Save craig-davis/ffdb8083b4becfd3be67ef892bbeca57 to your computer and use it in GitHub Desktop.
<?php
class Post
{
public function canEdit(User $user) : bool
{
$isEditor = $user->getRole() == 3 && $this->getEditorId() == $user->getId();
$isAdmin = $user->getRole() > 5;
$isAuthor = $this->getAuthorId() == $user->getId();
$isSupervisor = $this->getRole() == 4;
$isSidebarPost = $this->getType() == 8;
$isTooOld = $this->created_at < time() — 2592000;
if ($isSupervisor && $isSidebarPost) {
return true;
}
if ($isEditor || $isAdmin) {
return true;
}
if ($isAuthor && !$isTooOld) {
return true;
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment