@param string $content
@param user   $user
@param string $format

@return \Icap\PortfolioBundle\Entity\Portfolio|null

@throws \Exception
973790
protected function import($content, User $user, $format)
    {
        if (!isset($this->importers[$format])) {
            throw new \Exception(sprintf("No importer for the '%s' format.", $format));
        }

        return $this->importers[$format]->import($content, $user);
    }
599132
public function extract($format, $carrier){
        if($format == Formats\TEXT_MAP){
            return $this->propagator->extract($format, $carrier);
        }else{
            throw new \Exception("not support format");
        }
    }
1371882
public function createUser(User $user)
    {
        if ($this->userStorage->getUserByField("email", $user->email)) {
            throw new Exception("E-postadress används redan.");
        }
        if ($this->userStorage->getUserByField("username", $user->username)) {
            throw new Exception("Användarnamn redan taget.");
        }
        $this->userStorage->createUser($user);
    }
386981
public function serializeContent($content, $format = 'json')
    {
        try {
            return $this->getSerializer()->serialize(
                $content,
                $format
            );
        } catch (\Exception $e) {
            $msg = sprintf(
                'Cannot serialize content class: %s; with id: %s; Message: %s',
                get_class($content),
                method_exists($content, 'getId') ? $content->getId() : '-no id-',
                str_replace('MongoDBODMProxies\__CG__\GravitonDyn', '', $e->getMessage())
            );
            $this->logger->alert($msg);
            throw new \Exception($msg, $e->getCode());
        }
    }
822312
public function getNewComment(Portfolio $portfolio, User $user)
    {
        $comment = $this->commentFactory->createComment($portfolio, $user);

        return $comment;
    }
82883
public function create_file_from_string($newfilename, $content, $userid = NULL) {
        if (!$this->is_writable() or !$this->lf->is_directory()) {
            return null;
        }

        $newfilename = clean_param($newfilename, PARAM_FILE);
        if ($newfilename === '') {
            return null;
        }

        $fs = get_file_storage();

        $now = time();

        $newrecord = new stdClass();
        $newrecord->contextid = $this->lf->get_contextid();
        $newrecord->component = $this->lf->get_component();
        $newrecord->filearea  = $this->lf->get_filearea();
        $newrecord->itemid    = $this->lf->get_itemid();
        $newrecord->filepath  = $this->lf->get_filepath();
        $newrecord->filename  = $newfilename;

        if ($fs->file_exists($newrecord->contextid, $newrecord->component, $newrecord->filearea, $newrecord->itemid, $newrecord->filepath, $newrecord->filename)) {
            // file already exists, sorry
            return null;
        }

        $newrecord->timecreated  = $now;
        $newrecord->timemodified = $now;
        $newrecord->mimetype     = mimeinfo('type', $newfilename);
        $newrecord->userid       = $userid;

        if ($file = $fs->create_file_from_string($newrecord, $content)) {
            return $this->browser->get_file_info($this->context, $file->get_component(), $file->get_filearea(), $file->get_itemid(), $file->get_filepath(), $file->get_filename());
        }
        return null;
    }
1271050
public function replaceUser(User $from, User $to)
    {
        $portfolioGuides = $this->entityManager->getRepository('IcapPortfolioBundle:PortfolioGuide')->findByUser($from);

        if (count($portfolioGuides) > 0) {
            foreach ($portfolioGuides as $portfolioGuide) {
                $portfolioGuide->setUser($to);
            }

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

        return count($portfolioGuides);
    }
285980
public function out($format = null)
    {
        if (0 == count($this->url)) {
            throw new Exception('No URL is set');
        }
        if (! is_null($format)) {
            $this->format($format);
        }
        if (is_null($this->response)) {
            $this->call();
        }

        return $this->parseResponse();
    }
705559
public function getViewAction(User $loggedUser, Portfolio $portfolio, $startDate, $endDate)
    {
        $this->checkPortfolioToolAccess($loggedUser, $portfolio);

        $startDate = new \DateTime($startDate);
        $endDate = new \DateTime($endDate);

        $chartData = $this->getAnalyticsManager()->getViewsForChart(
            $loggedUser,
            $portfolio,
            [$startDate->getTimestamp(), $endDate->getTimestamp()]
        );
        $response = new JsonResponse($chartData, Response::HTTP_OK);

        return $response;
    }
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);
    }
1187746
public function revise($content, User $actor)
    {
        if ($this->content !== $content) {
            $this->content = $content;

            $this->edited_at = Carbon::now();
            $this->edited_user_id = $actor->id;

            $this->raise(new Revised($this));
        }

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

        $commentManager = $this->getCommentsManager();

        $newComment = $commentManager->getNewComment($portfolio, $loggedUser);
        $data = $commentManager->handle($newComment, $loggedUser, $request->request->all(), $this->get('kernel')->getEnvironment());

        $response = new JsonResponse($data, Response::HTTP_CREATED);

        return $response;
    }
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,
        ];
    }
1288120
public function typeAction($contentDocument, $_format, Request $request)
    {
        if (!$contentDocument || ! $contentDocument instanceof Page) {
            throw new NotFoundHttpException('Content not found');
        }
        if ($this->container->has('profiler')) {
        	$this->container->get('profiler')->disable();
        }
        $isAdminUi = $request->query->get('admin', false) && $this->container->get('security.context')->isGranted('ROLE_ADMIN');

        $data = $params = $this->formatter->format($contentDocument);
		if("html" == $_format) {
	        $params = array(
	            'cmfMainContent' => $contentDocument,
	        	'jsData' => $data,
	        	'settings' => array("currentPath"=>"/","urlBase"=>"/"),
	        	'isAdminUI' => $isAdminUi,
	        	'serializationContext' => $this->getSerializerContext(array('front'))
	        );
		}

        return $this->renderResponse('ApplicationToguApplicationModelsBundle:Default:index.html.twig', $params);
    }
953167
public function export(Builder $query, $format)
    {
        $method = 'to'.strtoupper($format);

        if (method_exists($this, $method)) {
            return call_user_func_array([$this, $method], [$query]);
        }

        if (method_exists($this->module, $method)) {
            return call_user_func_array([$this->module, $method], [$query]);
        }

        throw new Exception(sprintf('Don\'t know how to export to %s format.', $format));
    }
1010074
public function getUserGuidedPortfoliosData(User $user)
    {
        /** @var \Icap\PortfolioBundle\Entity\Portfolio[] $portfolios */
        $portfolios = $this->entityManager->getRepository('IcapPortfolioBundle:Portfolio')->findAvailableToGuideByUser($user);

        $data = [];

        foreach ($portfolios as $portfolio) {
            $data[] = $this->getUserGuidedPortfolioData($portfolio, $user);
        }

        return $data;
    }
632424
public function view(UserPolicy $user, Portfolio $portfolio)
    {
        if ($user->canDo('portfolio.portfolio.view') && $user->isAdmin()) {
            return true;
        }

        return $portfolio->user_id == user_id() && $portfolio->user_type == user_type();
    }