PageRenderTime 43ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/app/code/core/Mage/DesignEditor/Model/History.php

https://bitbucket.org/sunil_nextbits/magento2
PHP | 160 lines | 59 code | 15 blank | 86 comment | 3 complexity | e0ecec5b89c5d94e063826588e6a0e9d MD5 | raw file
  1. <?php
  2. /**
  3. * Magento
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@magentocommerce.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade Magento to newer
  18. * versions in the future. If you wish to customize Magento for your
  19. * needs please refer to http://www.magentocommerce.com for more information.
  20. *
  21. * @category Mage
  22. * @package Mage_DesignEditor
  23. * @copyright Copyright (c) 2012 X.commerce, Inc. (http://www.magentocommerce.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26. /**
  27. * Visual Design Editor history model
  28. */
  29. class Mage_DesignEditor_Model_History
  30. {
  31. /**
  32. * Base class for all change instances
  33. */
  34. const BASE_CHANGE_CLASS = 'Mage_DesignEditor_Model_ChangeAbstract';
  35. /**
  36. * Changes collection class
  37. */
  38. const CHANGE_COLLECTION_CLASS = 'Mage_DesignEditor_Model_Change_Collection';
  39. /**
  40. * Internal collection of changes
  41. *
  42. * @var Mage_DesignEditor_Model_Change_Collection
  43. */
  44. protected $_collection;
  45. /**
  46. * Initialize empty internal collection
  47. */
  48. public function __construct()
  49. {
  50. $this->_initCollection();
  51. }
  52. /**
  53. * Initialize changes collection
  54. *
  55. * @return Mage_DesignEditor_Model_History
  56. */
  57. protected function _initCollection()
  58. {
  59. $this->_collection = Mage::getModel(self::CHANGE_COLLECTION_CLASS);
  60. return $this;
  61. }
  62. /**
  63. * Get change instance
  64. *
  65. * @param array $data
  66. * @return Mage_DesignEditor_Model_ChangeAbstract
  67. */
  68. protected function _getChangeItem($data)
  69. {
  70. return Mage_DesignEditor_Model_Change_Factory::getInstance($data);
  71. }
  72. /**
  73. * Load changes from DB. To be able to effectively compact changes they should be all loaded first.
  74. *
  75. * @return Mage_DesignEditor_Model_History
  76. */
  77. public function loadChanges()
  78. {
  79. return $this;
  80. }
  81. /**
  82. * Add change to internal collection
  83. *
  84. * @param Mage_DesignEditor_Model_ChangeAbstract|Varien_Object|array $item
  85. * @return Mage_DesignEditor_Model_History
  86. */
  87. public function addChange($item)
  88. {
  89. $baseChangeClass = self::BASE_CHANGE_CLASS;
  90. if (!$item instanceof $baseChangeClass) {
  91. $item = $this->_getChangeItem($item);
  92. }
  93. $this->_collection->addItem($item);
  94. return $this;
  95. }
  96. /**
  97. * Add changes to internal collection
  98. *
  99. * @param array|Traversable $changes
  100. * @return Mage_DesignEditor_Model_History
  101. */
  102. public function addChanges($changes)
  103. {
  104. foreach ($changes as $change) {
  105. $this->addChange($change);
  106. }
  107. return $this;
  108. }
  109. /**
  110. * Set changes to internal collection
  111. *
  112. * @param array|Traversable $changes
  113. * @return Mage_DesignEditor_Model_History
  114. */
  115. public function setChanges($changes)
  116. {
  117. $collectionClass = self::CHANGE_COLLECTION_CLASS;
  118. if ($changes instanceof $collectionClass) {
  119. $this->_collection = $changes;
  120. } else {
  121. $this->_initCollection();
  122. $this->addChanges($changes);
  123. }
  124. return $this;
  125. }
  126. /**
  127. * Get changes collection
  128. *
  129. * @return Mage_DesignEditor_Model_Change_Collection
  130. */
  131. public function getChanges()
  132. {
  133. return $this->_collection;
  134. }
  135. /**
  136. * Render all types of output
  137. *
  138. * @param Mage_DesignEditor_Model_History_RendererInterface $renderer
  139. * @return Mage_DesignEditor_Model_History_RendererInterface
  140. */
  141. public function output(Mage_DesignEditor_Model_History_RendererInterface $renderer)
  142. {
  143. return $renderer->render($this->_collection);
  144. }
  145. }