Пример #1
0
 public function edit()
 {
     $data = $this->request->data;
     if ($this->request->is('post') and isset($data['save'])) {
         $filename = $data['file-upload']['name'];
         $file = $data['file-upload']['tmp_name'];
         $error = $data['file-upload']['error'];
         $ext = $this->getExtension($filename);
         $activ = null;
         if (isset($data['active'])) {
             $activ = 1;
         }
         if ($error) {
             $valid_file = TRUE;
             $logoUrl = null;
         } elseif (!in_array($ext, $this->img_valid_ext)) {
             $valid_file = FALSE;
             $this->set([MESSAGE => 'Please choose valide image file.', COLOR => ERROR_COLOR]);
         } elseif (in_array($ext, $this->img_valid_ext)) {
             $imgDir = new Folder(IMAGE_UPLOAD, true);
             $filename = $this->getGUID() . $filename;
             $destination = $imgDir->path . $filename;
             if (move_uploaded_file($file, $destination)) {
                 $valid_file = TRUE;
                 $logoUrl = '/img/' . $filename;
             } else {
                 $valid_file = FALSE;
             }
         }
         if ($valid_file) {
             $restaurantDto = new DownloadDTO\RestaurantShowDto($data['restaurantId'], $data['title'], $logoUrl, $data['address'], $activ, $data['area'], $data['city'], $data['country'], $data['phone']);
             $restaurantController = new RestaurantController();
             $restaurantUpdateResult = $restaurantController->updateRestaurantInfo($restaurantDto);
             if ($restaurantUpdateResult) {
                 $this->set(['suc_msg' => DTO\ErrorDto::prepareMessage(122), COLOR => SUCCESS_COLOR]);
             } else {
                 $this->set(['suc_msg' => DTO\ErrorDto::prepareMessage(123), COLOR => ERROR_COLOR]);
             }
         }
     } elseif ($this->request->is('post') and isset($data['cancel'])) {
         // $this->redirect('/');
     }
     $restaurantId = parent::readCookie('cri');
     if (isset($restaurantId)) {
         $restaurantController = new RestaurantController();
         $allRestaurants = $restaurantController->getAdminRestaurants(array($restaurantId));
         $this->set(['data' => $allRestaurants, 'rites' => false]);
     } else {
         $this->redirect('login');
     }
 }