*/ class Mage_XmlConnect_Model_Simplexml_Message extends Varien_Object { /** * Message status `error` */ const MESSAGE_STATUS_ERROR = 'error'; /** * Message status `warning` */ const MESSAGE_STATUS_WARNING = 'warning'; /** * Message status `success` */ const MESSAGE_STATUS_SUCCESS = 'success'; /** * Error message decorator * * @var Mage_XmlConnect_Model_Simplexml_Message_Abstract */ protected $_messageRenderer; /** * Message status * * @var string */ protected $_messageStatus; /** * Message code * * @var string */ protected $_messageCode; /** * Message text * * @var string|null */ protected $_messageText; /** * Children message params * * @var array */ protected $_children = array(); /** * Flag error in processing the message * * @var bool */ protected $_flagError = false; /** * Init simple xml message * * @param string $messageCode */ public function __construct($messageCode) { $this->setMessageCode($messageCode)->_setMessageStatus(); switch ($this->getMessageStatus()) { case self::MESSAGE_STATUS_SUCCESS: case self::MESSAGE_STATUS_WARNING: $renderer = self::MESSAGE_STATUS_SUCCESS; break; case self::MESSAGE_STATUS_ERROR: $renderer = self::MESSAGE_STATUS_ERROR; break; default: $this->setMessageCode(Mage_XmlConnect_Model_Simplexml_Message_Error::ERROR_SERVER_SP_DEFAULT) ->setMessageText(Mage::helper('xmlconnect')->__('Message type doesn\'t recognized')) ->_setMessageStatus()->_setFlagError(true); $renderer = self::MESSAGE_STATUS_ERROR; break; } $this->_setMessageRenderer(Mage::getModel('xmlconnect/simplexml_message_' . $renderer, $this)); } /** * Get message type * * @return Mage_XmlConnect_Model_Simplexml_Message */ protected function _setMessageStatus() { list($messageType) = explode('_', $this->_messageCode); $this->_messageStatus = $messageType; return $this; } /** * Get message status * * @return string */ public function getMessageStatus() { return $this->_messageStatus; } /** * Get message text * * @return string|null */ public function getMessageText() { return $this->_messageText; } /** * set message text * * @param string $text * @return Mage_XmlConnect_Model_Simplexml_Message */ public function setMessageText($text) { if (!$this->_getFlagError()) { $this->_messageText = $text; } return $this; } /** * Get message code * * @return string */ public function getMessageCode() { return $this->_messageCode; } /** * Set message code * * @param string $messageCode * @return Mage_XmlConnect_Model_Simplexml_Message */ public function setMessageCode($messageCode) { if (!$this->_getFlagError()) { $this->_messageCode = $messageCode; } return $this; } /** * Convert object attributes to string * * @return string */ public function __toString() { return $this->_getMessageRenderer()->getMessage(); } /** * Set children message params * * @param array $children * @return Mage_XmlConnect_Model_Simplexml_Message */ public function setChildren($children) { if (!$this->_getFlagError()) { $this->_children = $children; } return $this; } /** * Set children message params * * @return array */ public function getChildren() { return $this->_children; } /** * Get message renderer * * @return Mage_XmlConnect_Model_Simplexml_Message_Abstract */ protected function _getMessageRenderer() { return $this->_messageRenderer; } /** * Set message renderer * * @param Mage_XmlConnect_Model_Simplexml_Message_Abstract $messageRenderer * @return Mage_XmlConnect_Model_Simplexml_Message */ protected function _setMessageRenderer($messageRenderer) { $this->_messageRenderer = $messageRenderer; return $this; } /** * Get flag error in processing * * @return boolean */ public function _getFlagError() { return $this->_flagError; } /** * Set flag error in processing * * @param boolean $flagError * @return Mage_XmlConnect_Model_Simplexml_Message */ public function _setFlagError($flagError) { $this->_flagError = $flagError; return $this; } }