📁 PHP Dosya Yöneticisi
/
/
home
/
demodesigncom
/
otogaleriscripti.demodesign.com.tr
/
includes
/
models
📝
Category.php
← Geri Dön
<? class Categories{ public function getAll() { global $dbh; $sth = $dbh->prepare("select * from categories "); $sth->execute( ); $rows = $sth->fetchAll (PDO::FETCH_OBJ); $r=[]; foreach ($rows as $row) { /** @var Category $row */ $r[] = new Category($row->id,$row->name,$row->parent); } return $r; } public function getSubs($parent) { global $dbh; if($parent==null){$parent=0;} $sth = $dbh->prepare("select * from categories where parent=:parent"); $sth->execute( array("parent" => $parent ) ); $rows = $sth->fetchAll (PDO::FETCH_OBJ); $r=[]; foreach ($rows as $row) { /** @var Category $row */ $r[] = new Category($row->id,$row->name,$row->parent); } return $r; } public function getAllSubs($cat) { global $dbh; $sth = $dbh->prepare("select * from categories where parent=:parent"); $sth->execute( array("parent" => $cat ) ); $rows = $sth->fetchAll (PDO::FETCH_OBJ); $r=[]; foreach ($rows as $row) { /** @var Category $row */ $ct= new Category($row->id,$row->name,$row->parent); $r[] =$ct; $r= array_merge($r,$this->getAllSubs($row->id)); } return $r; } public function getTree($cat=0) { global $dbh; $sth = $dbh->prepare("select * from categories where parent=:parent"); $sth->execute( array("parent" => $cat ) ); $rows = $sth->fetchAll (PDO::FETCH_OBJ); $r=[]; foreach ($rows as $row) { /** @var Category $row */ $ct= new Category($row->id,$row->name,$row->parent); $ct->subs=$this->getTree($row->id); $r[] =$ct; } return $r; } public function getRootCategories() { global $dbh; $sth = $dbh->prepare("select * from categories where parent=0 "); $sth->execute( ); $rows = $sth->fetchAll (PDO::FETCH_OBJ); $r=[]; foreach ($rows as $row) { /** @var Category $row */ $r[] = new Category($row->id,$row->name,$row->parent); } return $r; } } class Category{ public $id , $parent ,$name ; public function __construct($id="",$name="",$parent="") { $this->set($id,$name,$parent); } public function set($id="",$name="",$parent="") { $this->id = $id; $this->name = $name; $this->parent = $parent; } public function get($id) { global $dbh; $sth = $dbh->prepare("select * from categories where id=:id"); $sth->execute(array("id"=>$id)); $row = $sth->fetch(PDO::FETCH_ASSOC); if(isset($row["id"])){ $this->set ( $row["id"], $row["name"], $row["parent"]); $this->id = $row["id"]; return $this; }else{ return false; } } public function getParent(){ return $this->get($this->parent); } public function getByName($name) { global $dbh; $sth = $dbh->prepare("select * from categories where name=:name"); $sth->execute(array("name"=>$name)); $row = $sth->fetch(PDO::FETCH_ASSOC); if(isset($row["id"])){ $this->set ( $row["id"], $row["name"], $row["parent"]); $this->id = $row["id"]; return $this; }else{ return false; } } public function insert(){ /** @var PDO $dbh */ global $dbh; $sth = $dbh->prepare("insert into categories set name=:name ,parent=:parent "); $sth->execute(array( "name"=>$this->name, "parent"=>$this->parent, )); $error=$sth->errorInfo(); if(!isset($error[1])){ $this->id = $dbh->lastInsertId(); return $this; }else{ print_r($error); return false; } } public function update(){ /** @var PDO $dbh */ global $dbh; $sth = $dbh->prepare("update categories set name=:name ,parent=:parent where id=:id"); $sth->execute(array( "id"=>$this->id, "name"=>$this->name, "parent"=>$this->parent, )); $error=$sth->errorInfo(); if(!isset($error[1])){ return $this; }else{ print_r($error); return false; } } public function delete(){ /** @var PDO $dbh */ global $dbh; $sth = $dbh->prepare("delete from categories where id=:id "); $sth->execute(array( "id"=>$this->id )); $error=$sth->errorInfo(); if(!isset($error[1])){ return true; }else{ print_r($error); return false; } } }
💾 Kaydet
İptal
📝 Yeniden Adlandır
İptal
Kaydet
🔐 Dosya İzinleri (chmod)
İzin Değeri:
Hızlı Seçim:
777
755
644
600
777
= Herkes okur/yazar/çalıştırır
755
= Sahip tam, diğerleri okur/çalıştırır
644
= Sahip okur/yazar, diğerleri okur
600
= Sadece sahip okur/yazar
İptal
Uygula