1: <?php
2:
3: namespace PHPixie\ORM\Relationships\Type\ManyToMany\Property;
4:
5: class Entity extends \PHPixie\ORM\Relationships\Relationship\Implementation\Property\Entity
6: implements \PHPixie\ORM\Relationships\Relationship\Property\Entity\Data,
7: \PHPixie\ORM\Relationships\Relationship\Property\Entity\Query
8: {
9:
10: public function query()
11: {
12: return $this->handler->query($this->side, $this->entity);
13: }
14:
15: protected function load()
16: {
17: $this->handler->loadProperty($this->side, $this->entity);
18: }
19:
20: public function add($items)
21: {
22: $config = $this->side->config();
23: list($left, $right) = $this->getSides($items);
24: $plan = $this->handler->linkPlan($config, $left, $right);
25: $plan->execute();
26: $this->handler->linkProperties($config, $left, $right);
27: return $this;
28: }
29:
30: public function remove($items)
31: {
32: $config = $this->side->config();
33: list($left, $right) = $this->getSides($items);
34: $plan = $this->handler->unlinkPlan($config, $left, $right);
35: $plan->execute();
36: $this->handler->unlinkProperties($config, $left, $right);
37: return $this;
38: }
39:
40: public function removeAll()
41: {
42: $plan = $this->handler->unlinkAllPlan($this->side, $this->entity);
43: $plan->execute();
44: $this->handler->unlinkAllProperties($this->side, $this->entity);
45: return $this;
46: }
47:
48: protected function getSides($opposing)
49: {
50: if ($this->side->type() === 'right')
51: return array($this->entity, $opposing);
52:
53: return array($opposing, $this->entity);
54: }
55:
56: public function asData($recursive = false)
57: {
58: $data = array();
59: foreach($this->value() as $entity) {
60: if(!$entity->isDeleted()) {
61: $data[] = $entity->asObject($recursive);
62: }
63: }
64: return $data;
65: }
66:
67: }
68: