Exemplo n.º 1
0
 /**
  * View test from node
  *
  * @param node
  * @Route("/list/tests/{_format}/{id}", name="node_view_tests", defaults={"_format": "html"},
  *     requirements={"id": "\d+","_format": "html|docx|pdf",})
  * @Pdf()
  * Cache(expires="+2 week")
  */
 public function viewTestsAction(Node $node, $_format)
 {
     $entityManager = $this->getDoctrine()->getManager();
     $repository = $entityManager->getRepository('TestBundle:Test');
     $testIds = $repository->getTestsIdsFromNode($node->getId());
     if (!count($testIds)) {
         $translator = $this->get('translator');
         return $this->render("TestBundle:Node:nodeDoNotContainsTest.html.twig", array('title' => $translator->trans('No tests'), 'description' => $translator->trans('This node does not contain tests')));
     }
     $template_twig = sprintf("TestBundle:Node:viewTests.%s.twig", $_format);
     $response = null;
     $data = array('node' => $node, 'title' => 'Test base');
     if ($_format == 'html') {
         $tests_query = $repository->getTestsByIds($testIds);
         $tests_pagination = $this->getPagination($tests_query);
         $data = array_merge($data, ['pagination' => $tests_pagination]);
     } elseif ($_format == 'docx') {
         $name = $node->getName();
         $name = str_replace(' ', '_', $name);
         $response = new Response('Content', Response::HTTP_OK, array('Content-type' => 'application/vnd.ms-word', 'Content-Disposition' => 'attachment;Filename=' . $name . '.docx'));
         $data = array_merge($data, ['title' => 'med-test.in.ua']);
     } elseif ($_format == 'pdf') {
         $data = array_merge($data, ['title' => 'med-test.in.ua']);
     }
     return $this->render($template_twig, $data, $response);
 }
Exemplo n.º 2
0
 public function load(ObjectManager $manager)
 {
     $nodes_array = [['name' => 'Крок', 'language' => 'ru'], ['name' => 'Elex', 'language' => 'ru'], ['name' => 'Крок', 'language' => 'uk'], ['name' => 'Elex', 'language' => 'uk'], ['name' => 'Krok', 'language' => 'en'], ['name' => 'Elex', 'language' => 'en'], ['name' => 'Работа над ошибками', 'language' => 'bg']];
     foreach ($nodes_array as $node_array) {
         $language = $manager->getRepository('TestBundle:Language')->findOneBy(['slug' => $node_array['language']]);
         $node = new Node();
         $node->setName($node_array['name']);
         $node->setChildren(null);
         $node->setLanguage($language);
         $manager->persist($node);
     }
     $manager->flush();
 }
Exemplo n.º 3
0
 /**
  * @test
  */
 public function getFindingChildrenIds()
 {
     $node = new Node();
     $node1_1 = new Node();
     $node1_2 = new Node();
     $node2_1 = new Node();
     $node1_2->setChildren($node2_1);
     $node->setChildren($node1_1);
     $node->setChildren($node1_2);
     $findingChildren = $node->getFindingChildrenIds();
     $this->assertCount(2, $findingChildren);
     $this->assertEmpty(array_diff([$node1_1->getId(), $node2_1->getId()], $findingChildren));
 }
Exemplo n.º 4
0
 /**
  * Create new Task and set it.
  *
  * @Route("/task/{id}", requirements={"id": "\d+"}, name="task")
  * @Template()
  */
 public function indexAction(Request $request, Node $node)
 {
     if (!count($node->getTests())) {
         $translator = $this->get('translator');
         return $this->render("TestBundle:Node:nodeDoNotContainsTest.html.twig", array('title' => $translator->trans('No tests'), 'description' => $translator->trans('This node does not contain tests')));
     }
     $form = $this->_getTaskForm($request);
     if ($form->isSubmitted() && $form->isValid()) {
         $user = $this->getUser();
         $task = $form->getData();
         $task = $this->_settingTask($task, $user, $node, $node->getTestsIds());
         return $this->redirectToRoute('testing', array('id' => $task->getId()));
     }
     return array('form' => $form->createView(), 'title' => $this->get('translator')->trans('Test setup'), 'node' => $node);
 }
 /**
  *
  * @param Request $request
  * @param Node $node
  *
  * @Route("/node/{id}",  requirements={"id": "[0-9*]+"}, name="node_statistic")
  * Cache(expires="+2 week")
  */
 public function nodeStatisticAction(Request $request, Node $node)
 {
     $node_id_arr = $node->getFindingChildrenIds();
     $entityManager = $this->getDoctrine()->getEntityManager();
     $statRepository = $entityManager->getRepository('TestBundle:Statistics');
     $result = $statRepository->countTestsInNode($node_id_arr);
     $user = $this->getUser();
     if ($user) {
         $user_result = $statRepository->countPassedTestsInNode($node_id_arr, $user->getId());
         $result = array_merge($result, $user_result);
     }
     return new JsonResponse($result);
 }