@param Portfolio $portfolio
@param User      $user

@return array
976468
public function getUserGuidedPortfolioData(Portfolio $portfolio, User $user)
    {
        return [
            'type' => ($user === $portfolio->getUser()) ? 'owned' : 'guided',
            'id' => $portfolio->getId(),
            'title' => $portfolio->getTitle(),
            'unreadComments' => $portfolio->getCountUnreadComments(),
            'commentsViewAt' => $portfolio->getCommentsViewAt()->format(DATE_W3C),
        ];
    }
716456
public function getByPortfolioForGridster(Portfolio $portfolio, $inArray = false)
    {
        $portfolioWidgets = $this->entityManager->getRepository('IcapPortfolioBundle:PortfolioWidget')->findOrderedByRowAndCol($portfolio);

        if ($inArray) {
            $portfolioWidgetsInArray = [];
            foreach ($portfolioWidgets as $portfolioWidget) {
                $portfolioWidgetsInArray[] = $this->getPortfolioWidgetData($portfolioWidget);
            }

            $portfolioWidgets = $portfolioWidgetsInArray;
        }

        return $portfolioWidgets;
    }
171706
public function getAll(User $user)
    {
        return array_map(function ($dashboard) {
            return $this->exportDashboard($dashboard);
        }, $this->getRepository()->findBy(['creator' => $user]));
    }
822312
public function getNewComment(Portfolio $portfolio, User $user)
    {
        $comment = $this->commentFactory->createComment($portfolio, $user);

        return $comment;
    }
853395
public function findUserList(User $user)
    {
        $dql = 'SELECT e FROM Phraseanet:UsrListEntry e
            WHERE e.user = :usr_id';

        $params = [
            'usr_id' => $user->getId(),
        ];

        $query = $this->_em->createQuery($dql);
        $query->setParameters($params);

        return $query->getResult();
    }
204052
public function replaceUser(User $from, User $to)
    {
        $portfolios = $this->entityManager->getRepository('IcapPortfolioBundle:Portfolio')->findByUser($from);

        if (count($portfolios) > 0) {
            foreach ($portfolios as $portfolio) {
                $portfolio->setUser($to);
            }

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

        return count($portfolios);
    }
304791
public function edit(PortfolioRequest $request, Portfolio $portfolio)
    {
        return $this->response->title(trans('app.edit') . ' ' . trans('portfolio::portfolio.name'))
            ->view('portfolio::portfolio.edit', true)
            ->data(compact('portfolio'))
            ->output();
    }
1287227
public function deleteAction(Request $request, User $loggedUser, Portfolio $portfolio, $type, $portfolioWidgetId)
    {
        $this->checkPortfolioToolAccess($loggedUser, $portfolio);

        /** @var \Icap\PortfolioBundle\Entity\PortfolioWidget $portfolioWidget */
        $portfolioWidget = $this->getDoctrine()->getRepository('IcapPortfolioBundle:PortfolioWidget')->findOneBy([
            'id' => $portfolioWidgetId,
            'widgetType' => $type,
            'portfolio' => $portfolio,
        ]);

        $response = new JsonResponse();

        try {
            $this->getWidgetsManager()->deletePortfolioWidget($portfolioWidget);
            $event = new PortfolioEditEvent($portfolio);
            $this->get('event_dispatcher')->dispatch('log', $event);
        } catch (\Exception $exception) {
            $response->setStatusCode(Response::HTTP_INTERNAL_SERVER_ERROR);
        }

        return $response;
    }
1098472
public function getRolesFor(User $user)
    {

        $userRoles = $user->roles()->get();

        $roles  = Role::where('order', '<=', $this->maxRole()->order);

        foreach ($userRoles as $role) {
            $roles = $roles->where('name', '!=', $role->name);
        }

        return $roles->get();
    }
468381
public function includeAbilities(User $user)
    {
        $abilities = isset($user->selected_context_id) ? $user->selected_context->abilities : [];

        return $this->collection($abilities, new AbilityTransformer, 'ability');
    }
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);
    }
