Nu stiu daca am facut totul bine (in sensul de profesionist), dar functioneaza, am testat. N-am putut modifica chiar in toata baza de date sau aplicatie, mi-ar fi luat prea mult timp, dar pe viitor voi tine cont de sugestiile tale.
Noua varianta de clasa Ore:
Cod: Selectaţi tot
class Ore extends AbstractTableMapper {
protected $vclasa = 'Ore'; // numele clasei (il folosesc sa verific obiectul cu care lucrez la un moment dat)
protected $vtabela = 'ore'; // numele tabelei (folosit la fisierul modelinsert.php, modelupdtae.php,
//modelselect.php - am un singur fisier de inserare)
protected $vnumeid = 'ore_id'; //numele cimpului ID din tabela (sa nu-l mai caut ulterior)
protected $v=[];
protected $languages = [];
protected $vtabel = [];
function __construct(){
parent::__construct(); // face conexiunea
$languages = $this->getFromLanguages(); // preluare fostele variabile GLOBAL
$this->v = $this->showColumnsFromTableAdd($languages); // array pentru add/modify
$this->vtabel = $this->showColumnsFromTableHTML($languages); // array pentru tabela html
}
protected function getFromLanguages(){
$dir_lang = isset($_SESSION['language']) ? $_SESSION['language'] : 'ro';
include (dirname(__DIR__).'/language/'.$dir_lang.'/limba.php');
$languages = [];
$languages += array(0=>$lang['ore']['anul']);
$languages += array(1=>$lang['ore']['luna']);
$languages += array(2=>$lang['ore']['oreluc']);
return $languages;
}
protected function showColumnsFromTableAdd($languages){
$sql= 'SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA =\'atis\' AND TABLE_NAME=\'ore\'';
$rows = $this->conn->sqlExec($sql); //preluare lista cimpuri din tabela
$rows = array_slice($rows, 1, -1); //sterg primul si ultimul (ore_id si datamod de care nu am nevoie la add)
$nr_ar = count($rows);
for($i=0; $i<$nr_ar; $i++){ // sterg cimpurile care nu-mi trebuie (nu le folosesc in formular)
foreach($rows[$i] as $k=>$v){
if($v =='aredoc') unset($rows[$i]);
if($v =='userid') unset($rows[$i]);
}
}
$numItems = count($languages);
$i=0;
foreach ($rows as $k=>$v){ // completez array add/modify
if($i<$numItems)
$this->v += [$languages[$i]=>$v[0]];
$i++;
}
return $this->v;
}
protected function showColumnsFromTableHTML($languages){
$sql= 'SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA =\'atis\' AND TABLE_NAME=\'ore\'';
$rows = $this->conn->sqlExec($sql);
$rows = array_slice($rows, 1, -1);
$nr_ar = count($rows);
for($i=0; $i<$nr_ar; $i++){
foreach($rows[$i] as $k=>$v){
if($v =='aredoc') unset($rows[$i]);
if($v =='userid') unset($rows[$i]);
}
}
$numItems = count($languages);
$i=0;
foreach ($rows as $k=>$v){
if($i<$numItems)
$this->vtabel += [$languages[$i]=>$v[0]];
$i++;
}
return $this->vtabel;
}
protected function getMappedTableName(){
return $this->vtabela;
}
protected function getPrimaryKeyColumnName(){
return $this->vnumeid;
}
public function getClasa(){
return $this->vclasa;
}
public function getTabela(){
return $this->vtabela;
}
public function getNumeid(){
return $this->vnumeid;
}
public function getVariabile(){
return $this->v;
}
public function getTabel(){
return $this->vtabel;
}
}