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_GiftMessage
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27:
28: /**
29: * Gift Message model
30: *
31: * @method Mage_GiftMessage_Model_Resource_Message _getResource()
32: * @method Mage_GiftMessage_Model_Resource_Message getResource()
33: * @method int getCustomerId()
34: * @method Mage_GiftMessage_Model_Message setCustomerId(int $value)
35: * @method string getSender()
36: * @method Mage_GiftMessage_Model_Message setSender(string $value)
37: * @method string getRecipient()
38: * @method Mage_GiftMessage_Model_Message setRecipient(string $value)
39: * @method string getMessage()
40: * @method Mage_GiftMessage_Model_Message setMessage(string $value)
41: *
42: * @category Mage
43: * @package Mage_GiftMessage
44: * @author Magento Core Team <core@magentocommerce.com>
45: */
46: class Mage_GiftMessage_Model_Message extends Mage_Core_Model_Abstract
47: {
48: /**
49: * Allowed types of entities for using of gift messages
50: *
51: * @var array
52: */
53: static protected $_allowedEntityTypes = array(
54: 'order' => 'sales/order',
55: 'order_item' => 'sales/order_item',
56: 'order_address' => 'sales/order_address',
57: 'quote' => 'sales/quote',
58: 'quote_item' => 'sales/quote_item',
59: 'quote_address' => 'sales/quote_address',
60: 'quote_address_item' => 'sales/quote_address_item'
61: );
62:
63: protected function _construct()
64: {
65: $this->_init('giftmessage/message');
66: }
67:
68: /**
69: * Return model from entity type
70: *
71: * @param string $type
72: * @return Mage_Eav_Model_Entity_Abstract
73: */
74: public function getEntityModelByType($type)
75: {
76: $types = self::getAllowedEntityTypes();
77: if(!isset($types[$type])) {
78: Mage::throwException(Mage::helper('giftmessage')->__('Unknown entity type'));
79: }
80:
81: return Mage::getModel($types[$type]);
82: }
83:
84: /**
85: * Checks thats gift message is empty
86: *
87: * @return boolean
88: */
89: public function isMessageEmpty()
90: {
91: return trim($this->getMessage()) == '';
92: }
93:
94: /**
95: * Return list of allowed entities for using in gift messages
96: *
97: * @return array
98: */
99: static public function getAllowedEntityTypes()
100: {
101: return self::$_allowedEntityTypes;
102: }
103:
104: }
105: