示例#1
0
 public function editAction(Params $params, Finder $finder, Form $form, View $view)
 {
     $entity = $finder->find(['T4webTranslate' => ['Words' => ['Id' => (int) $params('id')]]]);
     if ($entity) {
         $view->setEntity($entity);
         $form->populateValues($entity->extract());
     }
     $view->setForm($form);
     return $view;
 }
示例#2
0
 public function getLocationsByCityAction(Params $params, BaseFinder $cityFinderService, BaseFinder $regionFinderService, BaseFinder $countryFinderService)
 {
     $dataLocation = $params->fromPost();
     $city = $cityFinderService->find(['RoLocations' => ['Cities' => ['Id' => $dataLocation['id']]]]);
     if (!$city) {
         $this->setError('error');
         return $this->view;
     }
     $this->view->countries = $countryFinderService->findMany(['RoLocations' => ['Countries' => []]]);
     $this->view->regions = $regionFinderService->findMany(['RoLocations' => ['Regions' => ['countryId' => $city->getCountryId()]]]);
     $this->view->cities = $cityFinderService->findMany(['RoLocations' => ['Cities' => ['regionId' => $city->getRegionId()]]]);
     $this->view->locations = $city->extract();
     return $this->view;
 }
示例#3
0
 public function saveAction(Params $params, Request $request, Response $response, Form $form, Finder $finderService, Update $updateService, Form $form, View $view)
 {
     if ($request->getMethod() !== Request::METHOD_PUT) {
         return $view;
     }
     $id = $params('id');
     $entity = $finderService->find(['T4webTranslate' => ['Words' => ['Id' => (int) $id]]]);
     if (!$entity) {
         $response->setStatusCode(Response::STATUS_CODE_404);
         $view->setErrors(['message' => 'bad params']);
         return $view;
     }
     $data = Json::decode($request->getContent(), Json::TYPE_ARRAY);
     $form->setData($data);
     if (!$form->isValid()) {
         $response->setStatusCode(Response::STATUS_CODE_404);
         $view->setErrors($form->getMessages());
         return $view;
     }
     $entity->populate($data);
     $result = $updateService->update($id, $entity->extract());
     $view->setVariables($result->extract());
     return $view;
 }