/**
  * @Route("/order/getcategories")
  */
 function getcategories(Request $request)
 {
     /*
      $url = $this->getSetting("AppBundle:Entity:tecdocServiceUrl");
      $fields = array(
      'action' => 'getcarcategories',
      'linkingTargetId' => $request->request->get("car")
      );
      $fields_string = "";
      foreach ($fields as $key => $value) {
      $fields_string .= $key . '=' . $value . '&';
      }
      rtrim($fields_string, '&');
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, $url);
      curl_setopt($ch, CURLOPT_POST, count($fields));
      curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
      $data = curl_exec($ch);
      $data = unserialize($data);
     */
     $em = $this->getDoctrine()->getManager();
     $tecdoc = new Tecdoc();
     $params["linkingTargetId"] = $request->request->get("car");
     $data = $tecdoc->linkedChildNodesAllLinkingTargetTree($params);
     $articleIds = array();
     foreach ($data as $key => $dt) {
         foreach ((array) $dt->articleIds as $articleId) {
             $articleIds[] = $articleId;
         }
     }
     $tecdocArticleIds = array();
     if (count($articleIds)) {
         $query = $em->createQuery("SELECT  p.tecdocArticleId\r\n                        FROM 'SoftoneBundle:Product' p\r\n                        where p.tecdocArticleId in (" . implode(",", $articleIds) . ")");
         /*
         echo "SELECT  p.tecdocArticleId
                     FROM 'SoftoneBundle:Product' p
                     where p.tecdocArticleId in (" . implode(",", $articleIds) . ")";
         */
         $products = $query->getResult();
         //print_r($products);
         foreach ($products as $product) {
             $tecdocArticleIds[] = $product["tecdocArticleId"];
         }
     }
     //print_r($tecdocArticleIds);
     $tecdocEdiArticleIds = array();
     if (count($articleIds)) {
         $query = $em->createQuery("SELECT  p.tecdocArticleId\r\n                        FROM 'EdiBundle:EdiItem' p, EdiBundle:Edi e\r\n                        where \r\n                            e.id = p.Edi AND p.tecdocArticleId in (" . implode(",", $articleIds) . ")");
         $products = $query->getResult();
         foreach ($products as $product) {
             $tecdocEdiArticleIds[] = $product["tecdocArticleId"];
         }
     }
     foreach ($data as $key => $dt) {
         $matched = array_intersect(@(array) $dt->articleIds, $tecdocArticleIds);
         $edimatched = array_intersect(@(array) $dt->articleIds, $tecdocEdiArticleIds);
         $dt->matched = array();
         $dt->matched = base64_encode(serialize($matched));
         $dt->matched_count = count($matched);
         $dt->edimatched = array();
         $dt->edimatched = base64_encode(serialize($edimatched));
         $dt->edimatched_count = count($edimatched);
         $all["matched"] = (array) $matched;
         $all["edimatched"] = (array) $edimatched;
         $all["articleIds"] = @(array) $dt->articleIds;
         $dt->all = base64_encode(serialize($all));
         //$data[$key] = $dt;
     }
     $json = json_encode($data);
     //$data = unserialize($data);
     return new Response($json, 200, array('Content-Type' => 'application/json'));
 }