コード例 #1
0
ファイル: TwigExtension.php プロジェクト: briesurrood/Vidal
 public function newLetters($str)
 {
     $firstChar = mb_substr($str, 0, 1, 'utf-8');
     return in_array($firstChar, ProductNameCommand::newLetters());
 }
コード例 #2
0
ファイル: VidalController.php プロジェクト: briesurrood/Vidal
 /**
  * Описание препарата
  * @Route("/veterinar/{EngName}-{ProductID}.{ext}", name="v_product", requirements={"ProductID":"\d+", "EngName"=".*"}, defaults={"ext"="htm"})
  * @Route("/veterinar/{EngName}~{ProductID}.{ext}", name="v_product_old", requirements={"ProductID":"\d+", "EngName"=".+"}, defaults={"ext"="htm"})
  *
  * @Template("VidalVeterinarBundle:Vidal:document.html.twig")
  */
 public function productAction($EngName, $ProductID)
 {
     $em = $this->getDoctrine()->getManager('veterinar');
     $params = array();
     /** @var Product $product */
     $product = $em->getRepository('VidalVeterinarBundle:Product')->findByProductID($ProductID);
     if (empty($product) || $product['inactive'] === true) {
         throw $this->createNotFoundException();
     }
     $firstChar = mb_substr($product['RusName'], 0, 1, 'utf-8');
     if (in_array($firstChar, ProductNameCommand::newLetters())) {
         $request = $this->getRequest();
         $routeName = $request->get('_route');
         if ($routeName == "v_product_old") {
             if (!in_array($product['ProductID'], array(27840, 27869, 27868, 27934, 27935, 27996, 28175, 27710, 28247, 27987, 27705, 27964, 27962, 28004, 28080, 28086, 28086, 27949, 27947, 28078, 27784, 27785, 27720))) {
                 return $this->redirect($this->generateUrl('v_product', array('EngName' => $product['Name'], 'ProductID' => $product['ProductID'])), 301);
             }
         }
     }
     $params['title'] = $this->strip($product['RusName']) . ' - ' . $product['ZipInfo'] . ' | Видаль-Ветеринар';
     $document = $em->getRepository('VidalVeterinarBundle:Document')->findByProductID($ProductID);
     if ($document) {
         $articleId = $document->getArticleID();
         $params['document'] = $document;
         $params['articleId'] = $articleId;
         $params['infoPages'] = $em->getRepository('VidalVeterinarBundle:InfoPage')->findByDocumentID($document->getDocumentID());
     } else {
         # если связи ProductDocument не найдено, то это описание конкретного вещества (Molecule)
         $molecule = $em->getRepository('VidalVeterinarBundle:Molecule')->findOneByProductID($ProductID);
         if ($molecule) {
             $document = $em->getRepository('VidalVeterinarBundle:Document')->findByMoleculeID($molecule['MoleculeID']);
             if (!$document) {
                 throw $this->createNotFoundException();
             }
             $params['document'] = $document;
             $params['molecule'] = $molecule;
             $params['articleId'] = $document->getArticleId();
             $params['infoPages'] = $em->getRepository('VidalVeterinarBundle:InfoPage')->findByDocumentID($document->getDocumentID());
         }
     }
     $productIds = array($product['ProductID']);
     $params['product'] = $product;
     $params['products'] = array($product);
     $params['owners'] = $em->getRepository('VidalVeterinarBundle:Company')->findOwnersByProducts($productIds);
     $params['distributors'] = $em->getRepository('VidalVeterinarBundle:Company')->findDistributorsByProducts($productIds);
     $params['pictures'] = $em->getRepository('VidalVeterinarBundle:Picture')->findAllByProductIds($productIds);
     $params['molecules'] = $em->getRepository('VidalVeterinarBundle:Molecule')->findByProductID($ProductID);
     return $params;
 }