Skip to content

Commit b7f5b10

Browse files
committed
Inverno
1 parent f4ef48c commit b7f5b10

File tree

4 files changed

+122
-7
lines changed

4 files changed

+122
-7
lines changed

Config/Database.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* @copyright 2016 Bill Rocha <http://google.com/+BillRocha>
1010
* @license <https://opensource.org/licenses/MIT> MIT
1111
* @version GIT: 0.0.1
12-
* @link http://paulorocha.tk/devbr
12+
* @link http://dbrasil.tk/devbr
1313
*/
1414

1515
namespace Config\Devbr;
@@ -21,7 +21,7 @@
2121
* @package Config
2222
* @author Bill Rocha <[email protected]>
2323
* @license <https://opensource.org/licenses/MIT> MIT
24-
* @link http://paulorocha.tk/devbr
24+
* @link http://dbrasil.tk/devbr
2525
*/
2626
class Database
2727
{

Database.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* @copyright 2016 Bill Rocha <http://google.com/+BillRocha>
1010
* @license <https://opensource.org/licenses/MIT> MIT
1111
* @version GIT: 0.0.1
12-
* @link http://paulorocha.tk/devbr
12+
* @link http://dbrasil.tk/devbr
1313
*/
1414

1515
namespace Devbr;
@@ -23,7 +23,7 @@
2323
* @package Data
2424
* @author Bill Rocha <[email protected]>
2525
* @license <https://opensource.org/licenses/MIT> MIT
26-
* @link http://paulorocha.tk/devbr
26+
* @link http://dbrasil.tk/devbr
2727
*/
2828
class Database
2929
{
@@ -167,7 +167,7 @@ function getSql()
167167
* @package Data
168168
* @author Bill Rocha <[email protected]>
169169
* @license <https://opensource.org/licenses/MIT> MIT
170-
* @link http://paulorocha.tk/devbr
170+
* @link http://dbrasil.tk/devbr
171171
*/
172172
class Row
173173
{

Model.php

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<?php
2+
/**
3+
* Resource\Model
4+
* PHP version 7
5+
*
6+
* @category Model
7+
* @package Resource
8+
* @author Bill Rocha <[email protected]>
9+
* @copyright 2016 Bill Rocha <http://google.com/+BillRocha>
10+
* @license <https://opensource.org/licenses/MIT> MIT
11+
* @version GIT: 0.0.1
12+
* @link http://dbrasil.tk/devbr
13+
*/
14+
15+
namespace Devbr;
16+
17+
use Devbr\Database;
18+
use Config\Devbr\Database as DbConf;
19+
20+
/**
21+
* Model Class
22+
*
23+
* @category Model
24+
* @package Resource
25+
* @author Bill Rocha <[email protected]>
26+
* @license <https://opensource.org/licenses/MIT> MIT
27+
* @link http://dbrasil.tk/devbr
28+
*/
29+
class Model
30+
{
31+
public $db = null;
32+
public $table = null;
33+
public $error = false;
34+
35+
function __construct()
36+
{
37+
$this->db = new Database(DbConf::get());
38+
}
39+
40+
function getError()
41+
{
42+
return $this->error;
43+
}
44+
45+
function setError($error = true)
46+
{
47+
return $this->error = $error;
48+
}
49+
50+
function setTable($table)
51+
{
52+
$this->table = $table;
53+
}
54+
55+
56+
//Lista todos || paginado
57+
final public function doIndex($start = 0, $len = 30, $search = null)
58+
{
59+
//SEarch
60+
if ($search !== null && is_array($search)) {
61+
$tmp = ' WHERE ';
62+
$and = '';
63+
foreach ($search as $k => $v) {
64+
$tmp .= $and.$k.' LIKE "%'.$v.'%" ';
65+
$and = ' AND ';
66+
}
67+
$search = $tmp;
68+
} else {
69+
$search = '';
70+
}
71+
72+
//Execute
73+
$this->db->query('SELECT * FROM '.$this->table.$search.' LIMIT '.(0+$start).', '.(0+$len));
74+
return $this->db->result();
75+
}
76+
77+
//Lista o selecionado
78+
final public function doShow($id)
79+
{
80+
$this->db->query('SELECT * FROM '.$this->table.' WHERE id = :id', [':id'=>$id]);
81+
$result = $this->db->result();
82+
return $result ? $result : false;
83+
}
84+
85+
//Insert/Update
86+
final public function doSave($values)
87+
{
88+
if (isset($values['id'])) {
89+
$action = 'UPDATE ';
90+
$where = ' WHERE id = :id';
91+
} else {
92+
$action = 'INSERT INTO ';
93+
$where = '';
94+
}
95+
96+
$cols = '';
97+
$vals = [];
98+
foreach ($values as $k => $v) {
99+
if ($k !== 'id') {
100+
$cols .= $k.' = :'.$k.',';
101+
}
102+
$vals[':'.$k] = $v;
103+
}
104+
105+
$cols = substr($cols, 0, -1); //tirando a ultima vírgula
106+
107+
return $this->db->query($action.$this->table.' SET '.$cols.$where, $vals);
108+
}
109+
110+
//Deletar
111+
final public function doDelete($id)
112+
{
113+
return $this->db->query('DELETE FROM '.$this->table.' WHERE id = :id', [':id'=>$id]);
114+
}
115+
}

User.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* @copyright 2016 Bill Rocha <http://google.com/+BillRocha>
1010
* @license <https://opensource.org/licenses/MIT> MIT
1111
* @version GIT: 0.0.1
12-
* @link http://paulorocha.tk/devbr
12+
* @link http://dbrasil.tk/devbr
1313
*/
1414

1515
namespace Devbr;
@@ -23,7 +23,7 @@
2323
* @package Util
2424
* @author Bill Rocha <[email protected]>
2525
* @license <https://opensource.org/licenses/MIT> MIT
26-
* @link http://paulorocha.tk/devbr
26+
* @link http://dbrasil.tk/devbr
2727
*/
2828
class User
2929
{

0 commit comments

Comments
 (0)