/**
  * @param \SimpleXMLElement $xml
  * @param User              $user
  *
  * @return Portfolio
  *
  * @throws \Exception
  */
 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)->setWidgets($this->retrieveWidgets($xml));
     return $portfolio;
 }
 /**
  * @param User      $user
  * @param Portfolio $portfolio
  * @param array     $range     0 => startDate and 1 => endDate
  *
  * @return array
  */
 public function getViewsForChart(User $user, Portfolio $portfolio, array $range)
 {
     /** @var \Claroline\CoreBundle\Repository\Log\LogRepository $logRepository */
     $logRepository = $this->entityManager->getRepository('ClarolineCoreBundle:Log\\Log');
     $queryBuilder = $logRepository->createQueryBuilder('log')->select('log.shortDateLog as shortDate, count(log.id) as total')->orderBy('shortDate', 'ASC')->groupBy('shortDate');
     $queryBuilder = $logRepository->addOwnerFilterToQueryBuilder($queryBuilder, $user);
     $queryBuilder = $logRepository->addActionFilterToQueryBuilder($queryBuilder, PortfolioViewEvent::ACTION);
     $queryBuilder = $logRepository->addOtherElementIdFilterToQueryBuilder($queryBuilder, $portfolio->getId());
     $queryBuilder = $logRepository->addDateRangeFilterToQueryBuilder($queryBuilder, $range);
     return $logRepository->extractChartData($queryBuilder->getQuery()->getResult(), $range);
 }
 /**
  * @Route("/portfolio/{id}", name="icap_portfolio_internal_portfolio_put")
  * @Method({"PUT"})
  *
  * @ParamConverter("loggedUser", options={"authenticatedUser" = true})
  */
 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;
 }
 /**
  * @param Portfolio $portfolio
  */
 public function updateCommentsViewDate(Portfolio $portfolio)
 {
     $portfolio->setCommentsViewAt(new \DateTime());
     $this->entityManager->flush($portfolio);
 }
 /**
  * Get details.
  *
  * @return array
  */
 public function getNotificationDetails()
 {
     $receiver = $this->getReceiver();
     $notificationDetails = array('portfolio' => array('id' => $this->portfolio->getId(), 'title' => $this->portfolio->getTitle(), 'slug' => $this->portfolio->getSlug()), 'guide' => array('id' => $receiver->getId(), 'publicUrl' => $receiver->getPublicUrl(), 'lastName' => $receiver->getLastName(), 'firstName' => $receiver->getFirstName()));
     return $notificationDetails;
 }
 /**
  * @Route("/delete/{id}", name="icap_portfolio_delete", requirements={"id" = "\d+"})
  *
  * @ParamConverter("loggedUser", options={"authenticatedUser" = true})
  * @Template()
  */
 public function deleteAction(Request $request, User $loggedUser, Portfolio $portfolio)
 {
     $this->checkPortfolioToolAccess();
     if ($loggedUser !== $portfolio->getUser()) {
         throw $this->createNotFoundException('Unkown user for this portfolio.');
     }
     try {
         $this->getPortfolioFormHandler()->handleDelete($portfolio);
         if ($request->isXmlHttpRequest()) {
             return new Response($this->refreshPortfolioList($loggedUser));
         } else {
             $this->getSessionFlashbag()->add('success', $this->getTranslator()->trans('portfolio_delete_success_message', [], 'icap_portfolio'));
         }
     } catch (\Exception $exception) {
         if ($request->isXmlHttpRequest()) {
             return new JsonResponse('Error while deleting the portfolio', 500);
         } else {
             $this->getSessionFlashbag()->add('error', $this->getTranslator()->trans('portfolio_delete_error_message', [], 'icap_portfolio'));
         }
     }
     return $this->redirect($this->generateUrl('icap_portfolio_index'));
 }
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->add('visibility', 'choice', array('choices' => Portfolio::getVisibilityLabels(), 'required' => true, 'label' => 'visibility', 'theme_options' => array('label_width' => 'col-md-2')))->add('portfolio_users', 'collection', array('type' => 'icap_portfolio_visible_user_form', 'by_reference' => false, 'theme_options' => array('label_width' => 'col-md-12'), 'prototype' => true, 'allow_add' => true, 'allow_delete' => true))->add('search_user', 'zenstruck_ajax_entity', array('class' => 'ClarolineCoreBundle:User', 'use_controller' => true, 'property' => 'username', 'repo_method' => 'findByNameForAjax', 'placeholder' => $this->translator->trans('select_user', array(), 'icap_portfolio'), 'mapped' => false))->add('portfolio_groups', 'collection', array('type' => 'icap_portfolio_visible_group_form', 'by_reference' => false, 'theme_options' => array('label_width' => 'col-md-12'), 'prototype' => true, 'allow_add' => true, 'allow_delete' => true))->add('search_group', 'zenstruck_ajax_entity', array('class' => 'ClarolineCoreBundle:Group', 'use_controller' => true, 'property' => 'name', 'repo_method' => 'findByNameForAjax', 'placeholder' => $this->translator->trans('select_group', array(), 'icap_portfolio'), 'mapped' => false))->add('portfolio_teams', 'collection', array('type' => 'icap_portfolio_visible_team_form', 'by_reference' => false, 'theme_options' => array('label_width' => 'col-md-12'), 'prototype' => true, 'allow_add' => true, 'allow_delete' => true))->add('search_team', 'zenstruck_ajax_entity', array('class' => 'ClarolineTeamBundle:Team', 'use_controller' => true, 'property' => 'name', 'placeholder' => $this->translator->trans('select_team', array(), 'icap_portfolio'), 'mapped' => false));
 }
 /**
  * @param null|User      $user
  * @param null|Portfolio $portfolio
  *
  * @throws NotFoundHttpException
  */
 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();
         }
     }
 }
 public function getLogSignature()
 {
     return self::ACTION . '_' . $this->portfolio->getId();
 }
 public function getVisibilityLabel($visibility)
 {
     return Portfolio::getVisibilityLabels()[$visibility];
 }
 /**
  * @param Portfolio $portfolio
  *
  * @return bool True on successfull processing, false otherwise
  */
 public function handleGuides(Portfolio $portfolio)
 {
     $originalPortfolioGuides = $portfolio->getPortfolioGuides();
     $form = $this->getGuidesForm($portfolio);
     $request = $this->requestStack->getCurrentRequest();
     if ($request->isMethod('POST')) {
         $form->submit($request);
         if ($form->isValid()) {
             $this->portfolioManager->updateGuides($portfolio, $originalPortfolioGuides);
             return true;
         }
     }
     return false;
 }