/
WidgetData.php
65 lines (51 loc) · 1.75 KB
/
WidgetData.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
class WidgetData {
public static $tablename = "widget";
public function WidgetData(){
$this->title = "";
$this->content = "";
$this->image = "";
$this->user_id = "";
$this->is_public = "0";
$this->created_at = "NOW()";
}
public function add(){
$sql = "insert into ".self::$tablename." (title,func,params,ord) ";
$sql .= "value (\"$this->title\",\"$this->func\",\"$this->params\",$this->ord)";
Executor::doit($sql);
}
public static function delById($id){
$sql = "delete from ".self::$tablename." where id=$id";
Executor::doit($sql);
}
public function del(){
$sql = "delete from ".self::$tablename." where id=$this->id";
Executor::doit($sql);
}
// partiendo de que ya tenemos creado un objecto WidgetData previamente utilizamos el contexto
public function update(){
$sql = "update ".self::$tablename." set title=\"$this->title\",func=\"$this->func\",params=\"$this->params\",status=\"$this->status\",ord=\"$this->ord\" where id=$this->id";
Executor::doit($sql);
}
public static function getById($id){
$sql = "select * from ".self::$tablename." where id=$id";
$query = Executor::doit($sql);
return Model::one($query[0],new WidgetData());
}
public static function getAll(){
$sql = "select * from ".self::$tablename;
$query = Executor::doit($sql);
return Model::many($query[0],new WidgetData());
}
public static function getPublics(){
$sql = "select * from ".self::$tablename." where status=1 order by ord";
$query = Executor::doit($sql);
return Model::many($query[0],new WidgetData());
}
public static function getLike($q){
$sql = "select * from ".self::$tablename." where title like '%$q%' or content like '%$q%'";
$query = Executor::doit($sql);
return Model::many($query[0],new WidgetData());
}
}
?>