Beispiel #1
0
 /**
  * @throws Exception
  */
 private function saveAdditionData($data)
 {
     $files = Session::get('files');
     if ($files) {
         $filesArray = unserialize($files);
         $media = Media\Crud::getInstance();
         $media->setUploadDir(Config::getModuleData('menu', 'full_path'));
         $dishesMedia = DishesMedia\Table::getInstance();
         foreach ($filesArray as $file) {
             $mediaId = $media->createExistOne($file);
             $dishesMediaArray = array('dishId' => $data['id'], 'mediaId' => reset($mediaId));
             $row = $dishesMedia::create($dishesMediaArray);
             $row->setFromArray($dishesMediaArray);
             $row->save();
         }
     }
     Session::delete('files');
 }
Beispiel #2
0
use Bluz\Proxy\Layout;
use Bluz\Proxy\Session;
use Bluz\Request\AbstractRequest;
return function () use($view) {
    /**
     * @var Bootstrap $this
     * @var \Bluz\View\View $view
     */
    Session::start();
    $this->useLayout('dashboard.phtml');
    Layout::breadCrumbs([$view->ahref('Dashboard', ['dashboard', 'index']), $view->ahref('Media', ['media', 'grid']), __('Upload')]);
    if (!$this->user()) {
        throw new Exception('User not found');
    }
    $userId = $this->user()->id;
    $crud = Media\Crud::getInstance();
    // get path from config
    $path = Config::getModuleData('media', 'upload_path');
    if (empty($path)) {
        throw new Exception('Upload path is not configured');
    }
    $crud->setUploadDir($path . '/' . $userId . '/media');
    $crudController = new Controller\Crud();
    $crudController->setCrud($crud);
    $result = $crudController();
    // FIXME: workaround
    if (($crudController->getMethod() == AbstractRequest::METHOD_POST or $crudController->getMethod() == AbstractRequest::METHOD_PUT) && !$result) {
        // all ok, go to grid
        $this->redirectTo('media', 'grid');
    }
    return $result;