1: <?php
2:
3: namespace PHPixie\ORM\Models\Type\Database\Implementation;
4:
5: abstract class Entity extends \PHPixie\ORM\Models\Model\Implementation\Entity
6: implements \PHPixie\ORM\Models\Type\Database\Entity
7: {
8: protected $repository;
9: protected $isDeleted = false;
10: protected $isNew;
11:
12: public function __construct($entityPropertyMap, $repository, $data, $isNew = false)
13: {
14: $this->repository = $repository;
15: $this->isNew = $isNew;
16:
17: parent::__construct($entityPropertyMap, $repository->config(), $data);
18: }
19:
20: public function isNew()
21: {
22: return $this->isNew;
23: }
24:
25: public function setIsNew($isNew)
26: {
27: $this->isNew = $isNew;
28: return $this;
29: }
30:
31: public function isDeleted()
32: {
33: return $this->isDeleted;
34: }
35:
36: public function setIsDeleted($isDeleted)
37: {
38: $this->isDeleted = $isDeleted;
39: return $this;
40: }
41:
42: public function id()
43: {
44: $this->assertNotDeleted();
45: return $this->getField($this->config->idField);
46: }
47:
48: public function setId($id) {
49: $this->assertNotDeleted();
50: $this->setField($this->config->idField, $id);
51: return $this;
52: }
53:
54: public function save()
55: {
56: $this->repository->save($this);
57: return $this;
58: }
59:
60: public function delete()
61: {
62: $this->repository->delete($this);
63: return $this;
64: }
65:
66: public function getRelationshipProperty($name, $createMissing = true)
67: {
68: $this->assertNotDeleted();
69: return parent::getRelationshipProperty($name, $createMissing);
70: }
71:
72: protected function assertNotDeleted()
73: {
74: if ($this->isDeleted())
75: throw new \PHPixie\ORM\Exception\Entity("This entity has been deleted.");
76: }
77:
78: }