-
Notifications
You must be signed in to change notification settings - Fork 0
/
Model.php
70 lines (58 loc) · 1.94 KB
/
Model.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
66
67
68
69
70
<?php
class Model
{
private $dbh;
public function __construct()
{
require 'db-config.php';
$this->dbh = new PDO($host_plus_dbname, $dbuser, $pass);
}
private function runsql($sql, $params = null)
{
$stmt = $this->dbh->prepare($sql);
$stmt->execute($params);
$result = $stmt->fetchAll();
$stmt = null;
return $result;
}
public function addTask($name, $email, $text, $status)
{
$this->runsql("INSERT INTO `tasks` (`user`, `email`, `text`, `status`) VALUES (?, ?, ?, ?)", array( $name, $email, $text, $status ));
}
public function UpdateTask($name, $email, $text, $status, $id)
{
$this->runsql("UPDATE `tasks` SET `user`=?, `email`=?, `text`=?, `status`=? WHERE `id`=? ", array( $name, $email, $text, $status, $id ));
}
public function setAdminEdited($id)
{
$this->runsql("UPDATE `tasks` SET `edited`='1' WHERE `id`=? ", array($id));
}
public function getItemById($id)
{
return $this->runsql("SELECT * FROM `tasks` WHERE `id`=? ", array($id));
}
public function getItems()
{
return $this->runsql("SELECT COUNT(*) as items FROM tasks");
}
public function getTasks()
{
$page = "1";
//calculating sql pagination limits
$fistindex = ($page - 1) * 3;
$per_page = 3;
return $this->runsql("SELECT * FROM `tasks` ORDER BY `id` ASC LIMIT " . $fistindex . "," . $per_page );
}
public function getIndexItems($sortby, $sortorder, $page)
{
//calculating sql pagination limits
$fistindex = ($page - 1) * 3;
$per_page = 3;
return $this->runsql("SELECT * FROM `tasks` ORDER BY ? ? LIMIT " . $fistindex . "," . $per_page , array( $sortby, $sortorder ));
}
public function getAdminByHash($hash_admin)
{
return $this->runsql("SELECT hash FROM admin WHERE hash='" . $hash_admin . "'");
}
}
?>