Skip to content

Instantly share code, notes, and snippets.

@jfabian
Created July 9, 2014 14:40
Show Gist options
  • Save jfabian/84f275c771605ea78306 to your computer and use it in GitHub Desktop.
Save jfabian/84f275c771605ea78306 to your computer and use it in GitHub Desktop.
public function itemsAction()
{
$idProduct = $this->_getParam('id');
$dataProduct = $this->_productsModel->getData($idProduct);
$itemsProductModel = new Application_Model_ItemsProduct();
$form = new Application_Form_FormItemsProduct();
if ($this->getRequest()->isPost()) {
$params = $this->getRequest()->getPost();
if ($form->isValid($params)) {
$file = '';
unset($_FILES['files']);
$upload = new Zend_File_Transfer_Adapter_Http();
$upload->setDestination(APPLICATION_PATH.'/../public/elements/resources/files/');
if (count($form->file->getFileName()) != 0) {
//$upload = $form->getElement('file')->getTransferAdapter();
$upload->setOptions(array('ignoreNoFile'=>true));
$originalFilename = pathinfo($form->file->getFileName());
$newFilename = 'fileCourse-' . uniqid() . '.' . $originalFilename['extension'];
$form->file->addFilter('Rename', $newFilename);
try {
$upload->receive($form->getValue('file'));
} catch (Zend_File_Transfer_Exception $e) {
$e->getMessage();
exit;
}
$file = $newFilename;
}
$upload->setDestination(APPLICATION_PATH.'/../public/elements/resources/images/');
$preview = '';
if (count($form->preview->getFileName()) != 0) {
$upload->setOptions(array('ignoreNoFile'=>true));
$originalFilename = pathinfo($form->preview->getFileName());
$newFilename = 'previewCourse-' . uniqid() . '.' . $originalFilename['extension'];
$form->preview->addFilter('Rename', $newFilename);
try {
$upload->receive($form->getValue('preview'));
} catch (Zend_File_Transfer_Exception $e) {
$e->getMessage();
exit;
}
$preview = $newFilename;
}
$itemsProductModel->insert(
array(
'name' => $params['name'],
'description' => $params['description'],
'file' => $file,
'preview' => $preview,
'id_product' => $idProduct,
'date_register' => date('Y-m-d H:i:s')
)
);
$this->_redirect('/admin/products/items/id/'.$idProduct);
}
}
$this->view->items = $itemsProductModel->getAll($idProduct);
$this->view->dataProduct = $dataProduct;
$this->view->form = $form;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment