예제 #1
0
 /**
  * Add action.
  *
  * @access public
  * @param Application $app Silex application
  * @param Request $request Request object
  * @return string Output
  */
 public function addAction(Application $app, Request $request)
 {
     $id = (int) $request->get('id', 0);
     $roomsModel = new RoomsModel($app);
     if (!$roomsModel->security($id)) {
         return $app->redirect($app['url_generator']->generate('rooms'), 301);
     }
     $data = array('room_id' => $id);
     $form = $app['form.factory']->createBuilder(new PhotoForm($app), $data)->getForm();
     $form->remove('room_id');
     if ($request->isMethod('POST')) {
         $form->bind($request);
         if ($form->isValid()) {
             try {
                 $data = $form->getData();
                 $files = $request->files->get($form->getName());
                 $mediaPath = dirname(dirname(dirname(__FILE__))) . '/web/upload';
                 $photosModel = new PhotosModel($app);
                 $photosModel->saveImage($files, $mediaPath, $data);
                 $app['session']->getFlashBag()->add('message', array('type' => 'success', 'content' => $app['translator']->trans('File successfully uploaded, you can add next photo to gallery')));
             } catch (Exception $e) {
                 $app['session']->getFlashBag()->add('message', array('type' => 'error', 'content' => $app['translator']->trans('Can not upload file.')));
             }
         } else {
             $app['session']->getFlashBag()->add('message', array('type' => 'error', 'content' => $app['translator']->trans('Form contains invalid data.')));
         }
     }
     $this->view['form'] = $form->createView();
     $this->view['id'] = $id;
     return $app['twig']->render('photos/add.twig', $this->view);
 }
예제 #2
0
 /**
  * Index action.
  *
  * @access public
  * @param Silex\Application $app Silex application
  * @param Symfony\Component\HttpFoundation\Request $request Request object
  * @return string Output
  */
 public function indexAction(Application $app, Request $request)
 {
     try {
         $roomsModel = new RoomsModel($app);
         $this->view['photos'] = $roomsModel->getMainGallery();
     } catch (\PDOException $e) {
         $app->abort(500, $app['translator']->trans('Something went wrong.'));
     }
     return $app['twig']->render('index/index.twig', $this->view);
 }
예제 #3
0
 /**
  * Delete action.
  *
  * @access public
  * @param Silex\Application $app Silex application
  * @param Symfony\Component\HttpFoundation\Request $request Request object
  * @return string Output
  */
 public function deleteAction(Application $app, Request $request)
 {
     try {
         $roomsModel = new RoomsModel($app);
         $id = (int) $request->get('id', null);
         if (!$roomsModel->security($id)) {
             return $app->redirect($app['url_generator']->generate('rooms'), 301);
         }
         $ok = (int) $request->get('ok', null);
         if ($ok) {
             $roomsModel->delete($id);
             $app['session']->getFlashBag()->add('message', array('type' => 'success', 'content' => $app['translator']->trans('Room deleted.')));
             return $app->redirect($app['url_generator']->generate('rooms'), 301);
         }
         $this->view['id'] = $id;
     } catch (\PDOException $e) {
         $app->abort(500, $app['translator']->trans('Something went wrong.'));
     }
     return $app['twig']->render('rooms/delete.twig', $this->view);
 }