@param Portfolio $portfolio
@param User|null $user
@param bool      $isAdmin

@return string|null
761949
public function getOpeningMode(Portfolio $portfolio, $user, $isAdmin = false)
    {
        $openingMode = null;

        if (null !== $user) {
            if ($user === $portfolio->getUser() || $isAdmin) {
                $openingMode = self::PORTFOLIO_OPENING_MODE_EDIT;
            } elseif ($portfolio->hasGuide($user)) {
                $openingMode = self::PORTFOLIO_OPENING_MODE_EVALUATE;
            } elseif ($this->visibleToUser($portfolio, $user)) {
                $openingMode = self::PORTFOLIO_OPENING_MODE_VIEW;
            }
        } elseif (Portfolio::VISIBILITY_EVERYBODY === $portfolio->getVisibility()) {
            $openingMode = self::PORTFOLIO_OPENING_MODE_VIEW;
        }

        return $openingMode;
    }
311534
public static function leap2a_writer(stdclass $user=null) {
        global $CFG;
        if (empty($user)) {
            global $USER;
            $user = $USER;
        }
        require_once($CFG->libdir . '/portfolio/formats/leap2a/lib.php');
        return new portfolio_format_leap2a_writer($user);
    }
148165
public function show(PortfolioRequest $request, Portfolio $portfolio)
    {

        if ($portfolio->exists) {
            $view = 'portfolio::portfolio.show';
        } else {
            $view = 'portfolio::portfolio.new';
        }

        return $this->response->title(trans('app.view') . ' ' . trans('portfolio::portfolio.name'))
            ->data(compact('portfolio'))
            ->view($view, true)
            ->output();
    }
720640
public function manageGuidesAction(Request $request, User $loggedUser, Portfolio $portfolio)
    {
        try {
            if ($this->getPortfolioFormHandler()->handleGuides($portfolio)) {
                if ($request->isXmlHttpRequest()) {
                    return new Response($this->refreshPortfolioList($loggedUser));
                } else {
                    $this->getSessionFlashbag()
                        ->add('success', $this->getTranslator()
                            ->trans('portfolio_guides_update_success_message', [], 'icap_portfolio'));

                    return $this->redirect($this->generateUrl('icap_portfolio_index'));
                }
            }
        } catch (\Exception $exception) {
            $this->getSessionFlashbag()->add('error', $this->getTranslator()->trans('portfolio_guides_update_error_message', [], 'icap_portfolio'));

            return $this->redirect($this->generateUrl('icap_portfolio_index'));
        }

        return [
            'form' => $this->getPortfolioFormHandler()->getGuidesForm($portfolio)->createView(),
            'portfolio' => $portfolio,
        ];
    }
913167
public function getLoginLink($isadmin, $create, $del)
    {
        $loggedin = '<a href="user/login">Logga in om du vill kommentera</a>';
        if ($this->sess['id']) {
            $loggedin = ' <a href="' . $create .'">Skriv ett inlägg</a>';
            if ($isadmin === true) {
                $loggedin .= ' | <a href="' . $del . '">Ta bort ett inlägg</a>';
            }
        }
        return $loggedin;
    }
1242717
public function destroy(PortfolioRequest $request, Portfolio $portfolio)
    {
        try {

            $portfolio->delete();
            return $this->response->message(trans('messages.success.deleted', ['Module' => trans('portfolio::portfolio.name')]))
                ->code(202)
                ->status('success')
                ->url(guard_url('portfolio/portfolio/0'))
                ->redirect();

        } catch (Exception $e) {

            return $this->response->message($e->getMessage())
                ->code(400)
                ->status('error')
                ->url(guard_url('portfolio/portfolio/' . $portfolio->getRouteKey()))
                ->redirect();
        }

    }
648681
public function postAction(Request $request, User $loggedUser, Portfolio $portfolio, $type)
    {
        $this->checkPortfolioToolAccess($loggedUser, $portfolio);

        $response = new JsonResponse();
        $widgetManager = $this->getWidgetsManager();
        $widgetsConfig = $widgetManager->getWidgetsConfig();
        $data = [];
        $statusCode = Response::HTTP_BAD_REQUEST;

        if (isset($widgetsConfig[$type])) {
            $newWidget = $widgetManager->getNewPortfolioWidget($portfolio, $type);
            $data = $widgetManager->handlePortfolioWidget($newWidget, $request->request->all(), $this->get('kernel')->getEnvironment());
            $event = new PortfolioEditEvent($portfolio);
            $this->get('event_dispatcher')->dispatch('log', $event);
            $statusCode = Response::HTTP_CREATED;
        }

        $response
            ->setData($data)
            ->setStatusCode($statusCode);

        return $response;
    }
720024
public function retrievePortfolioFromXml(\SimpleXMLElement $xml, User $user)
    {
        $portfolioTitleNodes = $xml->xpath('/feed/title');

        if (0 === count($portfolioTitleNodes)) {
            throw new \Exception("Missing portfolio's title");
        }

        $portfolio = new Portfolio();
        $portfolio
            ->setTitle((string) $portfolioTitleNodes[0])
            ->setUser($user)
            ->setPortfolioWidgets($this->retrieveWidgets($xml, $portfolio));

        return $portfolio;
    }
89889
public function visibleToUser(Portfolio $portfolio, User $user)
    {
        $visibility = $portfolio->getVisibility();
        $isVisible = false;

        if ($portfolio->getUser() === $user) {
            $isVisible = true;
        } else {
            if (Portfolio::VISIBILITY_EVERYBODY === $visibility ||
                Portfolio::VISIBILITY_PLATFORM_USER === $visibility) {
                $isVisible = true;
            } elseif (Portfolio::VISIBILITY_USER === $visibility) {
                $portfolioUsers = $portfolio->getPortfolioUsers();

                foreach ($portfolioUsers as $portfolioUser) {
                    if ($user === $portfolioUser->getUser()) {
                        $isVisible = true;
                        break;
                    }
                }

                if (!$isVisible) {
                    $portfolioGroups = $portfolio->getPortfolioGroups();
                    $userGroups = $user->getGroups();

                    foreach ($portfolioGroups as $portfolioGroup) {
                        foreach ($userGroups as $userGroup) {
                            if ($userGroup === $portfolioGroup->getGroup()) {
                                $isVisible = true;
                                break;
                            }
                        }
                    }
                }

                if (!$isVisible) {
                    $portfolioTeams = $portfolio->getPortfolioTeams();
                    /** @var \Claroline\TeamBundle\Entity\Team[] $userTeams */
                    $userTeams = $this->teamManager->getTeamsByUser($user);

                    foreach ($portfolioTeams as $portfolioTeam) {
                        foreach ($userTeams as $userTeam) {
                            if ($userTeam === $portfolioTeam->getTeam()) {
                                $isVisible = true;
                                break;
                            }
                        }
                    }
                }
            }
        }

        return $isVisible;
    }
562459
public function replaceUser(User $from, User $to)
    {
        $portfolioUsers = $this->repo->findByUser($from);

        if (count($portfolioUsers) > 0) {
            foreach ($portfolioUsers as $portfolioUser) {
                $portfolioUser->setUser($to);
            }

            $this->om->flush();
        }

        return count($portfolioUsers);
    }
402209
public function handleVisibility(Portfolio $portfolio)
    {
        $originalPortfolioUsers = $portfolio->getPortfolioUsers();
        $originalPortfolioGroups = $portfolio->getPortfolioGroups();
        $originalPortfolioTeams = $portfolio->getPortfolioTeams();
        $form = $this->getVisibilityForm($portfolio);

        $request = $this->requestStack->getCurrentRequest();
        if ($request->isMethod('POST')) {
            $form->submit($request);

            if ($form->isValid()) {
                $this->portfolioManager->updateVisibility($portfolio, $originalPortfolioUsers, $originalPortfolioGroups, $originalPortfolioTeams);

                return true;
            }
        }

        return false;
    }
