Esempio n. 1
0
 private function _getResponse($data, $_format)
 {
     $serializer = SerializerBuilder::create()->build();
     $jsonResponse = $serializer->serialize($data, $_format);
     $responseHandler = new ResponseHandler();
     return $responseHandler->getResponse($jsonResponse, $_format);
 }
Esempio n. 2
0
 /**
  * @Route("/goods_status/{_format}", name="api_goodsStatus_list", defaults={"_format"="json"}, options={"expose"=true})
  * @Method("GET")
  * @ApiDoc(
  *  resource=true,
  *  description="取得所有商品狀態的資料"
  * )
  */
 public function listAction(Request $request, $_format)
 {
     $em = $this->getDoctrine()->getManager();
     $goodsStatuses = $em->getRepository('WoojinGoodsBundle:GoodsStatus')->findAll();
     $serializer = \JMS\Serializer\SerializerBuilder::create()->build();
     $jsonGoodsStatuss = $serializer->serialize($goodsStatuses, $_format);
     $responseHandler = new ResponseHandler();
     return $responseHandler->getETag($request, $jsonGoodsStatuss, $_format);
 }
Esempio n. 3
0
 /**
  * @Route("/pattern/{_format}", name="api_pattern_list", defaults={"_format"="json"}, options={"expose"=true})
  * @Method("GET")
  * @ApiDoc(
  *  resource=true,
  *  description="取得所有款式的資料"
  * )
  */
 public function listAction(Request $request, $_format)
 {
     $em = $this->getDoctrine()->getManager();
     $patterns = $em->getRepository('WoojinGoodsBundle:Pattern')->findBy(array(), array('name' => 'ASC'));
     $serializer = \JMS\Serializer\SerializerBuilder::create()->build();
     $jsonPatterns = $serializer->serialize($patterns, $_format);
     $responseHandler = new ResponseHandler();
     return $responseHandler->getETag($request, $jsonPatterns, $_format);
 }
Esempio n. 4
0
 /**
  * @Route("/activity/{_format}", name="api_activity_list", defaults={"_format"="json"}, options={"expose"=true})
  * @Method("GET")
  * @ApiDoc(
  *  resource=true,
  *  description="取得所有活動的資料"
  * )
  */
 public function listAction(Request $request, $_format)
 {
     $em = $this->getDoctrine()->getManager();
     $activitys = $em->getRepository('WoojinStoreBundle:Activity')->findAll();
     $serializer = \JMS\Serializer\SerializerBuilder::create()->build();
     $jsonActivitys = $serializer->serialize($activitys, $_format);
     $responseHandler = new ResponseHandler();
     return $responseHandler->getETag($request, $jsonActivitys, $_format);
 }
Esempio n. 5
0
 /**
  * @Route("", name="admin_search_res", options={"expose"=true})
  * @Method("POST")
  * @Template()
  */
 public function resAction(Request $request)
 {
     $finder = $this->get('product.finder');
     $finder->find($request);
     $serializer = \JMS\Serializer\SerializerBuilder::create()->build();
     $json = $serializer->serialize(array('count' => $finder->getCount(), 'page' => $finder->getPage(), 'perpage' => $finder->getPerpage(), 'data' => $finder->getData()), 'json');
     $responseHandler = new ResponseHandler();
     return $responseHandler->getResponse($json, 'json');
 }
Esempio n. 6
0
 /**
  * @Route("/behalf/{id}/{_format}", requirements={"id"="\d+"}, defaults={"_format"="json"}, name="api_behalf_show", options={"expose"=true})
  * @ParamConverter("behalf", class="WoojinGoodsBundle:Behalf")
  * @Method("GET")
  * 
  * @ApiDoc(
  *  resource=true,
  *  description="取得代購資訊,ETag cache",
  *  requirements={
  *      {
  *          "name"="id", 
  *          "requirement"="\d+",
  *          "dataType"="integer", 
  *          "required"=true, 
  *          "description"="Entity Behalf's id"
  *      },
  *      {
  *          "name"="_format", 
  *          "dataType"="string", 
  *          "required"=false, 
  *          "description"="回傳的格式,支援 json, xml, html"
  *      }
  *  }
  * )
  */
 public function showAction(Request $request, $behalf, $_format)
 {
     if ($behalf->getCustom()->getId() !== $this->get('session.custom')->current()->getId()) {
         throw new AccessDeniedHttpException('Not Your own behalf');
     }
     if ($want = $behalf->getWant()) {
         $want->setCost(0);
     }
     if ($got = $behalf->getGot()) {
         $got->setCost(0);
     }
     $serializer = \JMS\Serializer\SerializerBuilder::create()->build();
     $jsonBehalf = $serializer->serialize($behalf, $_format);
     $responseHandler = new ResponseHandler();
     return $responseHandler->getETag($request, $jsonBehalf, $_format);
 }
Esempio n. 7
0
 /**
  * @Route("/custom/whishlist/empty", name="api_custom_whishlist_empty", options={"expose"=true})
  * @Method("PUT")
  *
  * @ApiDoc(
  *  description="清空用戶的願望清單"
  * )
  */
 public function emptyWhishlistAction()
 {
     $custom = $this->get('session.custom')->current();
     if (!$custom) {
         return $responseHandler->getResponse(json_encode(array('status' => 2, '')), 'json');
     }
     $custom->setWhishlist(array());
     $em = $this->getDoctrine()->getManager();
     $em->persist($custom);
     $em->flush();
     $responseHandler = new ResponseHandler();
     $msg = array('status' => 1, 'msg' => 'ok', 'data' => $whishlist);
     return $responseHandler->getResponse(json_encode($msg), 'json');
 }
 /**
  * @Route("/goods_passport/fetch/{_format}", defaults={"_format"="json"}, name="api_goodsPassport_fetchWithCondition", options={"expose"=true})
  * @Method("POST")
  *
  * @ApiDoc(
  *  resource=true,
  *  description="根據搜尋條件取得商品資訊,不需要作 cache"
  * )
  */
 public function fetchAction(Request $request, $_format)
 {
     /**
      * 字串流
      *
      * @var [string]
      */
     $content = $request->getContent();
     /**
      * stdClass, 有一個 jsonCondition屬性,該屬性內容為 json 字串
      *
      * @var [\stdClass]
      */
     $conditionClass = json_decode($content);
     /**
      * 條件物件, 格式如下
      *
      * @example
      * stdClass Object
      *(
      *    [gd] => stdClass Object
      *        (
      *            [brands] => Array
      *                (
      *                    [0] => stdClass Object
      *                        (
      *                            [id] => 59
      *                            [name] => 3.1
      *                            [isChecked] => 1
      *                        )
      *
      *                    [1] => stdClass Object
      *                        (
      *                            [id] => 23
      *                            [name] => ADMJ
      *                            [isChecked] => 1
      *                        )
      *
      *                    [2] => stdClass Object
      *                        (
      *                            [id] => 66
      *                            [name] => agnes b
      *                            [isChecked] => 1
      *                        )
      *
      *                )
      *
      *        )
      *
      *)
      *
      * @var [\stdClass]
      */
     $condition = json_decode($conditionClass->jsonCondition);
     $this->addOnBoardAndIsWebConstraint($condition);
     $serializer = \JMS\Serializer\SerializerBuilder::create()->build();
     /**
      * 自製的 條件轉換 query 服務
      */
     $gdConverter = $this->get('gd.converter');
     $gdConverter->gen($condition, false, false, true);
     // 除錯的時候拿掉這段註解可以看 condition 的詳情和實際執行的 Dql 語句
     //
     //$gdConverter->dump()->_print();
     $goodses = $gdConverter->getResult();
     // 對於權限不夠的,成本必須要隱藏起來,否則客人看到成本不就好笑了?
     if (!$this->get('authority.judger')->isCostValid()) {
         foreach ($goodses as $key => $goods) {
             $goods->setCost('0');
             $goods->setSn($goods->getSn(true));
         }
     }
     $count = $gdConverter->getCount();
     $res = array();
     $res['goodses'] = $goodses;
     $res['count'] = $count;
     $res['status'] = '1';
     $jsonResponse = $serializer->serialize($res, $_format);
     $responseHandler = new ResponseHandler();
     return $responseHandler->getNoncached($request, $jsonResponse, $_format);
 }
Esempio n. 9
0
 /**
  * @Route("/mobile/order", name="mobile_order", options={"expose"=true})
  * @Method("POST")
  */
 public function orderAction(Request $request)
 {
     $em = $this->getDoctrine()->getManager();
     $product = $em->find('WoojinGoodsBundle:GoodsPassport', $request->request->get('id'));
     $orders = $this->hasReadableAuth($product) ? $product->getOrders() : array();
     $serializer = \JMS\Serializer\SerializerBuilder::create()->build();
     $jsonResponse = $serializer->serialize($orders, 'json');
     $responseHandler = new ResponseHandler();
     return $responseHandler->getNoncached($request, $jsonResponse, 'json');
 }
Esempio n. 10
0
 /**
  * 取得該促銷活動已經售出之商品
  * 
  * @Route("/api/{id}/sold/{_format}", defaults={"_format"="json"}, name="promotion_api_fetch_sold", options={"expose"=true})
  * @ParamConverter("promotion", class="WoojinGoodsBundle:Promotion")
  * @Method("GET")
  */
 public function fetchSoldoutAction(Promotion $promotion, $_format)
 {
     $user = $this->get('security.token_storage')->getToken()->getUser();
     $em = $this->getDoctrine()->getManager();
     $qb = $em->createQueryBuilder();
     $qb->select('g')->from('WoojinGoodsBundle:GoodsPassport', 'g')->leftJoin('g.orders', 'o')->where($qb->expr()->eq('g.promotion', $promotion->getId()), $qb->expr()->eq('g.status', Avenue::GS_SOLDOUT), $qb->expr()->eq('o.kind', Avenue::OK_OFFICIAL));
     $products = $qb->getQuery()->getResult();
     $serializer = \JMS\Serializer\SerializerBuilder::create()->build();
     $jProducts = $serializer->serialize($products, $_format);
     $responseHandler = new ResponseHandler();
     return $responseHandler->getResponse($jProducts, $_format);
 }