private function canEdit(Post $post, User $user) { // this assumes that the data object has a getOwner() method // to get the entity of the user who owns this data object //if ($post->getAuthor()->getIsAdmin() and !$user->getIsAdmin()) { // return false; //} return $user === $post->getAuthor() or $user->getIsAdmin(); }
/** * Send email to author and all people from comments when vote is Approved or Rejected * * @param Post $post * @param string $translation * @param string $template */ private function sendPostVoteClosedEmail(Post $post, $translation, $template) { $recipients[] = $post->getAuthor()->getEmail(); /** @var Comment $comment */ $comments = $post->getComments(); foreach ($comments as $comment) { $recipients[] = $comment->getUser()->getEmail(); } $subject = $this->translator->trans($translation); $body = $this->renderView($template, array('post' => $post)); $this->mailer->send($recipients, $subject, $body); }
/** * {@inheritDoc} */ public function getAuthor() { $this->__initializer__ && $this->__initializer__->__invoke($this, 'getAuthor', []); return parent::getAuthor(); }