- 1 sprawdzanie czy user jest zalogowanych (autoryzacja)
- 2 głosowanie , ocena artykułu , dziedziczy po 1szej
Mam pytanie :
Czy napisałem to poprawnie , bo zaczyna przygodę z OOP pisząc swój mały cmsik .
Czekam na sugestie do plików, ukazanie błędów czy innych możliwości łatwiejszego zapisu.
<?php ///////////klasa usera auth class//////////// class User { public $logged_in = null; public $user_level = null; function __construct($db) { $this->_db = $db; $this->startSession(); } public function loginCheck() { return true; } else { return false; } } public function levelCheck() { $q = $this->_db->query("Select * from mpa_users where id='$id'"); if($this->_db->num_rows($q) == 1) { $row = $this->_db->fetch_array($q); if($row['admin'] == 1) { return 7; { return 2; { $this->_db->query("Update mpa_users set premium='0' where id='$id'"); return 1; }elseif($row['admin'] == 0 && $row['premium'] == 0) { return 1; } } else { } } private function startSession() { $this->logged_in = $this->loginCheck(); if($this->logged_in) { $this->user_level = $this->levelCheck(); } else { $this->user_level = 0; } } } ?> //////////////Rate Class <?php class Rating extends User{ function __construct($db) { $this->_db = $db; $this->AllowRate = $this->loginCheck(); } private function checkRate($smth,$type) { if($this->AllowRate) { $check = $this->_db->num_rows($this->_db->query("Select * from mpa_rate where userid='".$this->user_id."' and fileid='".$this->movie."' and type='".$this->type."'")); if($check == 0) { return true; } else { return false; } } else { return false; } } private function checkData($smth,$type) { { $error = 0; if($this->value > 5) { $error++; } switch($this->type) { case 1: if($this->_db->num_rows($this->_db->query("Select * from mpa_movies where id='".$this->movie."'")) == 0) { $error++; } break; case 2: break; default : $error++; break; } if($error == 0) { return true; } else { return false; } } else { return false; } } public function doRate($smth,$type) { { if($this->AllowRate && $this->CheckRate($smth,$type) && $this->checkData($smth,$type)) { $check = $this->_db->query("INSERT INTO `mpa_rate` (`id`, `userid`, `fileid`, `type`, `value`) VALUES (NULL, '".$this->user_id."', '".$this->movie."', '$type', '".$this->value."');"); if($check) { return "good"; } else { return "bad"; } } else { ///Sypie ze brak dostepu return "bad"; } } else { return "bad22"; } } } ?>
Update plików