1 <?php
2
3 namespace PLus\Orders\Repositories;
4
5 use Nette;
6
7 abstract class Repository extends \Nette\Object {
8
9
10 protected $connection;
11
12
13 protected $table;
14
15 public function __construct(Nette\Database\Table\Selection $table, Nette\Database\Context $db) {
16 $this->table = $table;
17 $this->connection = $db;
18 }
19
20
21 22 23 24 25
26 protected function getTable() {
27 return clone $this->table;
28 }
29
30 31 32 33 34
35 public function findBy(array $by) {
36 return $this->getTable()->where($by);
37 }
38
39 40 41 42 43
44
45 public function findById($id) {
46 return $this->getTable()->get($id);
47 }
48
49 50 51 52 53
54
55 public function deleteById($id) {
56 return $this->getTable()->get($id)->delete();
57 }
58
59 60 61 62 63
64
65 public function updateById($id, $data) {
66 return $this->getTable()->wherePrimary($id)->update($data);
67 }
68
69 70 71 72 73
74
75 public function insertData($data) {
76 return $this->getTable()->insert($data);
77 }
78
79 }
80