Exemple #1
0
 public function treatAction()
 {
     $mediaMapper = new MediaMapper();
     $catId = (int) $this->getRequest()->getParam('id');
     if ($this->getRequest()->getPost('save') && $this->getRequest()->getPost('title_treat')) {
         $model = new \Modules\Media\Models\Media();
         $model->setCatId($catId);
         $model->setCatName($this->getRequest()->getPost('title_treat'));
         $mediaMapper->treatCat($model);
         $this->addMessage('Success');
         $this->redirect(array('action' => 'index'));
     }
     $this->getView()->set('cat', $mediaMapper->getCatById($catId));
 }
Exemple #2
0
 public function indexAction()
 {
     $ilchdate = new IlchDate();
     $mediaMapper = new MediaMapper();
     $this->getLayout()->getAdminHmenu()->add($this->getTranslator()->trans('media'), array('controller' => 'index', 'action' => 'index'))->add($this->getTranslator()->trans('import'), array('action' => 'index'));
     $directory = $this->getConfig()->get('media_uploadpath');
     $filetypes = $this->getConfig()->get('media_ext_img');
     $globMediaArray = glob($directory . "*.*");
     if ($this->getRequest()->getPost('save') === 'save') {
         foreach ($this->getRequest()->getPost('check_medias') as $media) {
             $upload = new \Ilch\Upload();
             $upload->setFile($media);
             $upload->setTypes($filetypes);
             $upload->setPath($directory);
             $upload->save();
             $model = new \Modules\Media\Models\Media();
             $model->setUrl($upload->getUrl());
             $model->setUrlThumb($upload->getUrlThumb());
             $model->setEnding($upload->getEnding());
             $model->setName($upload->getName());
             $model->setDatetime($ilchdate->toDb());
             $mediaMapper->save($model);
         }
         $this->addMessage('Success');
         $this->redirect(array('action' => 'index'));
     }
     $mediaListAll = $mediaMapper->getMediaListAll();
     $existsMediaArray = array();
     if (!empty($mediaListAll)) {
         foreach ($mediaListAll as $existsMedia) {
             $existsMediaArray[] = $directory . $existsMedia->getName() . '.' . $existsMedia->getEnding();
         }
     }
     $newMediaArray = array();
     foreach ($globMediaArray as $globMedia) {
         $upload = new \Ilch\Upload();
         $upload->setFile($globMedia);
         $existsUrl = $mediaMapper->getByWhere(array('url' => $directory . $upload->getName() . '.' . $upload->getEnding()));
         $existsUrlThumb = $mediaMapper->getByWhere(array('url_thumb' => $directory . $upload->getName() . '.' . $upload->getEnding()));
         if (!$existsUrl && !$existsUrlThumb) {
             $newMediaArray[] = $directory . $upload->getName() . '.' . $upload->getEnding();
         }
     }
     $this->getView()->set('media', array_diff($newMediaArray, $existsMediaArray));
     $this->getView()->set('media_ext_img', $this->getConfig()->get('media_ext_img'));
     $this->getView()->set('path', $directory);
 }
Exemple #3
0
 public function uploadAction()
 {
     $this->getLayout()->getAdminHmenu()->add($this->getTranslator()->trans('media'), array('action' => 'index'))->add($this->getTranslator()->trans('mediaUpload'), array('action' => 'upload'));
     if (!is_writable(APPLICATION_PATH . '/modules/media/static/upload/')) {
         $this->addMessage('writableMedia', 'danger');
     }
     $ilchdate = new IlchDate();
     $mediaMapper = new MediaMapper();
     if ($this->getRequest()->isPost()) {
         $upload = new \Ilch\Upload();
         $upload->setFile($_FILES['upl']['name']);
         $upload->setPath($this->getConfig()->get('media_uploadpath'));
         $upload->upload();
         $model = new \Modules\Media\Models\Media();
         $model->setUrl($upload->getUrl());
         $model->setUrlThumb($upload->getUrlThumb());
         $model->setEnding($upload->getEnding());
         $model->setName($upload->getName());
         $model->setDatetime($ilchdate->toDb());
         $mediaMapper->save($model);
     }
 }
 /**
  * Shows api content
  *
  * @param \phpOMS\Message\RequestAbstract  $request  Request
  * @param \phpOMS\Message\ResponseAbstract $response Response
  *
  * @since  1.0.0
  * @author Dennis Eichhorn <*****@*****.**>
  */
 private function apiUpload($request, $response)
 {
     $upload = new \Modules\Media\Models\Upload();
     $rndPath = str_pad(dechex(rand(0, 65535)), 4, '0', STR_PAD_LEFT);
     $upload->setOutputDir('/Modules/Media/Files/' . $rndPath[0] . $rndPath[1] . '/' . $rndPath[2] . $rndPath[3]);
     $upload->setFileName(false);
     $status = $upload->upload($_FILES);
     if ($status['success'] === \Modules\Media\Models\UploadStatus::OK) {
         $media = new \Modules\Media\Models\Media($this->app->dbPool->get());
         /* TODO: fill data */
         $media->insert();
     }
 }