Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php // see lines 8/9 & 82/83
- namespace Bom\Controller;
- //use Zend\Mvc\Controller\RestfulController;
- use Zend\Mvc\Controller\ActionController
- ,Zend\View\Model\ViewModel
- ,Bom\Model\DbTable\BomTable // TODO: **** Move data table gateway
- //,Bom\Model\BomTable
- ,Bom\Form\BomForm
- ,Bom\Form\AddBomForm
- ,Company\Model\CompanyTable
- ,Company\Model\ContactTable
- ;
- class BomController extends ActionController
- {
- protected $bomTable;
- protected $contactTable;
- protected $companyTable;
- protected $saveFilePath;
- // TODO: **** figiure out how to eliminate this constructor
- public function __construct($path = null) {
- $this->setFilePath();
- return $this;
- }
- // TODO: **** add parameter handling to allow switching scope to archived boms
- public function indexAction()
- {
- $allBOMs = $this->bomTable->fetchAll();
- $boms = array();
- foreach($allBOMs as $bom){
- $co = $this->companyTable->getCompany($bom->company_id);
- $contact = $this->contactTable->getContact($bom->contact_id_requestor);
- $boms[] = array(
- 'id' => $bom->id,
- 'company' => $co->name,
- 'contact' => $contact->aka? $contact->aka: $contact->fname.' '.$contact->lname,
- 'datetime' => date('Y-m-d',strtotime($bom->datetime_created)),
- 'rows' => $bom->row_count,
- 'notes' => $bom->notes,
- );
- }
- return new ViewModel(array(
- 'boms' => $boms,
- ));
- }
- public function addAction(){
- // trunc'd for brevity .. details avail if requested
- }
- public function editAction(){
- // trunc'd for brevity .. details avail if requested
- }
- public function archiveAction(){ // TODO: this will move record to `bom_files_archive` table
- }
- public function unArchiveAction(){ // TODO: this will move record back to `bom_files` table
- }
- protected function makeFileName($getFileInfo){ // a helper func
- if(!empty($getFileInfo['uri']['name'])){
- $filename = $getFileInfo['uri']['name']; // capture the name info
- $nameparts = pathinfo($filename); // break it into components
- $name = $nameparts['filename']; // capture the name component
- $ext = '.'.$nameparts['extension']; // capture the extention component, and prepend a dot
- $payload = $name.'_'.time().$ext; // build filename with timestamp in it
- } // end IF(!empty($filename))...
- else{
- $payload = false; // no file info provided
- }
- return $payload;
- } // end function makeFileName()
- public function setBomTable(DbTable\BomTable $bomTable){ // TODO: **** Move data table gateway
- //public function setBomTable(BomTable $bomTable){
- $this->bomTable = $bomTable;
- return $this;
- }
- public function setContactTable(ContactTable $contactTable){
- $this->contactTable = $contactTable;
- return $this;
- }
- public function setCompanyTable(CompanyTable $companyTable){
- $this->companyTable = $companyTable;
- return $this;
- }
- //TODO: **** Get this method to be called automatically via the config
- public function setFilePath($path = null) {
- // TODO: **** set a default path value in config
- $this->saveFilePath = $path? (string)$path: 'C:\wamp\NetBeansProjects\bomSlave\uploads\boms\\'; // REMEMBER the closing slash
- //echo'<pre>Value: ', $this->saveFilePath, '</pre>'; // For Testing ---->
- return $this;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement