forked from pimcore/pimcore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Resource.php
107 lines (91 loc) · 4 KB
/
Resource.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
98
99
100
101
102
103
104
105
106
107
<?php
/**
* Pimcore
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://www.pimcore.org/license
*
* @category Pimcore
* @package Object_Class
* @copyright Copyright (c) 2009-2010 elements.at New Media Solutions GmbH (http://www.elements.at)
* @license http://www.pimcore.org/license New BSD License
*/
class Object_Objectbrick_Resource extends Object_Fieldcollection_Resource {
/**
* @param Object_Concrete $object
* @return array
*/
public function load(Object_Concrete $object) {
$fieldDef = $object->getClass()->getFieldDefinition($this->model->getFieldname());
$values = array();
foreach ($fieldDef->getAllowedTypes() as $type) {
try {
$definition = Object_Objectbrick_Definition::getByKey($type);
} catch (Exception $e) {
continue;
}
$tableName = $definition->getTableName($object->getClass(), false);
try {
$results = $this->db->fetchAll("SELECT * FROM ".$tableName." WHERE o_id = ? AND fieldname = ?", array($object->getId(), $this->model->getFieldname()));
} catch (Exception $e) {
$results = array();
}
$allRelations = $this->db->fetchAll("SELECT * FROM object_relations_" . $object->getO_classId() . " WHERE src_id = ? AND ownertype = 'objectbrick' AND ownername = ?", array($object->getO_id(), $this->model->getFieldname()));
$fieldDefinitions = $definition->getFieldDefinitions();
$brickClass = "Object_Objectbrick_Data_" . ucfirst($type);
foreach ($results as $result) {
$brick = new $brickClass($object);
$brick->setFieldname($result["fieldname"]);
$brick->setObject($object);
foreach ($fieldDefinitions as $key => $fd) {
/*if ($fd->isRelationType()) {
$relations = array();
foreach ($allRelations as $relation) {
if ($relation["fieldname"] == $key) {
$relations[] = $relation;
}
}
$brick->setValue( $key, $fd->getDataFromResource($relations));
}*/
if (method_exists($fd, "load")) {
// datafield has it's own loader
$value = $fd->load($brick);
if($value === 0 || !empty($value)) {
$brick->setValue($key, $value);
}
} else {
if (is_array($fd->getColumnType())) {
$multidata = array();
foreach ($fd->getColumnType() as $fkey => $fvalue) {
$multidata[$key . "__" . $fkey] = $result[$key . "__" . $fkey];
}
$brick->setValue(
$key,
$fd->getDataFromResource($multidata));
} else {
$brick->setValue(
$key,
$fd->getDataFromResource($result[$key]));
}
}
}
$setter = "set" . ucfirst($type);
$this->model->$setter($brick);
$values[] = $brick;
}
}
return $values;
}
/**
* @throws Exception
* @param Object_Concrete $object
* @return void
*/
public function delete (Object_Concrete $object) {
throw new Exception("Not implemented yet");
}
}