-
Notifications
You must be signed in to change notification settings - Fork 6
/
Model.php
97 lines (81 loc) · 2.35 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
namespace Magomogo\Persisted\Test\Person;
use Magomogo\Persisted\Container\ContainerInterface;
use Magomogo\Persisted\ModelInterface;
use Magomogo\Persisted\Test\Keymarker;
class Model implements ModelInterface
{
/**
* @var Properties
*/
protected $properties;
/**
* @var Keymarker\Model[]
*/
private $tags = array();
/**
* @param ContainerInterface $container
* @param string $id
* @return self
*/
public static function load($container, $id)
{
$p = new Properties();
$p->loadFrom($container, $id);
return new self($p, $p->collections()->tags->asArray());
}
public function save($container)
{
$this->properties->hasCollection(new Keymarker\Collection, 'tags');
foreach ($this->tags as $tag) {
$this->properties->collections()->tags[] = $tag;
}
return $this->properties->putIn($container);
}
//----------------------------------------------------------------------------------------------------------------------
/**
* @param Properties $properties
* @param array $tags array of Keymarker\Model
*/
public function __construct($properties, array $tags = array())
{
$this->properties = $properties;
array_map(array($this, 'tag'), $tags);
}
public function politeTitle()
{
return $this->properties->title . ' ' . $this->properties->firstName . ' ' . $this->properties->lastName;
}
public function lastName()
{
return $this->properties->lastName;
}
public function contactInfo()
{
return 'Phone: ' . $this->properties->phone . "\n" . 'Email: ' . $this->properties->email;
}
public function phoneNumberIsChanged($newNumber)
{
$this->properties->phone = $newNumber;
}
public function paymentInfo()
{
return $this->ableToPay() ?
$this->properties->creditCard->paymentSystem() . ', ' . $this->properties->creditCard->maskedPan() : null;
}
public function ableToPay()
{
return !is_null($this->properties->creditCard);
}
/**
* @param Keymarker\Model $keymarker
*/
public function tag($keymarker)
{
$this->tags[strval($keymarker)] = $keymarker;
}
public function taggedAs()
{
return join(', ', $this->tags);
}
}