/pimcore/models/Object/Objectbrick/Data/Abstract.php

https://github.com/timglabisch/pimcore · PHP · 160 lines · 66 code · 24 blank · 70 comment · 3 complexity · fe79e17261ce9f3183d8cb76dd7d916a MD5 · raw file

  1. <?php
  2. /**
  3. * Pimcore
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://www.pimcore.org/license
  11. *
  12. * @category Pimcore
  13. * @package Object_Objectbrick
  14. * @copyright Copyright (c) 2009-2013 pimcore GmbH (http://www.pimcore.org)
  15. * @license http://www.pimcore.org/license New BSD License
  16. */
  17. class Object_Objectbrick_Data_Abstract extends Pimcore_Model_Abstract {
  18. /**
  19. * @var string
  20. */
  21. public $fieldname;
  22. /**
  23. * @var bool
  24. */
  25. public $doDelete;
  26. /**
  27. * @var Object_Concrete
  28. */
  29. public $object;
  30. /**
  31. * @param Object_Concrete $object
  32. */
  33. public function __construct(Object_Concrete $object) {
  34. $this->setObject($object);
  35. }
  36. /**
  37. * @return string
  38. */
  39. public function getFieldname () {
  40. return $this->fieldname;
  41. }
  42. /**
  43. * @param $fieldname
  44. * @return void
  45. */
  46. public function setFieldname ($fieldname) {
  47. $this->fieldname = $fieldname;
  48. return $this;
  49. }
  50. /**
  51. * @return
  52. */
  53. public function getType () {
  54. return $this->type;
  55. }
  56. /**
  57. * @return mixed
  58. */
  59. public function getDefinition () {
  60. $definition = Object_Objectbrick_Definition::getByKey($this->getType());
  61. return $definition;
  62. }
  63. /**
  64. * @param $doDelete
  65. * @return void
  66. */
  67. public function setDoDelete($doDelete)
  68. {
  69. $this->doDelete = $doDelete;
  70. return $this;
  71. }
  72. /**
  73. * @return bool
  74. */
  75. public function getDoDelete()
  76. {
  77. return $this->doDelete;
  78. }
  79. /**
  80. * for compatibility, in case of removeal, please force a save on every available brick in updatescript
  81. * @deprecated
  82. * @return
  83. */
  84. public function getBaseObject() {
  85. return $this->getObject();
  86. }
  87. /**
  88. * @param $object
  89. * @return void
  90. */
  91. public function delete($object) {
  92. $this->doDelete = true;
  93. parent::delete($object);
  94. }
  95. /**
  96. * @return mixed
  97. */
  98. public function getValueFromParent($key) {
  99. $parent = Object_Service::hasInheritableParentObject($this->getObject());
  100. if(!empty($parent)) {
  101. $containerGetter = "get" . ucfirst($this->fieldname);
  102. $brickGetter = "get" . ucfirst($this->getType());
  103. $getter = "get" . ucfirst($key);
  104. if($parent->$containerGetter()->$brickGetter()) {
  105. return $parent->$containerGetter()->$brickGetter()->$getter();
  106. }
  107. }
  108. return null;
  109. }
  110. /**
  111. * @param Object_Concrete $object
  112. * @return void
  113. */
  114. public function setObject($object)
  115. {
  116. $this->object = $object;
  117. return $this;
  118. }
  119. /**
  120. * @return Object_Concrete
  121. */
  122. public function getObject()
  123. {
  124. return $this->object;
  125. }
  126. /**
  127. * @param string $key
  128. * @return void
  129. */
  130. public function getValueForFieldName($key) {
  131. if ($this->$key) {
  132. return $this->$key;
  133. }
  134. return false;
  135. }
  136. }