Ojs\JournalBundle\Service\JournalService::getSelectedJournalRoles PHP Method

getSelectedJournalRoles() public method

public getSelectedJournalRoles ( Journal $journal = null ) : Doctrine\Common\Collections\Collection
$journal Ojs\JournalBundle\Entity\Journal
return Doctrine\Common\Collections\Collection
    public function getSelectedJournalRoles(Journal $journal = null)
    {
        $journal = $journal ? $journal : $this->getSelectedJournal();
        $token = $this->tokenStorage->getToken();
        if ($token instanceof AnonymousToken || !$journal instanceof Journal) {
            return array();
        }
        /** @var JournalUser $journalUser */
        $user = $token->getUser();
        $journalUserRepo = $this->em->getRepository('OjsJournalBundle:JournalUser');
        $journalUser = $journalUserRepo->findOneBy(['journal' => $journal, 'user' => $user]);
        if (!$journalUser) {
            return new ArrayCollection();
        }
        return $journalUser->getRoles();
    }

Usage Example

示例#1
0
 /**
  * @return \Doctrine\Common\Collections\Collection
  */
 public function userJournalRoles()
 {
     return $this->journalService->getSelectedJournalRoles();
 }