639554
public function checkPortfolioToolAccess(User $user = null, Portfolio $portfolio = null)
    {
        if (!$this->getPortfolioToolAccess()) {
            throw $this->createNotFoundException();
        }

        if (null !== $user && null !== $portfolio && $portfolio->getUser() !== $user) {
            $portfolioGuide = $this->getPortfolioGuideManager()->getByPortfolioAndGuide($portfolio, $user);

            if (null === $portfolioGuide) {
                throw $this->createNotFoundException();
            }
        }
    }
1233591
protected function refreshPortfolioList(User $loggedUser)
    {
        $ownedPortfolioQuery = $this->getDoctrine()->getRepository('IcapPortfolioBundle:Portfolio')->findByUserWithWidgetsAndComments($loggedUser, false);
        /** @var \Icap\PortfolioBundle\Entity\Portfolio[] $portfoliosPager */
        $portfoliosPager = $this->get('claroline.pager.pager_factory')->createPager($ownedPortfolioQuery, 1, 10);

        $guidedPortfolioQuery = $this->getDoctrine()->getRepository('IcapPortfolioBundle:Portfolio')->findGuidedPortfolios($loggedUser, false);
        $guidedPortfoliosPager = $this->get('claroline.pager.pager_factory')->createPager($guidedPortfolioQuery, 1, 10);

        $importManager = $this->getImportManager();
        $availableImportFormats = $importManager->getAvailableFormats();

        $parameters = [
            'portfoliosPager' => $portfoliosPager,
            'guidedPortfoliosPager' => $guidedPortfoliosPager,
            'availableImportFormats' => $availableImportFormats,
            'portfolioId' => 0,
        ];

        return $this->renderView('IcapPortfolioBundle:portfolio:list_content.html.twig', $parameters);
    }
1348307
public function doImport($content, User $user, $format)
    {
        $portfolio = $this->simulateImport($content, $user, $format);
        $entityManager = $this->getObjectManager();

        foreach ($portfolio->getPortfolioWidgets() as $portfolioWidget) {
            $entityManager->persist($portfolioWidget->getWidget());
        }
        $entityManager->persist($portfolio);
        $entityManager->flush();

        return $portfolio;
    }
436744
protected function hasValidCredentials($user, $credentials)
    {
        return ! is_null($user) && $this->provider->validateCredentials($user, $credentials);
    }
1040518
public function putCommentsAction(Request $request, User $loggedUser, Portfolio $portfolio)
    {
        $this->checkPortfolioToolAccess();
        $portfolioManager = $this->getPortfolioManager();

        $portfolioGuideManager = $this->getPortfolioGuideManager();
        $portfolioGuide = $portfolioGuideManager->getByPortfolioAndGuide($portfolio, $loggedUser);

        if ($portfolio->getUser() === $loggedUser) {
            $portfolioManager->updateCommentsViewDate($portfolio);
        } elseif (null !== $portfolioGuide) {
            $portfolioGuideManager->updateCommentsViewDate($portfolioGuide);
        } else {
            throw new NotFoundHttpException();
        }

        $data = $portfolioManager->getUserGuidedPortfolioData($portfolio, $loggedUser);
        if (null !== $portfolioGuide) {
            $data['unreadComments'] = $portfolio->getCountUnreadComments($portfolioGuide->getCommentsViewAt());
            $data['commentsViewAt'] = $portfolioGuide->getCommentsViewAt();
        }

        $response = new JsonResponse();
        $response->setData($data);

        return $response;
    }
1151998
public function getCanEdit(Comm $item, $isadmin, $del)
    {
        $canedit = "";
        $update = $this->setUrlCreator("comm/update");
        if ($item->userid == $this->sess['id'] || $isadmin) {
            $canedit = '<br /><a href="' . $update . '/' . $item->id . '">Redigera</a>';
            $canedit .= ' | <a href="' . $del . '/' . $item->id . '">Ta bort inlägget</a></p>';
        } else {
            $canedit .= '</p>';
        }
        return $canedit;
    }