1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Nip\Records\AbstractModels; |
4
|
|
|
|
5
|
|
|
use Nip\HelperBroker; |
6
|
|
|
use \Exception; |
7
|
|
|
use Nip\Records\Traits\ActiveRecord\ActiveRecordTrait; |
8
|
|
|
use Nip\Records\Traits\HasAttributes\HasAttributesRecordTrait; |
9
|
|
|
use Nip\Records\Traits\HasHelpers\HasHelpersRecordTrait; |
10
|
|
|
use Nip\Records\Traits\HasManager\HasManagerRecordTrait; |
11
|
|
|
use Nip\Records\Traits\Serializable\SerializableRecord; |
12
|
|
|
use Nip\Utility\Traits\NameWorksTrait; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class Row |
16
|
|
|
* @package Nip\Records\_Abstract |
17
|
|
|
* |
18
|
|
|
* @method \Nip_Helper_Url URL() |
19
|
|
|
*/ |
20
|
|
|
abstract class Record implements \Serializable |
21
|
|
|
{ |
22
|
|
|
use NameWorksTrait; |
23
|
|
|
use ActiveRecordTrait; |
24
|
|
|
use HasHelpersRecordTrait; |
25
|
|
|
use HasManagerRecordTrait; |
26
|
|
|
use HasAttributesRecordTrait; |
27
|
|
|
use SerializableRecord; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Overloads Ucfirst() helper |
31
|
|
|
* |
32
|
|
|
* @param string $name |
33
|
|
|
* @param array $arguments |
34
|
|
|
* @return \Nip\Helpers\AbstractHelper|null |
35
|
|
|
*/ |
36
|
|
|
public function __call($name, $arguments) |
37
|
|
|
{ |
38
|
|
|
if ($this->isHelperCall($name)) { |
39
|
|
|
return $this->getHelper($name); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
trigger_error("Call to undefined method $name", E_USER_ERROR); |
43
|
|
|
return null; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @return string |
48
|
|
|
*/ |
49
|
|
|
public function toJSON() |
50
|
|
|
{ |
51
|
|
|
return json_encode($this->toArray()); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return mixed |
56
|
|
|
*/ |
57
|
|
|
public function toArray() |
58
|
|
|
{ |
59
|
|
|
$vars = get_object_vars($this); |
60
|
|
|
return $vars['_data']; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param $fields |
65
|
|
|
* @param string $glue |
66
|
|
|
* @return string |
67
|
|
|
*/ |
68
|
1 |
|
public function implodeFields($fields, $glue = '-') |
69
|
|
|
{ |
70
|
1 |
|
$return = []; |
71
|
1 |
|
foreach ($fields as $field) { |
72
|
1 |
|
$return[] = $this->{$field}; |
73
|
|
|
} |
74
|
1 |
|
return implode($glue, $return); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return mixed |
79
|
|
|
*/ |
80
|
|
|
public function toApiArray() |
81
|
|
|
{ |
82
|
|
|
$data = $this->toArray(); |
83
|
|
|
return $data; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @return Record |
88
|
|
|
*/ |
89
|
|
|
public function getClone() |
90
|
|
|
{ |
91
|
|
|
$clone = $this->getManager()->getNew(); |
92
|
|
|
$clone->updateDataFromRecord($this); |
93
|
|
|
|
94
|
|
|
return $clone; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @param self $record |
99
|
|
|
*/ |
100
|
|
|
public function updateDataFromRecord($record) |
101
|
|
|
{ |
102
|
|
|
$data = $record->toArray(); |
103
|
|
|
$cleanup = [$this->getManager()->getPrimaryKey(), 'created']; |
104
|
|
|
foreach ($cleanup as $key) { |
105
|
|
|
unset($data[$key]); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
$this->writeData($data); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @return \Nip\Request |
113
|
|
|
*/ |
114
|
|
|
protected function getRequest() |
115
|
|
|
{ |
116
|
|
|
return $this->getManager()->getRequest(); |
|
|
|
|
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.