/** * Get select from options from the Content and Categories * * @param boolean $contentLoaded * @param boolean $categoriesLoaded * @return array */ public function getSelectFrom($contentLoaded = false, $categoriesLoaded = false) { $options = ['content' => [], 'categories' => []]; if ($contentLoaded) { $sess = Session::getInstance(); unset($sess->lastSortField); unset($sess->lastSortOrder); unset($sess->lastPage); $types = \Phire\Content\Table\ContentTypes::findAll(); foreach ($types->rows() as $type) { $content = new \Phire\Content\Model\Content(); $content->getAll($type->id, 'id'); $options['content'][$type->name] = $content->getFlatMap(); } } if ($categoriesLoaded) { $categories = new \Phire\Categories\Model\Category(); $categories->getAll(); $options['categories'] = $categories->getFlatMap(); } return $options; }
/** * batch action method * * @param int $lid * @return void */ public function batch($lid) { $library = new Model\MediaLibrary(); $library->getById($lid); if (!isset($library->id)) { $this->redirect(BASE_PATH . APP_URI . '/media'); } $browser = new Browser(); $dragAndDrop = !($browser->isMsie() && $browser->getVersion() <= 9); if (null !== $this->request->getQuery('basic') && $this->request->getQuery('basic')) { $this->prepareView('media/batch.phtml'); $this->view->title = 'Media : ' . $library->name . ' : Batch Upload'; $this->view->lid = $lid; $this->view->max = $library->getMaxFilesize(); $this->view->dragAndDrop = $dragAndDrop; $fields = $this->application->config()['forms']['Phire\\Media\\Form\\Batch']; $fields[0]['library_id']['value'] = $lid; $fields[2]['batch_archive']['label'] = 'Batch Archive File <span class="batch-formats">(' . implode(', ', array_keys(\Pop\Archive\Archive::getFormats())) . ')</span>'; $fields[2]['batch_archive']['validators'] = new \Pop\Validator\RegEx('/^.*\\.(' . implode('|', array_keys(\Pop\Archive\Archive::getFormats())) . ')$/i', 'That file archive type is not allowed.'); $this->view->form = new Form\Batch($fields); if ($this->request->isPost()) { $settings = $library->getSettings(); $folder = $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . DIRECTORY_SEPARATOR . $library->folder; if (!file_exists($folder)) { $library->createFolder($library->folder); } $values = !empty($_FILES['file_1']) && !empty($_FILES['file_1']['name']) ? array_merge($this->request->getPost(), ['file_1' => $_FILES['file_1']['name']]) : $this->request->getPost(); $this->view->form->addFilter('htmlentities', [ENT_QUOTES, 'UTF-8'])->setFieldValues($values, $settings); if ($this->view->form->isValid()) { $this->view->form->clearFilters()->addFilter('html_entity_decode', [ENT_QUOTES, 'UTF-8'])->filter(); $media = new Model\Media(); $media->batch($_FILES, $this->view->form->getFields()); $this->view->id = $media->ids; $this->sess->setRequestValue('saved', true); $this->redirect(BASE_PATH . APP_URI . '/media/' . $lid . '?basic=1'); } } } else { if (!$dragAndDrop) { $this->redirect(BASE_PATH . APP_URI . '/media/batch/' . $lid . '?basic=1'); } else { $this->prepareView('media/batch-ajax.phtml'); $this->view->title = 'Media : ' . $library->name . ' : Batch Upload'; $this->view->lid = $lid; $this->view->max = $library->getMaxFilesize(); $this->view->categoriesForBatch = null; if (class_exists('Phire\\Categories\\Model\\Category')) { $config = $this->application->module('phire-categories'); $cat = new \Phire\Categories\Model\Category([], $config); $cat->getAll(); if (count($cat->getFlatMap()) > 0) { $categoryValues = $cat->getCategoryValues(); $categories = new \Pop\Form\Element\CheckboxSet('categories', $categoryValues); $categories->setLabel('Categories'); $this->view->categoriesForBatch = $categories; } } } } $this->send(); }