Dopiero zaczynam z obiektowym i nie wiem jak ugryźć problem dodawania nowych obiektów do bazy danych.
Moje klasy wyglądają tak:
<?php require_once 'interface.Validate.php'; /** * class PropertyObject * */ abstract class PropertyObject implements Validate { /** Aggregations: */ /** Compositions: */ /*** Attributes: ***/ /** * * @access protected */ protected $data; public function __construct($arData){ $this->data=$arData; } function __get($propertyName){ throw new Exception("Błędna własność \"$propertyName\"! "); if(method_exists($this, 'get'.$propertyName)){ } else { return $this->data[$this->propertyTable[$propertyName]]; } } function __set($propertyName, $value){ throw new Exception("Błędna własność \"$propertyName\" "); if(method_exists($this, 'set'.$propertyName)){ return call_user_func( $value ); } else { //jeżeli wartość własności uległa zmianie i nie ma jej //jeszcze w tabeli chengedProperties, zostanie do niej dołączona if($this->propertyTable[$propertyName]!=$value && $this->changedProperties[]=$propertyName; } $this->data[$this->propertyTable[$propertyName]] = $value; } } /** * * * @return * @access public */ function validate( ) { } // end of member function validate function errormsg(){ foreach ($this->errors as $value) { } } } // end of PropertyObject ?>
<?php require_once 'class.PropertyObject.php'; require_once 'class.Collection.php'; require_once 'class.Telefon.php'; require_once 'class.Adres.php'; require_once 'class.Email.php'; require_once 'class.Organizator.php'; require_once 'class.Firma.php'; require_once 'class.TypOsoby.php'; /** * Description of classJednostka * * @author daniel */ abstract class Jednostka extends PropertyObject { public $typjednostka; public function __construct($arData) { $arData2=DataManager::getData($arData['idjednostka'],'jednostka'); parent::__construct($arData); $this->propertyTable['nazwa']='name'; $this->propertyTable['idjednostka']='idjednostka'; $this->propertyTable['nip']='nip'; $this->telephones= new Collection(); $this->telephones->setLoadCallback('_loadTelephones',$this); $this->emails= new Collection(); $this->emails->setLoadCallback('_loadEmails',$this); $this->adresses= new Collection(); $this->adresses->setLoadCallback('_loadAdresses',$this); } public function _loadTelephones(Collection $col) { $this->telephones=DataManager::getColectionObjectsForEntity($this->idjednostka, $col, 'telefon'); } // end of member function public function _loadEmails(Collection $col) { $this->emails=DataManager::getColectionObjectsForEntity($this->idjednostka, $col, 'email'); } // end of member function public function _loadAdresses(Collection $col) { $this->adresses=DataManager::getColectionObjectsForEntity($this->idjednostka, $col, 'adres'); } // end of member function public function addItem($typ){ $this->typjednostka=$typ; } } ?>
<?php require_once 'class.Jednostka.php'; require_once 'class.TypOsoby.php'; /** * Description of osoba * * @author daniel */ abstract class Osoba extends Jednostka{ public function __construct($arData) { $arData2=DataManager::getData($arData['idosoba'],'osoba'); parent::__construct($arData); $this->propertyTable['pesel']='pesel'; $this->propertyTable['nrdowodu']='nrdowodu'; $this->propertyTable['idosoba']='idosoba'; $this->propertyTable['idtyposoba']='idtyposoba'; } } ?>
<?php /* * To change this template, choose Tools | Templates * and open the template in the editor. */ require_once 'class.Osoba.php'; /** * Description of classPilot * * @author daniel */ class Pilot extends Osoba{ public function __construct($id) { $arData=DataManager::getData($id,'pilot'); parent::__construct($arData); $this->propertyTable['idpilot']='idpilot'; } public function __toString() { return $this->nazwa; } } ?>
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.