Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php] nowe obiekty i dodawanie danych do bazy, proste dodawanie nowych obiektów
dantekir
post
Post #1





Grupa: Zarejestrowani
Postów: 66
Pomógł: 0
Dołączył: 14.06.2004
Skąd: Świętochłowice

Ostrzeżenie: (0%)
-----


Witam,
Dopiero zaczynam z obiektowym i nie wiem jak ugryźć problem dodawania nowych obiektów do bazy danych.
Moje klasy wyglądają tak:
  1. <?php
  2. require_once 'interface.Validate.php';
  3. /**
  4.  * class PropertyObject
  5.  *
  6.  */
  7. abstract class PropertyObject implements Validate
  8. {
  9.  
  10.  /** Aggregations: */
  11.  
  12.  /** Compositions: */
  13.  
  14.   /*** Attributes: ***/
  15.  
  16.  /**
  17.    *
  18.    * @access protected
  19.    */
  20.  
  21.  protected $propertyTable =array ();
  22.  protected $changedProperties= array();
  23.  protected $data;
  24.  protected $errors = array();
  25.  
  26.  
  27.  public function __construct($arData){
  28.      $this->data=$arData;
  29.  }
  30.  
  31.  function __get($propertyName){
  32.      if(!array_key_exists($propertyName, $this->propertyTable))
  33.            throw new Exception("Błędna własność \"$propertyName\"!  ");
  34.  
  35.      if(method_exists($this, 'get'.$propertyName)){
  36.          return call_user_func(array($this, 'get'.$propertyName));
  37.      } else {
  38.  
  39.          return $this->data[$this->propertyTable[$propertyName]];
  40.      }
  41.  }
  42.  
  43.  function __set($propertyName, $value){
  44.      if(!array_key_exists($propertyName, $this->propertyTable))
  45.        throw new Exception("Błędna własność \"$propertyName\"  ");
  46.      if(method_exists($this, 'set'.$propertyName)){
  47.          return call_user_func(
  48.              array($this,'set'.$propertyName),
  49.              $value
  50.          );
  51.      } else {
  52.          //jeżeli wartość własności uległa zmianie i nie ma jej
  53.          //jeszcze w tabeli chengedProperties, zostanie do niej dołączona
  54.          if($this->propertyTable[$propertyName]!=$value &&
  55.              !in_array($propertyName,$this->changedProperties)){
  56.                $this->changedProperties[]=$propertyName;
  57.              }
  58.          $this->data[$this->propertyTable[$propertyName]] = $value;
  59.      }
  60.  }
  61.  
  62.  
  63.  /**
  64.    *
  65.    *
  66.    * @return
  67.    * @access public
  68.    */
  69.  function validate( ) {
  70.      
  71.  } // end of member function validate
  72.  
  73.  function errormsg(){
  74.      foreach ($this->errors as $value) {
  75.           print ('!!!!'.$value.'!!!!');
  76.      }
  77.  }
  78.  
  79. } // end of PropertyObject
  80. ?>


  1. <?php
  2. require_once 'class.PropertyObject.php';
  3. require_once 'class.Collection.php';
  4. require_once 'class.Telefon.php';
  5. require_once 'class.Adres.php';
  6. require_once 'class.Email.php';
  7. require_once 'class.Organizator.php';
  8. require_once 'class.Firma.php';
  9. require_once 'class.TypOsoby.php';
  10. /**
  11.  * Description of classJednostka
  12.  *
  13.  * @author daniel
  14.  */
  15. abstract class Jednostka extends PropertyObject
  16. {
  17.    public $telephones = array();
  18.    public $emails = array();
  19.    public $adresses = array();
  20.    public $typjednostka;
  21.  
  22.    public function __construct($arData) {
  23.  
  24.        $arData2=DataManager::getData($arData['idjednostka'],'jednostka');
  25.        $arData=array_merge($arData,$arData2);
  26.        parent::__construct($arData);
  27.        $this->propertyTable['nazwa']='name';
  28.        $this->propertyTable['idjednostka']='idjednostka';
  29.        $this->propertyTable['nip']='nip';
  30.        $this->telephones= new Collection();
  31.        $this->telephones->setLoadCallback('_loadTelephones',$this);
  32.        $this->emails= new Collection();
  33.        $this->emails->setLoadCallback('_loadEmails',$this);
  34.        $this->adresses= new Collection();
  35.        $this->adresses->setLoadCallback('_loadAdresses',$this);
  36.        
  37.    }
  38.    public function _loadTelephones(Collection $col) {
  39.        $this->telephones=DataManager::getColectionObjectsForEntity($this->idjednostka, $col, 'telefon');
  40.    } // end of member function
  41.    public function _loadEmails(Collection $col) {
  42.        $this->emails=DataManager::getColectionObjectsForEntity($this->idjednostka, $col, 'email');
  43.    } // end of member function
  44.    public function _loadAdresses(Collection $col) {
  45.        $this->adresses=DataManager::getColectionObjectsForEntity($this->idjednostka, $col, 'adres');
  46.    } // end of member function
  47.    public function addItem($typ){
  48.        $this->typjednostka=$typ;
  49.    }
  50.  
  51. }
  52. ?>


  1. <?php
  2. require_once 'class.Jednostka.php';
  3. require_once 'class.TypOsoby.php';
  4. /**
  5.  * Description of osoba
  6.  *
  7.  * @author daniel
  8.  */
  9. abstract class Osoba extends Jednostka{
  10.    public function __construct($arData) {
  11.        $arData2=DataManager::getData($arData['idosoba'],'osoba');
  12.        $arData=array_merge($arData,$arData2);
  13.        parent::__construct($arData);
  14.        $this->propertyTable['pesel']='pesel';
  15.        $this->propertyTable['nrdowodu']='nrdowodu';
  16.        $this->propertyTable['idosoba']='idosoba';
  17.        $this->propertyTable['idtyposoba']='idtyposoba';
  18.  
  19.    }
  20. }
  21. ?>


  1. <?php
  2. /*
  3.  * To change this template, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. require_once 'class.Osoba.php';
  7. /**
  8.  * Description of classPilot
  9.  *
  10.  * @author daniel
  11.  */
  12. class Pilot extends Osoba{
  13.    public function __construct($id) {
  14.            $arData=DataManager::getData($id,'pilot');
  15.            parent::__construct($arData);
  16.            $this->propertyTable['idpilot']='idpilot';
  17.    }
  18.    public function  __toString() {
  19.        return $this->nazwa;
  20.    }
  21.  
  22. }
  23. ?>


Chciałbym teraz stworzyć nowego pilota (wraz ze wszystkimi danymi wypełniającymi m.in. kolekcje takie jak adresy, telefony itp) oraz dodać to do bazy danych.
Nie wiem jak najlepiej się do tego zabrać... ;|
Proszę o pomoc i wszelkie sugestie.


--------------------
...albo jesteś zerem albo jedynką ;)
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 22.08.2025 - 09:35