Tak keď pišem takto triedu tak to asi robíme zle?
<?php
include_once __DIR__."/../db/MySQL.php";
include_once __DIR__."/../data/Data.php";
include_once __DIR__."/../data/ValiData.php";
include_once __DIR__."/../Form/Admin.php";
class Text{
public function __construct(){
session_start();
$this->MySQL = new MySQL;
$this->Data = new Data;
$this->ValiData = new ValiData;
$this->Form = new Form;
$this->lang = $this->Data->html($_session['lang']);
$this->id = $this->Data->html($_POST['id']);
$this->Name = $this->Data->html($_POST['Name']);
$this->Text = $this->Data->html($_POST['Text']);
$this->Seo = $this->Data->html($_POST['Seo']);
$this->Url = $this->Data->html($_POST['Url']);
$this->Status = $this->Data->html($_POST['Status']);
}
private function insert(){
list($validate, $error) = $this->ValiData->strlen_min($this->name, 'Názov', '5')
->strlen_min($this->text, 'Text', '5')
->strlen_min($this->seo[0], 'Title', '5')
->strlen_min($this->seo[2], 'Description', '5')
->strlen_min($this->url, 'Url názov', '5')
->status($this->status)
->lang($this->lang)
->result();
$value = array("Name" => $this->Name,
"Text" => $this->Text,
"Seo" => $this->Seo,
"Url" => $this->Url,
"Status" => $this->Status);
if($validate == 1){
$Db = $this->MySQL->table('subpage')->insert($value);
}
return array($Db, $error, $value);
}
private function update(){
list($validate, $error) = $this->ValiData->strlen_min($this->name, 'Názov', '5')
->strlen_min($this->text, 'Text', '5')
->strlen_min($this->seo[0], 'Title', '5')
->strlen_min($this->seo[2], 'Description', '5')
->status($this->status)
->lang($this->lang)
->idexists($this->id, 'subpage')
->result();
if($validate == 1){
$Db = $this->MySQL->table('subpage')->where('id=:id', $where = array("id" => $this->id))
->update($value = array("Name" => $this->name,
"Text" => $this->text,
"Seo" => $this->seo,
"Status"=> $this->status
));
}
$value = array_merge($value,$where);
return array($Db, $error, $value);
}
private function delete(){
list($validate, $error) = $this->ValiData->idexists($this->id, 'subpage')->result();
if($validate == 1){
$Db = $this->MySQL->table('subpage')->where('id=:id',$where = array("id" => $this->id))->delete();
}
return array($Db, $error);
}
private function result($id,$delete){
$pocet = 1;
$Db = $this->MySQL->table('subpage')->select()->resultset();
$result = '<table>
<th>
<td>#</td>
<td>Názov</td>
<td></td>
</th>';
foreach($Db as $value){
$result .= '<tr>
<td>'.$pocet++.'</td>
<td>'.$value['Name'].'</td>
<td>'.$edit.$delete.'</td>
<tr>';
}
$result .= '.</table>.';
return $result;
}
public function list($id, $action){
if($action == "result"){
$result = Text::result($id,null);
}
if($action == "insert"){
if($_SERVER['REQUEST_METHOD'] == Post){
$insert = Text::insert();
$result = $this->Form->text($insert);
}else{
$result = $this->Form->text(null);
}
}
if($action == "update"){
if($_SERVER['REQUEST_METHOD'] == Post){
$update = Text::update();
$result = $this->Form->text($update);
}else{
$update = $this->MySQL->table('admin')->where('id=:id',$where = array("id" => $id))->select()->single();
$result = $this->Form->text($update = array("Db" => null,
"error" => null,
"value" => array("Name" => $update['Name'],
"Text" => $update['Text'],
"Seo" => $update['Seo'],
"Status" => $update['Status'])
));
}
}
if($action == "delete"){
$delete = Text::delete();
$result .= Text::result($id,$delete);
}
if($action == "result"){
$result = Text::result($id,null);
}
return $result;
}
}
?>
napr. Text::result som volal funkciu v tej istej triedy...