-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBaseModel.php
44 lines (33 loc) · 1.1 KB
/
BaseModel.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
<?php
namespace kapitanluffy\PropelModelParserBundle;
use \BaseObject;
abstract class BaseModel extends \BaseObject
{
public function parseObject($collection = array(), $object = null)
{
$object = $object ?: $this;
$data = array();
foreach($collection as $key => $property){
$value = $property->getValue();
$criteria = $property->getCriteria();
$item = $value;
if(method_exists($object, $value)){
$item = $object->$value($criteria);
}
if($item instanceof BaseModel){
$data[$key] = $this->parseObject($property, $item);
}
else if($item instanceof \PropelCollection){
$data[$key] = array();
foreach($item as $o){
$data[$key][] = $this->parseObject($property, $o);
}
}
else {
$data[$key] = $item;
}
}
$_default_data = $object->toArray(\BasePeer::TYPE_FIELDNAME);
return array_merge($_default_data, $data);
}
}