コード例 #1
0
ファイル: OrdersService.php プロジェクト: netoudi/apigility
 public function find($id)
 {
     $order = $this->ordersRepository->find($id);
     $client = $this->clientsRepository->findBy(['id' => $order->getClientId()])->current();
     $ptype = $this->ptypesRepository->findBy(['id' => $order->getPtypeId()])->current();
     $user = $this->usersRepository->findBy(['id' => $order->getUserId()])->current();
     $sql = $this->ordersRepository->getItemTable()->getSql();
     $select = $sql->select();
     $select->join('products', 'order_items.product_id = products.id', ['product_name' => 'name'])->where(['order_id' => $order->getId()]);
     $items = $this->ordersRepository->getItemTable()->selectWith($select);
     foreach ($items as $item) {
         $order->addItem($item);
     }
     $hydrator = new ClassMethods();
     $hydrator->addStrategy('items', new OrdersItemsHydratorStrategy(new ClassMethods()));
     $order->setClient($hydrator->extract($client));
     $order->setPtype($hydrator->extract($ptype));
     $order->setUser($hydrator->extract($user));
     $result = $hydrator->extract($order);
     unset($result['client_id']);
     unset($result['ptype_id']);
     unset($result['user_id']);
     unset($result['user']['username']);
     unset($result['user']['password']);
     return $result;
 }
コード例 #2
0
 /**
  * Update a resource
  *
  * @param  mixed $id
  * @param  mixed $data
  * @return ApiProblem|mixed
  */
 public function update($id, $data)
 {
     if (!$this->userService->isAdmin()) {
         return new ApiProblem(403, 'Only admin can update clients.');
     }
     return $this->repository->update($id, $data);
 }
コード例 #3
0
 /**
  * Update a resource
  *
  * @param  mixed $id
  * @param  mixed $data
  * @return ApiProblem|mixed
  */
 public function update($id, $data)
 {
     $user = $this->userRepository->findByUsername($this->getIdentity()->getRoleId());
     if ($user->getRole() != "admin") {
         return new ApiProblem("403", "The user has not access to this info.");
     }
     return $this->repository->update($id, (array) $data);
 }
コード例 #4
0
 /**
  * Update a resource
  *
  * @param  mixed $id
  * @param  mixed $data
  * @return ApiProblem|mixed
  */
 public function update($id, $data)
 {
     $userRepository = $this->repository->getUsersRepository();
     $user = $userRepository->findByUsername($this->getIdentity()->getRoleId());
     if ($user->getRole() == "admin") {
         return $this->repository->update($id, $data);
     }
     return new ApiProblem(403, 'Sem autorização para Editar');
 }
コード例 #5
0
 /**
  * Update a resource
  *
  * @param  mixed $id
  * @param  mixed $data
  * @return ApiProblem|mixed
  */
 public function update($id, $data)
 {
     $usuarioLogado = $this->getUsuarioLogado();
     if ($usuarioLogado->getRole() === 'admin') {
         return $this->repository->update($id, $data);
     } else {
         return new ApiProblem(403, "Apenas usuários 'admin' podem editar os produtos");
     }
 }
コード例 #6
0
ファイル: ClientsResource.php プロジェクト: netoudi/apigility
 /**
  * Update a resource
  *
  * @param  mixed $id
  * @param  mixed $data
  * @return ApiProblem|mixed
  */
 public function update($id, $data)
 {
     try {
         $this->authService->hasRole('admin');
         return $this->repository->update($id, $data);
     } catch (\Exception $e) {
         return new ApiProblem($e->getCode(), $e->getMessage());
     }
 }
コード例 #7
0
 public function findByName($name)
 {
     return $this->clientsRepository->findByName($name);
 }