Exemple #1
0
 /**
  * @param ServerRequestInterface $request
  * @return ResponseInterface
  */
 public function update(ServerRequestInterface $request)
 {
     $validator = new Validator(['name' => [Validator::required(), Validator::length(2, 20)]]);
     if (!$validator->validate($request->getParsedBody())) {
         return Response::factory(400, $validator->getErrorMessage());
     }
     $id = $request->getAttribute('id');
     $name = Input::fromBody('name');
     $this->repository->where(compact('id'))->update(compact('name'));
     return Response::redirect('/admin/settings/categories');
 }
Exemple #2
0
 /**
  * @param ServerRequestInterface $request
  * @return ResponseInterface
  */
 public function update(ServerRequestInterface $request)
 {
     $validator = new Validator(['title' => [Validator::required(), Validator::length(1, 100)], 'category' => [Validator::required()]]);
     if (!$validator->validate($request->getParsedBody())) {
         return Response::factory(400, $validator->getErrorMessage());
     }
     $title = Input::fromBody('title');
     $category = Input::fromBody('category');
     $contents = Input::fromBody('contents');
     $url = Input::fromBody('url');
     $link = Input::fromBody('link');
     $filter = Input::fromBody('filter');
     $facebook = Input::fromBody('facebook');
     $master = Input::fromBody('master');
     $address = Input::fromBody('address');
     $phone = Input::fromBody('phone');
     $time = Input::fromBody('time');
     $seat = Input::fromBody('seat');
     $parking = Input::fromBody('parking');
     $lat = Input::fromBody('lat');
     $lng = Input::fromBody('lng');
     $event = Input::fromBody('event');
     $eventTitle = Input::fromBody('eventTitle');
     $eventContents = Input::fromBody('eventContents');
     $eventLink = Input::fromBody('eventLink');
     $valuesToUpdate = ['title' => $title, 'category_id' => $category, 'contents' => $contents, 'extra' => ['url' => $url, 'link' => $link, 'store' => ['filter' => $filter, 'facebook' => $facebook, 'master' => $master, 'address' => $address, 'phone' => $phone, 'time' => $time, 'seat' => $seat, 'parking' => $parking, 'lat' => $lat, 'lng' => $lng, 'event' => $event], 'event' => ['eventTitle' => $eventTitle, 'eventContents' => $eventContents, 'eventLink' => $eventLink]]];
     $files = $request->getUploadedFiles();
     $post = $this->repository->get($request->getAttribute('id'));
     $valuesToUpdate['thumbnail'] = $this->fileParser($files['thumbnail']);
     if (!isset($valuesToUpdate['thumbnail'])) {
         $valuesToUpdate['thumbnail'] = isset($post['thumbnail']) ? $post['thumbnail'] : '';
         if (Input::fromBody('thumbnailDelete') === '1') {
             $valuesToUpdate['thumbnail'] = '';
         }
     }
     for ($i = 0; $i < 4; $i++) {
         $file = $this->fileParser($files['eventImage' . $i]);
         if (isset($file)) {
             $valuesToUpdate['extra']['event']['eventImage'][$i] = $file;
         } else {
             $valuesToUpdate['extra']['event']['eventImage'][$i] = isset($post['extra']['event']['eventImage'][$i]) ? $post['extra']['event']['eventImage'][$i] : '';
             if (Input::fromBody('eventImageDelete' . $i) === '1') {
                 $valuesToUpdate['extra']['event']['eventImage'][$i] = '';
             }
         }
     }
     $this->repository->where(['id' => $request->getAttribute('id')])->update($valuesToUpdate);
     return Response::redirect('/admin/posts');
 }
Exemple #3
0
 /**
  * @param ServerRequestInterface $request
  * @return ResponseInterface
  */
 public function update(ServerRequestInterface $request)
 {
     $validator = new Validator(['email' => [Validator::required(), Validator::email()], 'username' => [Validator::required(), Validator::length(3, 20)], 'password' => Validator::equals('password2')]);
     if (!$validator->validate($request->getParsedBody())) {
         return Response::factory(400, $validator->getErrorMessage());
     }
     $email = Input::fromBody('email');
     $username = Input::fromBody('username');
     $password = Input::fromBody('password');
     $level = Input::fromBody('level');
     $valuesToUpdate = compact('email', 'username', 'level');
     if ($password) {
         $valuesToUpdate['password'] = $password;
     }
     $this->repository->where(['username' => $request->getAttribute('username')])->update($valuesToUpdate);
     return Response::redirect('/admin/users/' . $username);
 }