/**
* 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();
}