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_Core
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: * Core Flag model
30: *
31: * @method Mage_Core_Model_Resource_Flag _getResource()
32: * @method Mage_Core_Model_Resource_Flag getResource()
33: * @method string getFlagCode()
34: * @method Mage_Core_Model_Flag setFlagCode(string $value)
35: * @method int getState()
36: * @method Mage_Core_Model_Flag setState(int $value)
37: * @method string getLastUpdate()
38: * @method Mage_Core_Model_Flag setLastUpdate(string $value)
39: *
40: * @category Mage
41: * @package Mage_Core
42: * @author Magento Core Team <core@magentocommerce.com>
43: */
44: class Mage_Core_Model_Flag extends Mage_Core_Model_Abstract
45: {
46: /**
47: * Flag code
48: *
49: * @var string
50: */
51: protected $_flagCode = null;
52:
53: /**
54: * Init resource model
55: * Set flag_code if it is specified in arguments
56: *
57: */
58: protected function _construct()
59: {
60: if ($this->hasData('flag_code')) {
61: $this->_flagCode = $this->getData('flag_code');
62: }
63: $this->_init('core/flag');
64: }
65:
66: /**
67: * Processing object before save data
68: *
69: * @return Mage_Core_Model_Flag
70: */
71: protected function _beforeSave()
72: {
73: if (is_null($this->_flagCode)) {
74: Mage::throwException(Mage::helper('core')->__('Please define flag code.'));
75: }
76:
77: $this->setFlagCode($this->_flagCode);
78: $this->setLastUpdate(date('Y-m-d H:i:s'));
79:
80: return parent::_beforeSave();
81: }
82:
83: /**
84: * Retrieve flag data
85: *
86: * @return mixed
87: */
88: public function getFlagData()
89: {
90: if ($this->hasFlagData()) {
91: return unserialize($this->getData('flag_data'));
92: } else {
93: return null;
94: }
95: }
96:
97: /**
98: * Set flag data
99: *
100: * @param mixed $value
101: * @return Mage_Core_Model_Flag
102: */
103: public function setFlagData($value)
104: {
105: return $this->setData('flag_data', serialize($value));
106: }
107:
108: /**
109: * load self (load by flag code)
110: *
111: * @return Mage_Core_Model_Flag
112: */
113: public function loadSelf()
114: {
115: if (is_null($this->_flagCode)) {
116: Mage::throwException(Mage::helper('core')->__('Please define flag code.'));
117: }
118:
119: return $this->load($this->_flagCode, 'flag_code');
120: }
121: }
122: