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_XmlConnect
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: * XmlConnect Model Resource Application
29: *
30: * @category Mage
31: * @package Mage_XmlConnect
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34: class Mage_XmlConnect_Model_Resource_Application extends Mage_Core_Model_Resource_Db_Abstract
35: {
36: /**
37: * Constructor, setting table and index field
38: *
39: * @return null
40: */
41: protected function _construct()
42: {
43: $this->_init('xmlconnect/application', 'application_id');
44: }
45:
46: /**
47: * Update Application Status field, insert data to history table
48: *
49: * @param int $applicationId
50: * @param string $status
51: * @return Mage_XmlConnect_Model_Resource_Application
52: */
53: public function updateApplicationStatus($applicationId, $status)
54: {
55: $this->_getWriteAdapter()->update(
56: $this->getMainTable(),
57: array('status' => $status),
58: $this->_getWriteAdapter()->quoteInto($this->getIdFieldName() . '=?', $applicationId)
59: );
60: return $this;
61: }
62:
63: /**
64: * Processing object before save data
65: * Update app_code as Store + Device
66: *
67: * @param Mage_Core_Model_Abstract $object
68: * @return Mage_Core_Model_Abstract
69: */
70: protected function _beforeSave(Mage_Core_Model_Abstract $object)
71: {
72: if (!$object->getId()) {
73: $object->setCode($object->getCodePrefix());
74: }
75: return parent::_beforeSave($object);
76: }
77:
78: /**
79: * Processing object after save data
80: * Update app_code as Store + Device + 123 (increment).
81: *
82: * @param Mage_Core_Model_Abstract $object
83: * @return Mage_Core_Model_Abstract
84: */
85: protected function _afterSave(Mage_Core_Model_Abstract $object)
86: {
87: $appCode = $object->getCode();
88: $isCodePrefixed = $object->isCodePrefixed();
89: if (!$isCodePrefixed) {
90: $this->_getWriteAdapter()->update(
91: $this->getMainTable(),
92: array('code' => $appCode . $object->getId()),
93: $this->_getWriteAdapter()->quoteInto($this->getIdFieldName() . '=?', $object->getId())
94: );
95: }
96: return parent::_afterSave($object);
97: }
98:
99: /**
100: * Collect existing stores and type unique pairs
101: *
102: * @return array
103: */
104: public function getExistingStoreDeviceType()
105: {
106: $select = $this->_getWriteAdapter()->select()->from($this->getMainTable(), array('store_id', 'type'))
107: ->group(array('store_id', 'type'))->order(array('store_id', 'type'));
108: return $this->_getReadAdapter()->fetchAll($select, array('store_id', 'type'));
109: }
110:
111: /**
112: * Update all applications "updated at" parameter with current date
113: *
114: * @return Mage_XmlConnect_Model_Resource_Application
115: */
116: public function updateAllAppsUpdatedAtParameter()
117: {
118: $this->_getWriteAdapter()->update($this->getMainTable(), array('updated_at' => date('Y-m-d H:i:s')));
119: return $this;
120: }
121: }
122: