[TYPO3-dev] getter_setter script

Lars Haendler typo3 at larshaendler.com
Thu Sep 4 11:10:53 CEST 2008


Hi,

I'm hoping I'm at the right list. If not just plz tell where I should 
post this.

For me recent projects I wrote a small script that allows me to generate 
a getter_setter class for any DB table of the TYPO3 Installatin. Most of 
the time I have to do the same thing with an class.


I will paste a sample class generated from this script here. What I'd 
like to know is if there are grave errors of thinking and if there's a 
way to make a new instance of the object without the pid.

If someone is interessted I could try to do an extension from my current 
script.



<?php
require_once(PATH_tslib.'class.tslib_pibase.php');

class tx_apxorderform_medicine extends tslib_pibase {
    protected $uid;
    protected $pid;
    protected $tstamp;
    protected $crdate;
    protected $cruser_id;
    protected $deleted;
    protected $hidden;
    protected $order_uid;
    protected $title;


    public function __construct($uid=0,$pid=0) {
       $this->pid=$pid;
       $this->pi_loadLL();
       $this->uid=intval($uid);
       if($this->uid>0) {
          $this->init();
       }
       else {
          return false;
       }
    }


    private function init() {

       $query = $GLOBALS['TYPO3_DB']->SELECTquery(
       '*',
       'tx_apxorderform_medicine',
       'uid='.$this->uid);

       $res=$GLOBALS['TYPO3_DB']->sql(TYPO3_db,$query.';');
       $row=$GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);

       $this->uid=$row['uid'];
       $this->pid=$row['pid'];
       $this->tstamp=$row['tstamp'];
       $this->crdate=$row['crdate'];
       $this->cruser_id=$row['cruser_id'];
       $this->deleted=$row['deleted'];
       $this->hidden=$row['hidden'];
       $this->order_uid=$row['order_uid'];
       $this->title=$row['title'];
    }


    public function getUid(){
       return $this->uid;
    }

    public function getTstamp(){
       return $this->tstamp;
    }

    public function getCrdate(){
       return $this->crdate;
    }

    public function getDeleted(){
       return $this->deleted;
    }

    public function getHidden(){
       return $this->hidden;
    }

    public function getOrder_uid(){
       return $this->order_uid;
    }

    public function getTitle(){
       return $this->title;
    }

    public function setDeleted($value){
      $this->deleted=intval($value);
    }

    public function setHidden($value){
      $this->hidden=intval($value);
    }

    public function setOrder_uid($value){
      $this->order_uid=$value;
    }

    public function setTitle($value){
      $this->title=$value;
    }


    public function insertRecord() {

       $insertArray = array(
          'pid'=>$this->pid,
          'tstamp'=>time(),
          'crdate'=>time(),
          'deleted'=>$this->deleted,
          'hidden'=>$this->hidden,
          'order_uid'=>$this->order_uid,
          'title'=>$this->title,
       );

       $queryInsert = $GLOBALS['TYPO3_DB']->exec_INSERTquery(
          'tx_apxorderform_medicine',  //table
          $insertArray // insert array
       );

       $this->uid = $GLOBALS['TYPO3_DB']->sql_insert_id();
    }


    public function updateRecord() {

       $updateArray = array(
          'pid'=>$this->pid,
          'tstamp'=>time(),
          'deleted'=>$this->deleted,
          'hidden'=>$this->hidden,
          'order_uid'=>$this->order_uid,
          'title'=>$this->title,
       );

       $queryInsert = $GLOBALS['TYPO3_DB']->exec_UPDATEquery(
          'tx_apxorderform_medicine',  //table
          'uid='.$this->uid, // where clause
          $updateArray // insert array
       );
    }


    public function deleteRecord () {
       $updateArray = array(
          'deleted' => '1',
       );
       $queryUpdate = $GLOBALS['TYPO3_DB']->exec_UPDATEquery(
          'tx_apxorderform_medicine',  //table
          'uid='.$this->uid, // where clause
          $updateArray // insert array
       );
    }

}?>




More information about the TYPO3-dev mailing list