Advertisement
mOrloff

Table Gateway

Apr 2nd, 2012
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.31 KB | None | 0 0
  1. <?php    // see lines 2/3 & 9/10
  2. namespace   Bom\Model\DbTable;  // TODO: **** Move data table gateway
  3.             //Bom\Model;
  4.  
  5. use Zend\Db\TableGateway\TableGateway,
  6.     Zend\Db\Adapter\Adapter,
  7.     Zend\Db\ResultSet\ResultSet;
  8.  
  9. class BomTable extends TableGateway  // TODO: **** Move data table gateway
  10. //class DbTable_BomTable extends TableGateway
  11. {
  12.     public function __construct(Adapter $adapter = null, $databaseSchema = null,
  13.         ResultSet $selectResultPrototype = null)
  14.     {
  15.         return parent::__construct('bom_file', $adapter, $databaseSchema,
  16.             $selectResultPrototype);  // the first value is the name of the targeted table
  17.     }
  18.     public function fetchAll()
  19.     {
  20.         $resultSet = $this->select();
  21.         return $resultSet;
  22.     }
  23.     public function getBom($id)
  24.     {
  25.         $id  = (int) $id;
  26.         $rowset = $this->select(array('id' => $id));
  27.         $row = $rowset->current();
  28.         if (!$row) {
  29.             throw new \Exception("Could not find row $id");
  30.         }
  31.         return $row;
  32.     }
  33.     public function addBom($field1, $field2, $field3, $field4, $field5)
  34.     {
  35.         $data = array(
  36.             'company_id'            => $field1,
  37.             'contact_id_requestor'  => $field2,
  38.             'contact_id_uploader'   => $field3,
  39.             'uri'                   => $field4,
  40.             'notes'                 => $field5,
  41.             'datetime_created' => date('Y-m-d H:i:s'),
  42.         );
  43.         $this->insert($data);
  44.     }
  45.     public function updateBom($id, $field1, $field2, $field9)
  46.     {
  47.         $data = array(
  48.             'company_id'            => $field1,
  49.             'contact_id_requestor'  => $field2,
  50.             'notes'                 => $field9,
  51.         );
  52.         $this->update($data, array('id' => $id));
  53.     }
  54.     public function mapBom($id, $field5, $field6, $field7, $field8)
  55.     {
  56.         $data = array(
  57.             'separator'             => $field5,
  58.             'delimiter'             => $field6,
  59.             'first_data_row'        => $field7,
  60.             'row_count'             => $field8,
  61.         );
  62.         $this->update($data, array('id' => $id));
  63.     }
  64.     public function deleteBom($id)
  65.     {
  66.         $this->delete(array('id' => $id));
  67.     }
  68.     public function archiveBom($id)
  69.     {
  70.         ;
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement