/** * Patch entity field/s data by new values * * @param int $id * @param int $className * * @return Response * * @throws AccessDeniedException * * @Rest\Patch("entity_data/{className}/{id}") * @ApiDoc( * description="Update entity property", * resource=true, * requirements = { * {"name"="id", "dataType"="integer"}, * } * ) */ public function patchAction($className, $id) { $data = json_decode($this->get('request_stack')->getCurrentRequest()->getContent(), true); list($form, $data) = $this->getManager()->patch($className, $id, $data); if ($form->getErrors(true)->count() > 0) { $view = $this->view($form, Codes::HTTP_BAD_REQUEST); } else { $view = $this->view($data, Codes::HTTP_NO_CONTENT); } $response = parent::handleView($view); return $response; }
/** * Get translations. * * @QueryParam( * name="page", * requirements="\d+", * nullable=true, * description="Page number, starting from 1. Defaults to 1." * ) * @QueryParam( * name="limit", * requirements="\d+", * nullable=true, * description="Number of items per page. Defaults to 10." * ) * @QueryParam( * name="domain", * requirements=".+", * nullable=true, * description="The translation domain. Defaults to 'messages'." * ) * @QueryParam( * name="locale", * requirements=".+", * nullable=true, * description="The translation locale." * ) * @ApiDoc( * description="Get translations", * resource=true * ) * * @return Response */ public function cgetAction() { $page = (int) $this->getRequest()->get('page', 1); $limit = (int) $this->getRequest()->get('limit', RestGetController::ITEMS_PER_PAGE); $domain = $this->getRequest()->get('domain', 'messages'); $result = $this->get('translator')->getTranslations([$domain]); $data = []; if (isset($result[$domain]) && is_array($result[$domain])) { $slice = array_slice($result[$domain], $page > 0 ? ($page - 1) * $limit : 0, $limit); foreach ($slice as $key => $val) { $data[] = ['key' => $key, 'value' => $val]; } } $view = $this->view($data, Codes::HTTP_OK); $response = parent::handleView($view); $responseContext = ['result' => $data, 'totalCount' => function () use($result, $domain) { return isset($result[$domain]) && is_array($result[$domain]) ? count($result[$domain]) : 0; }]; $includeHandler = $this->get('oro_soap.handler.include'); $includeHandler->handle(new Context($this, $this->get('request'), $response, RestGetController::ACTION_LIST, $responseContext)); return $response; }
protected function handleView(View $view) { $serializeGroups = $this->get('request')->get('serialize', null); if (is_null($serializeGroups) === false && strlen($serializeGroups) > 0) { $view->setSerializationContext(SerializationContext::create()->setGroups(array($serializeGroups))); } return parent::handleView($view); }
/** * @param mixed|View $data * @param string $action * @param array $contextValues * @param int $status Used only if data was given in raw format * * @return Response */ protected function buildResponse($data, $action, $contextValues = [], $status = Codes::HTTP_OK) { if ($data instanceof View) { $response = parent::handleView($data); } else { $headers = isset($contextValues['headers']) ? $contextValues['headers'] : []; unset($contextValues['headers']); $response = new JsonResponse($data, $status, $headers); } $includeHandler = $this->get('oro_soap.handler.include'); $includeHandler->handle(new Context($this, $this->get('request'), $response, $action, $contextValues)); return $response; }