Ejemplo n.º 1
0
 public function blogImages()
 {
     if (!$this->loggedIn()) {
         header('Location: index.php?c=login&m=login');
     }
     $data = array();
     if (!isset($_GET['id'])) {
         header('Location: index.php?c=blog&m=index');
     }
     $blogCollection = new BlogCollection();
     $blog = $blogCollection->getOne($_GET['id']);
     if (is_null($blog)) {
         header('Location: index.php?c=blog&m=index');
     }
     $blogImagesCollection = new BlogImagesCollection();
     $images = $blogImagesCollection->getAll(array('blog_post_id' => $_GET['id']));
     $fileUpload = new fileUpload('image');
     $file = $fileUpload->getFilename();
     $fileExtention = $fileUpload->getFileExtention();
     $imageErrors = array();
     if ($file != '') {
         $imageErrors = $fileUpload->validate();
         $newName = sha1(time()) . '.' . $fileExtention;
         $insertInfo = array('blog_post_id' => $_GET['id'], 'image' => $newName);
         if (empty($imageErrors)) {
             $imageEntity = new BlogImagesEntity();
             $obj = $imageEntity->init($insertInfo);
             $blogImagesCollection->save($obj);
             $fileUpload->upload('uploads/tours/' . $newName);
             header("Location: index.php?c=blog&m=blogImages&id=" . $_GET['id']);
         }
     } else {
     }
     $data['imageErrors'] = $imageErrors;
     $data['images'] = $images;
     $data['blogId'] = $_GET['id'];
     $this->loadView('blog/blogImages', $data);
 }