/**
  * {@inheritDoc}
  */
 public function getStatus()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getStatus', array());
     return parent::getStatus();
 }
 public function bannerAction(Request $request)
 {
     /****** Admin session checking**********/
     $response = $this->checkAdmin($request->getSession());
     if ($response) {
         return $response;
     }
     $type = $this->container->get('request')->get('type');
     $id = $this->container->get('request')->get('id');
     if (empty($type) || empty($id)) {
         return $this->redirect($this->generateUrl('mytrip_admin_homepage'));
     }
     $em = $this->getDoctrine()->getManager();
     $render_array = array();
     if ($type == "destination") {
         $destination_query = $em->createQuery("SELECT d FROM MytripAdminBundle:Destination d WHERE d.destinationId={$id}");
         $destination = $destination_query->getArrayResult();
         $render_array = $destination;
     } elseif ($type == "hostal") {
         $hostal_query = $em->createQuery("SELECT h FROM MytripAdminBundle:Hostal h WHERE h.hostalId={$id}");
         $hostal = $hostal_query->getArrayResult();
         $render_array = $hostal;
     } elseif ($type == "story") {
         $story_query = $em->createQuery("SELECT h FROM MytripAdminBundle:Story h WHERE h.storyId={$id}");
         $story = $story_query->getArrayResult();
         $render_array = $story;
     }
     if ($request->getMethod() == "POST") {
         $banner = new Banner();
         if ($request->files->get('image') != '') {
             $awsAccessKey = $this->container->get('mytrip_admin.helper.amazon')->getOption('awsAccessKey');
             $awsSecretKey = $this->container->get('mytrip_admin.helper.amazon')->getOption('awsSecretKey');
             $bucket = $this->container->get('mytrip_admin.helper.amazon')->getOption('bucket');
             \S3::setAuth($awsAccessKey, $awsSecretKey);
             $em = $this->getDoctrine()->getManager();
             $banner->setBannerType(ucfirst($type));
             $banner->setTypeId($id);
             $ext = $request->files->get('image')->getClientOriginalExtension();
             $filename = $this->str_rand(8, "alphanum") . "." . $ext;
             $tmpfile = $request->files->get('image')->getPathName();
             $putobject = \S3::putObjectFile($tmpfile, $bucket, $filename, \S3::ACL_PUBLIC_READ);
             if ($putobject) {
                 //$request->files->get('image')->move("img/banner/".$type,$filename);
                 $banner->setImage($filename);
                 $banner->setStatus('Active');
                 $em->persist($banner);
                 $em->flush();
             } else {
                 $this->get('session')->getFlashBag()->add('error', '<div class="success msg">Something problem to upload image to server</div>');
             }
         }
         $this->get('session')->getFlashBag()->add('error', '<div class="success msg">Banner image successfully added</div>');
         return $this->redirect($this->generateUrl('mytrip_admin_banner', array('type' => $type, 'id' => $id)));
     }
     if (empty($render_array)) {
         return $this->redirect($this->generateUrl('mytrip_admin_homepage'));
     }
     $em = $this->getDoctrine()->getManager();
     $banner_query = $em->createQuery("SELECT b FROM MytripAdminBundle:Banner b WHERE b.typeId={$id} AND b.bannerType='" . ucfirst($type) . "'");
     $banner = $banner_query->getArrayResult();
     $render_array = array('banner' => $banner, $type => $render_array);
     return $this->render('MytripAdminBundle:Default:banner.html.php', $render_array);
 }