Last active
April 13, 2017 12:32
-
-
Save craig-davis/9461883b5c2d2c432f459f7b174d81aa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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(); | |
$isTooOld = $this->created_at < time() — 2592000; | |
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