/**
  * To generate the html (text with hole) without value
  *
  * @access private
  *
  * @param \UJM\ExoBundle\Entity\InteractionHole $interHole
  *
  */
 private function htmlWithoutValue($interHole)
 {
     //id hole in html = $hole->getPosition()
     $html = $interHole->getHtml();
     $tabInputValue = explode('value="', $html);
     $tabHoles = array();
     foreach ($interHole->getHoles() as $hole) {
         if ($hole->getSelector() === false) {
             $tabHoles[$hole->getPosition()] = $hole;
         } else {
             $selectInHtml = explode('<select id="' . $hole->getPosition() . '" class="blank" name="blank_' . $hole->getPosition() . '">', $html);
             $selectInHtml = explode('</select>', $selectInHtml[1]);
             $html = str_replace($selectInHtml[0], '', $html);
             $pos = $hole->getPosition();
             $regExpr = '<select id="' . $pos . '" class="blank" name="blank_' . $hole->getPosition() . '">';
             $select = '<select id="' . $pos . '" class="blank" name="blank_' . $hole->getPosition() . '">';
             $wrs = array();
             foreach ($hole->getWordResponses() as $wr) {
                 $wrs[] = $wr;
             }
             shuffle($wrs);
             foreach ($wrs as $wr) {
                 $id = $wr->getId();
                 $response = $wr->getResponse();
                 $select .= "<option value=\"{$id}\">{$response}</option>";
             }
             $html = str_replace($regExpr, $select, $html);
         }
     }
     ksort($tabHoles);
     $tabHoles = array_values($tabHoles);
     for ($i = 0; $i < count($tabInputValue); $i++) {
         $inputValue = explode('"', $tabInputValue[$i]);
         $regExpr = 'value="' . $inputValue[0] . '"';
         $html = str_replace($regExpr, 'value=""', $html);
     }
     $interHole->setHtmlWithoutValue($html);
     $this->em->persist($interHole);
     $this->em->flush();
 }
Exemplo n.º 2
0
 /**
  * @param \UJM\ExoBundle\Entity\InteractionHole     $interHole
  * @param \Symfony\Component\HttpFoundation\Request $request
  *
  * @return json
  */
 private function getJsonResponse($interHole, $request)
 {
     $tabResp = [];
     $em = $this->doctrine->getManager();
     foreach ($interHole->getHoles() as $hole) {
         $response = $request->get('blank_' . $hole->getPosition());
         $response = trim($response);
         $response = preg_replace('/\\s+/', ' ', $response);
         if ($hole->getSelector()) {
             $wr = $em->getRepository('UJMExoBundle:WordResponse')->find($response);
             $tabResp[$hole->getPosition()] = $wr->getResponse();
         } else {
             $from = array("'", '"');
             $to = array("\\u0027", "\\u0022");
             $tabResp[$hole->getPosition()] = str_replace($from, $to, $response);
         }
     }
     return json_encode($tabResp);
 }