コード例 #1
0
 /**
  * @param $perspective
  * @return \Symfony\Component\HttpFoundation\Response
  */
 protected function renderJsonPerspective(Perspective $perspective)
 {
     $translator = $this->container->get('translator');
     /** @var \Symfony\Bundle\TwigBundle\TwigEngine $templateEngine */
     $templateEngine = $this->container->get('templating');
     if ($perspective->getName() !== null) {
         $perspectiveTitle = $perspective->getName();
     } else {
         $perspectiveTitle = $translator->trans('title_perspective');
     }
     $relativePath = $perspective->getValue();
     $projectRootDir = realpath($this->container->getParameter('kernel.root_dir') . '/..');
     $jsonFilePath = $projectRootDir . '/' . $relativePath;
     $error = null;
     if (file_exists($jsonFilePath)) {
         $records = json_decode(file_get_contents($jsonFilePath), $asAssocArray = true);
         $jsonLastError = json_last_error();
         if ($jsonLastError !== JSON_ERROR_NONE) {
             $error = $jsonLastError;
         }
     } else {
         $records = [];
     }
     $query = sprintf('SELECT * FROM weaving_perspective WHERE per_id = %d', $perspective->getId());
     $response = $templateEngine->renderResponse('WeavingTheWebDashboardBundle:Perspective:showPerspective.html.twig', array('active_menu_item' => 'dashboard', 'anonymous_visit' => false, 'error' => $error, 'display_graph' => true, 'enabled_search' => true, 'default_query' => $query, 'records' => $records, 'title' => $perspectiveTitle));
     $dateTime = new \DateTime();
     $dateInterval = \DateInterval::createFromDateString('2 hours');
     $expiresAt = $dateTime->add($dateInterval);
     $response->setExpires($expiresAt);
     return $response;
 }
コード例 #2
0
 public function makeImportableJsonPerspective()
 {
     $perspective = new Perspective();
     $perspective->setType(Perspective::TYPE_JSON);
     $perspective->setStatus(Perspective::STATUS_IMPORTABLE);
     $perspective->setCreationDate(new \DateTime());
     return $perspective;
 }
コード例 #3
0
 /**
  * @param \WeavingTheWeb\Bundle\DashboardBundle\Entity\Perspective $perspective
  * @return \Symfony\Component\Validator\ConstraintViolationListInterface
  */
 protected function validatePerspectiveValue($perspective)
 {
     $queryConstraint = new Query();
     return $this->validator->validateValue($perspective->getValue(), $queryConstraint, $queryConstraint::GROUP_PUBLIC_QUERIES);
 }