Advertisement
mOrloff

Contoller

Apr 2nd, 2012
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.75 KB | None | 0 0
  1. <?php    // see lines 8/9 & 82/83
  2.  
  3. namespace Bom\Controller;
  4.  
  5. //use Zend\Mvc\Controller\RestfulController;
  6. use Zend\Mvc\Controller\ActionController
  7.     ,Zend\View\Model\ViewModel
  8.     ,Bom\Model\DbTable\BomTable  // TODO: **** Move data table gateway
  9.     //,Bom\Model\BomTable
  10.     ,Bom\Form\BomForm
  11.     ,Bom\Form\AddBomForm
  12.     ,Company\Model\CompanyTable
  13.     ,Company\Model\ContactTable
  14.     ;
  15.  
  16. class BomController extends ActionController
  17. {
  18.     protected $bomTable;
  19.     protected $contactTable;
  20.     protected $companyTable;
  21.     protected $saveFilePath;
  22.  
  23.     // TODO: **** figiure out how to eliminate this constructor
  24.     public function __construct($path = null) {
  25.         $this->setFilePath();
  26.         return $this;
  27.     }
  28.    
  29.     // TODO: **** add parameter handling to allow switching scope to archived boms
  30.     public function indexAction()
  31.     {
  32.         $allBOMs = $this->bomTable->fetchAll();
  33.         $boms = array();
  34.         foreach($allBOMs as $bom){
  35.             $co = $this->companyTable->getCompany($bom->company_id);
  36.             $contact = $this->contactTable->getContact($bom->contact_id_requestor);
  37.             $boms[] = array(
  38.                 'id'   => $bom->id,
  39.                 'company'   => $co->name,
  40.                 'contact'   => $contact->aka? $contact->aka: $contact->fname.' '.$contact->lname,
  41.                 'datetime'  => date('Y-m-d',strtotime($bom->datetime_created)),
  42.                 'rows'      => $bom->row_count,
  43.                 'notes'     => $bom->notes,
  44.             );
  45.         }
  46.                
  47.         return new ViewModel(array(
  48.             'boms' => $boms,
  49.         ));
  50.     }
  51.    
  52.     public function addAction(){
  53.         // trunc'd for brevity  .. details avail if requested
  54.     }
  55.    
  56.     public function editAction(){
  57.         // trunc'd for brevity  .. details avail if requested
  58.     }
  59.    
  60.     public function archiveAction(){  // TODO: this will move record to `bom_files_archive` table
  61.     }
  62.    
  63.     public function unArchiveAction(){  // TODO: this will move record back to `bom_files` table
  64.     }
  65.    
  66.    
  67.     protected function makeFileName($getFileInfo){    // a helper func
  68.         if(!empty($getFileInfo['uri']['name'])){            
  69.             $filename = $getFileInfo['uri']['name'];  // capture the name info
  70.             $nameparts = pathinfo($filename);  // break it into components
  71.             $name = $nameparts['filename'];  // capture the name component
  72.             $ext = '.'.$nameparts['extension'];  // capture the extention component, and prepend a dot
  73.             $payload = $name.'_'.time().$ext;  // build filename with timestamp in it
  74.         }  // end IF(!empty($filename))...
  75.         else{
  76.             $payload = false;  // no file info provided
  77.         }        
  78.         return $payload;
  79.     }  // end function makeFileName()
  80.    
  81.    
  82.     public function setBomTable(DbTable\BomTable $bomTable){  // TODO: **** Move data table gateway
  83.     //public function setBomTable(BomTable $bomTable){
  84.         $this->bomTable = $bomTable;
  85.         return $this;
  86.     }
  87.     public function setContactTable(ContactTable $contactTable){
  88.         $this->contactTable = $contactTable;
  89.         return $this;
  90.     }    
  91.     public function setCompanyTable(CompanyTable $companyTable){
  92.         $this->companyTable = $companyTable;
  93.         return $this;
  94.     }
  95.     //TODO: **** Get this method to be called automatically via the config
  96.     public function setFilePath($path = null) {
  97.       // TODO: **** set a default path value in config
  98.         $this->saveFilePath = $path? (string)$path: 'C:\wamp\NetBeansProjects\bomSlave\uploads\boms\\'; // REMEMBER the closing slash
  99.         //echo'<pre>Value: ', $this->saveFilePath, '</pre>';  // For Testing ---->
  100.         return $this;
  101.     }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement