コード例 #1
0
ファイル: AnsCalculate.php プロジェクト: seddor/practice2
 /**
  * @param Test $test
  * @return int
  */
 public function calculateMaxRating(Test $test)
 {
     $ratingArray = null;
     $rating = 0;
     foreach ($test->getQuestions()->getValues() as $question) {
         foreach ($question->getAnswers()->getValues() as $answer) {
             $ratingArray[] = $answer->getRating();
         }
         if ($ratingArray) {
             $rating += max($ratingArray);
         }
         $ratingArray = null;
     }
     return $rating;
 }
コード例 #2
0
 public function saveObjects($data, $manager)
 {
     // type object
     $object = new Test();
     // fields object
     $object->setPosition($data['position']);
     $object->setOptions(json_encode($data['options']));
     $object->setTitle($data['title']);
     // refs
     $object->setType($this->getReference($data['ref_testtype']));
     $object->setRequisiteHistorical($this->getReference($data['ref-requisitehistorical']));
     // persist
     $manager->persist($object);
     $manager->flush();
 }
コード例 #3
0
 /**
  * @ApiDoc(
  *  resource=true,
  *  description="Download a file test",
  *  https=true,
  *  requirements={
  *      {"name": "id", "dataType"="integer", "requirement"="\d+", "description"="Test id"},
  *  }
  * )
  * @Route("/tests/{id}/download")
  * @ParamConverter("test", class="AppBundle:Test", options={"mapping": {"id": "id"}})
  * @QueryParam(name="show", requirements="[01]", default="0", description="0: The file is downloaded, 1: The file is opened on the browser.")
  */
 public function getTestDownloadAction(Test $test, ParamFetcher $paramFetcher)
 {
     $filename = sprintf("%s-%s-%s.%s", Slugger::slugify($test->getSubject()->getName()), Slugger::slugify($test->getSeason()), Slugger::slugify($test->getYear()), pathinfo($test->getFilename(), PATHINFO_EXTENSION));
     $responseType = ResponseHeaderBag::DISPOSITION_ATTACHMENT;
     if ($page = $paramFetcher->get('show') === "1") {
         $responseType = ResponseHeaderBag::DISPOSITION_INLINE;
     }
     $fileToDownload = $this->get('vich_uploader.storage')->resolvePath($test, 'file');
     $response = new BinaryFileResponse($fileToDownload);
     $response->trustXSendfileTypeHeader();
     $response->setContentDisposition($responseType, $filename, iconv('UTF-8', 'ASCII//TRANSLIT', $filename));
     $em = $this->getDoctrine()->getManager();
     $test->incrementDownloads();
     $em->persist($test);
     $em->flush();
     return $response;
 }
コード例 #4
0
 public function post(array $parameters)
 {
     $test = new Test();
     $test->setCreatedBy($this->getUser());
     return $this->processForm($test, $parameters, 'POST');
 }
コード例 #5
0
 /**
  * Post a new test.
  *
  * { "test": { "title": "Test", "body": "test" } }
  *
  * @param Request $request
  * @param $user_id
  *
  * @return View|Response
  *
  * @FOSRest\View()
  * @FOSRest\Post(
  *     "/users/{user_id}/tests/",
  *     name = "api_users_tests_post",
  *     requirements = {
  *         "user_id" : "\d+"
  *     }
  * )
  * @Nelmio\ApiDoc(
  *     input = "ApiBundle\Form\TestType",
  *     statusCodes = {
  *         Response::HTTP_CREATED : "Created"
  *     }
  * )
  */
 public function postAction(Request $request, $user_id)
 {
     # HTTP method: POST
     # Host/port  : http://www.nmdad3.arteveldehogeschool.local
     #
     # Path       : /app_dev.php/api/v1/users/1/articles/
     $em = $this->getDoctrine()->getManager();
     $user = $em->getRepository('AppBundle:User')->find($user_id);
     if (!$user instanceof User) {
         throw new NotFoundHttpException();
     }
     $test = new Test();
     $test->setUser($user);
     $logger = $this->get('logger');
     $logger->info($request);
     return $this->processTestForm($request, $test);
 }
コード例 #6
0
 private function route(Test $module)
 {
     return $this->get('router')->generate('api_1_get_module', ['test' => $module->getId()]);
 }
コード例 #7
0
ファイル: TestController.php プロジェクト: seddor/practice2
 /**
  * @Security("has_role('ROLE_SUPER_ADMIN')")
  * @Route("/test", name="testNewForm")
  */
 public function newTestFormAction(Request $request)
 {
     $image = new Image();
     $form = $this->createFormBuilder($image)->add('file', 'file', array('label' => 'Изображение:'))->getForm();
     $form->handleRequest($request);
     if ($form->isValid()) {
         $em = $this->getDoctrine()->getManager();
         $test = new Test();
         $test->setName($request->get('_name'));
         $test->setDescription($request->get('_description'));
         $company = $this->getDoctrine()->getRepository('AppBundle:Company')->find($request->get('_company'));
         $test->addCompany($company);
         $company->addTest($test);
         if (!$form->get('file')->isEmpty()) {
             $test->setImage($image);
             $em->persist($test);
             $em->flush();
             $image->upload($test->getId());
             $image->setPath($test->getId() . '/' . $form->get('file')->getData()->getClientOriginalName());
             $em->persist($image);
             $em->flush();
             return $this->redirectToRoute('aboutTestpage', array('id' => $test->getId()));
         }
         $em->persist($test);
         $em->flush();
         return $this->redirectToRoute('aboutTestpage', array('id' => $test->getId()));
     }
     return $this->render(':tests:new_test.html.twig', array('companies' => $this->getDoctrine()->getRepository('AppBundle:Company')->findAll(), 'uploadForm' => $form->createView()));
 }
コード例 #8
0
ファイル: TestForm.php プロジェクト: spdionis/un-webservice
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->add('type', 'choice', ['choices' => array_combine(Test::getTypes(), Test::getTypes())])->add('duration', 'integer');
 }