dzisiaj pisząc klasę wyszła mi fajna funkcja wstawiam tylko kawałek który mi się spodobał nie sądziłem że to zadziała spróbowałem i zdziwienie :) poniżej kod funkcja upbuild :)
co polecacie zmienić w ogólnej strukturze klasy(jeszcze nie dokończona) ale na wykończeniu :)
wydaje mi się że poprawiłem swój styl pisania klas ale pewien nie jestem :)
class builds
{
private $db;
private $user;
private $id;
var $build;
function __construct(\PDO $db, $user, $id, $build)
{
$this->db = $db;
$this->id = $id;
$this->build = $build;
$this->user = new user_info($this->db = $db, $this->id = $id);
}
function getLvl()
{
$lvl = $this->user->builds->{$this->build} + 1;
return $lvl;
}
function GetInfo()
{
$query = $this->db->prepare("**** ");
$query->bindParam(1, $this->build, PDO::PARAM_STR);
$query->bindParam(2, $this->getLvl(), PDO::PARAM_INT);
$query->execute();
$object = $query->fetch(PDO::FETCH_OBJ);
return $object;
}
function GetCost()
{
$object = $this->GetInfo();
$info['wood'] = $object->cost_wood;
$info['stone'] = $object->cost_stone;
$info['iron'] = $object->cost_iron;
$info['gold'] = $object->cost_gold;
$info['time'] = $object->cost_time;
return $info;
}
function GetReqementes()
{
$object = $this->GetInfo();
$info = unserialize($object->cost_builds);
return $info;
}
function ChekRequementes()
{
$array = $this->GetReqementes();
if (!empty($array)) {
foreach ($array AS $val) {
if ($this->user->builds->{$val['build']} >= $val['lvl']) {
return true;
} else {
return false;
}
}
} else {
return false;
}
return false;
}
function ChekResources($dataUser, $dataSys)
{
if ($dataUser >= $dataSys) {
$calc = $dataUser - $dataSys;
return $calc;
} else {
return false;
}
}
function upbuild()
{
if ($this->ChekRequementes()) {
$Cost = $this->GetCost();
$lvl = $this->getLvl();
$a = array();
$table = array(1 => 'wood',
2 => 'stone',
3 => 'iron',
4 => 'gold',
5 => 'time');
foreach ($table AS $res) {
if ($res != 'time') {
${$res} = $this->ChekResources($this->user->resources->{$res}, $Cost[$res]);
$a[$res] = ${$res};
}
}
return $a;
} else {
return false;
}
}
}