Jak połączyć klasę SQL z klasą Eps tak by metody z klasy SQL wykonywały zapytania z klasy eps czyli
update_point() i delete_point()
$user_point = 2;
class sql { //dopisujemy parę funkcji do klasy Eps
public function update(Eps $update) {
}
public function remove(Eps $remove) {
}
}
abstract class Eps_Cat_Point {
protected
$eps_cat_point = array('A' => 3, 'C' => 5, 'D' => 2
);
// Dane beda pochodzic z bazy
// Litera to identyfikator kategorii za co dostaje sie pkt np A za artykul 3 pkt.
}
class Eps extends Eps_Cat_Point {
public $user_id;
public $cat_point;
public $query;
public $method_name;
public function __construct($user_id, $cat_point, $method_name) {
$this->user_id = $user_id;
$this->cat_point = $cat_point;
if(method_exists(__CLASS__, $method_name)){
$this->method_name = $method_name;
///$sql = new sql($this); jak tutaj dodac kod z klasy sql
call_user_func
(array(__CLASS__
, $this->method_name));
}
} else {
throw new Exception("Niepoprawna wartosc podanych parametrow");
}
}
public function check_point(){
if($user_point < $this->eps_cat_point[$this->cat_point]){
return true;
} else {
return false;
}
}
public function update_point(){
$this->query = "UPDATE tabela SET user_point=user_point+'".$this->eps_cat_point[$this->cat_point]."' WHERE user_id='".$this->user_id."'";
return $this->query;
}
public function delete_point(){
if($this->check_point()){
$this->query = "UPDATE tabela SET user_point=0 WHERE user_id='".$this->user_id."'";
return $this->query;
} else {
$this->query = "UPDATE tabela SET user_point=user_point-'".$this->eps_cat_point[$this->cat_point]."' WHERE user_id='".$this->user_id."'";
return $this->query;
}
}
}
$eps = new Eps(12, 'A', 'update_point');
.