/**
  * Action method shows and processes form used for deleting specific 
  * collection based on param id. If is collection delete confirmed, 
  * there is option used for deleting all photos in collection.
  * 
  * @before _secured, _admin
  * @param int $id   collection id
  */
 public function delete($id)
 {
     $view = $this->getActionView();
     $gallery = App_Model_Gallery::first(array('id = ?' => (int) $id), array('id', 'title', 'created'));
     if (NULL === $gallery) {
         $view->warningMessage(self::ERROR_MESSAGE_2);
         self::redirect('/admin/gallery/');
     }
     $view->set('gallery', $gallery);
     if (RequestMethods::post('submitDeleteGallery')) {
         if ($this->checkCSRFToken() !== true) {
             self::redirect('/admin/gallery/');
         }
         if (RequestMethods::post('action') == 1) {
             $fm = new FileManager();
             $configuration = Registry::get('config');
             if (!empty($configuration->files)) {
                 $pathToImages = trim($configuration->files->pathToImages, '/');
                 $pathToThumbs = trim($configuration->files->pathToThumbs, '/');
             } else {
                 $pathToImages = 'public/uploads/images';
                 $pathToThumbs = 'public/uploads/images';
             }
             $photos = App_Model_Photo::all(array('galleryId = ?' => (int) $id));
             $ids = array();
             foreach ($photos as $colPhoto) {
                 $ids[] = $colPhoto->getId();
             }
             App_Model_Photo::deleteAll(array('id IN ?' => $ids));
             $path = APP_PATH . '/' . $pathToImages . '/gallery/' . $gallery->getId();
             $pathThumbs = APP_PATH . '/' . $pathToThumbs . '/gallery/' . $gallery->getId();
             if ($path == $pathThumbs) {
                 $fm->remove($path);
             } else {
                 $fm->remove($path);
                 $fm->remove($pathThumbs);
             }
         } elseif (RequestMethods::post('action') == 2) {
             $photos = App_Model_Photo::all(array('galleryId = ?' => $id));
             $ids = array();
             foreach ($photos as $colPhoto) {
                 $ids[] = $colPhoto->getId();
             }
             App_Model_Photo::deleteAll(array('id IN ?' => $ids));
         }
         if ($gallery->delete()) {
             Event::fire('admin.log', array('success', 'Gallery id: ' . $id));
             $view->successMessage('Galerie' . self::SUCCESS_MESSAGE_3);
             self::redirect('/admin/gallery/');
         } else {
             Event::fire('admin.log', array('fail', 'Gallery id: ' . $id));
             $view->warningMessage(self::ERROR_MESSAGE_1);
             self::redirect('/admin/gallery/');
         }
     }
 }