601778
public function update(PortfolioRequest $request, Portfolio $portfolio)
    {
        try {
            $attributes = $request->all();

            $portfolio->update($attributes);
            return $this->response->message(trans('messages.success.updated', ['Module' => trans('portfolio::portfolio.name')]))
                ->code(204)
                ->status('success')
                ->url(guard_url('portfolio/portfolio/' . $portfolio->getRouteKey()))
                ->redirect();
        } catch (Exception $e) {
            return $this->response->message($e->getMessage())
                ->code(400)
                ->status('error')
                ->url(guard_url('portfolio/portfolio/' . $portfolio->getRouteKey()))
                ->redirect();
        }

    }
34387
public function destroy(UserPolicy $user, Portfolio $portfolio)
    {
        return $portfolio->user_id == user_id() && $portfolio->user_type == user_type();
    }
678817
public function getAllAction(User $loggedUser, Portfolio $portfolio)
    {
        $this->checkPortfolioToolAccess($loggedUser, $portfolio);

        $response = new JsonResponse($this->getCommentsManager()->getCommentsByPortfolio($portfolio), Response::HTTP_OK);

        return $response;
    }
1163919
public function putAction(Request $request, User $loggedUser, Portfolio $portfolio)
    {
        $this->checkPortfolioToolAccess();

        if ($portfolio->getUser() === $loggedUser) {
            $data = $this->getPortfolioManager()->handle($portfolio, $request->request->all(), $this->get('kernel')->getEnvironment());
        } else {
            $portfolioGuide = $this->getPortfolioGuideManager()->getByPortfolioAndGuide($portfolio, $loggedUser);

            if (null !== $portfolioGuide) {
                $this->getPortfolioGuideManager()->updateCommentsViewDate($portfolioGuide);
                $data = $this->getPortfolioManager()->getPortfolioData($portfolio);

                $data['unreadComments'] = $portfolio->getCountUnreadComments($portfolioGuide->getCommentsViewAt());
                $data['commentsViewAt'] = $portfolioGuide->getCommentsViewAt();
            } else {
                throw new NotFoundHttpException();
            }
        }

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

        return $response;
    }
776284
public function getPortfolioData(Portfolio $portfolio)
    {
        /** @var \Icap\PortfolioBundle\Entity\PortfolioWidget[] $portfolioWidgets */
        $portfolioWidgets = $this->widgetsManager->getByPortfolioForGridster($portfolio);
        /** @var \Icap\PortfolioBundle\Entity\PortfolioComment[] $comments */
        $comments = $this->entityManager->getRepository('IcapPortfolioBundle:PortfolioComment')->findSome($portfolio);

        $data = [
            'id' => $portfolio->getId(),
            'title' => $portfolio->getTitle(),
            'portfolioWidgets' => [],
        ];

        foreach ($portfolioWidgets as $portfolioWidget) {
            $data['portfolioWidgets'][] = $this->widgetsManager->getPortfolioWidgetData($portfolioWidget);
        }

        $commentsDatas = [];

        foreach ($comments as $comment) {
            $commentsDatas[] = $comment->getData();
        }
        $data['comments'] = $commentsDatas;
        $data['unreadComments'] = $portfolio->getCountUnreadComments();
        $data['commentsViewAt'] = $portfolio->getCommentsViewAt()->format(DATE_W3C);

        return $data;
    }
1273243
public function findAvailableToGuideByUser(User $user, $executeQuery = true)
    {
        $queryBuilder = $this->createQueryBuilder('p')
            ->leftJoin('p.portfolioGuides', 'guides')
            ->andWhere('p.user = :user')
            ->orWhere('guides.user = :guide')
            ->setParameter('user', $user)
            ->setParameter('guide', $user)
        ;

        return $executeQuery ? $queryBuilder->getQuery()->getResult() : $queryBuilder->getQuery();
    }