Created
July 9, 2014 01:20
-
-
Save jfabian/9472c181d602fe8e3c2b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Admin_CompanyController extends App_Controller_Action_Admin | |
{ | |
protected $_companyModel; | |
public function init() | |
{ | |
parent::init(); | |
$this->appendCurrentPageTitle("Company"); | |
$this->_companyModel = new Application_Model_Company(); | |
} | |
public function indexAction() | |
{ | |
$this->view->companies = $this->_companyModel->getAll(); | |
} | |
public function addAction() | |
{ | |
$formCompany = new Application_Form_FormCompany(); | |
$companyAreaModel = new Application_Model_CompanyArea(); | |
if ($this->getRequest()->isPost()) { | |
$params = $this->getRequest()->getPost(); | |
if ($formCompany->isValid($params)) { | |
$logo = ''; | |
if (count($formCompany->logo->getFileName()) != 0) { | |
$upload = $formCompany->getElement('logo')->getTransferAdapter(); | |
$originalFilename = pathinfo($formCompany->logo->getFileName()); | |
$newFilename = 'logocompany-' . uniqid() . '.' . $originalFilename['extension']; | |
$formCompany->logo->addFilter('Rename', $newFilename); | |
$upload->receive(); | |
$logo = $newFilename; | |
} | |
$dataArea = $companyAreaModel->getDataByNameArea($params['area']); | |
if (count($dataArea) == 0) { | |
$params['area_id'] = $companyAreaModel->insert( | |
array( | |
'name' => trim($params['area']), | |
'date_register' => date('Y-m-d H:i:s') | |
) | |
); | |
} else { | |
$params['area_id'] = $dataArea[0]['id']; | |
} | |
unset($params['MAX_FILE_SIZE']); | |
unset($params['area']); | |
$params['logo'] = $logo; | |
$params['date_register'] = date('Y-m-d H:i:s'); | |
$this->_companyModel->insert($params); | |
$this->_redirect('/admin/company'); | |
} | |
} | |
$this->view->formCompany = $formCompany; | |
} | |
public function editAction() | |
{ | |
$idCompany = $this->_getParam('id'); | |
$formCompany = new Application_Form_FormCompany(); | |
$companyAreaModel = new Application_Model_CompanyArea(); | |
$dataCompany = $this->_companyModel->getData($idCompany); | |
$formCompany->isValid($dataCompany); | |
if ($this->getRequest()->isPost()) { | |
$params = $this->getRequest()->getPost(); | |
if ($formCompany->isValid($params)) { | |
$logo = ''; | |
if (count($formCompany->logo->getFileName()) != 0) { | |
$upload = $formCompany->getElement('logo')->getTransferAdapter(); | |
$originalFilename = pathinfo($formCompany->logo->getFileName()); | |
$newFilename = 'logocompany-' . uniqid() . '.' . $originalFilename['extension']; | |
$formCompany->logo->addFilter('Rename', $newFilename); | |
$upload->receive(); | |
$logo = $newFilename; | |
$params['logo'] = $logo; | |
} | |
$dataArea = $companyAreaModel->getDataByNameArea($params['area']); | |
if (count($dataArea) == 0) { | |
$params['area_id'] = $companyAreaModel->insert( | |
array( | |
'name' => trim($params['area']), | |
'date_register' => date('Y-m-d H:i:s') | |
) | |
); | |
} else { | |
$params['area_id'] = $dataArea[0]['id']; | |
} | |
unset($params['MAX_FILE_SIZE']); | |
unset($params['area']); | |
$params['date_update'] = date('Y-m-d H:i:s'); | |
$this->_companyModel->update( | |
$params, | |
$this->_companyModel->getAdapter()->quoteInto('id = ?', $idCompany) | |
); | |
$this->_redirect('/admin/company'); | |
} | |
} | |
$this->view->formCompany = $formCompany; | |
$this->view->dataCompany = $dataCompany; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment