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: * Queue resource collection
29: *
30: * @category Mage
31: * @package Mage_XmlConnect
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34: class Mage_XmlConnect_Model_Resource_Queue_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
35: {
36: /**
37: * Internal constructor
38: *
39: * @return null
40: */
41: protected function _construct()
42: {
43: $this->_init('xmlconnect/queue');
44: }
45:
46: /**
47: * Initialize collection select
48: *
49: * @return Mage_XmlConnect_Model_Resource_Queue_Collection
50: */
51: protected function _initSelect()
52: {
53: parent::_initSelect();
54: $this->_joinNames();
55: return $this;
56: }
57:
58: /**
59: * Join Template Name and Application Name to collection
60: *
61: * @return Mage_XmlConnect_Model_Resource_Queue_Collection
62: */
63: protected function _joinNames()
64: {
65: $this->_joinTemplateName();
66: $this->_joinApplicationName();
67: return $this;
68: }
69:
70: /**
71: * Join Template Name to collection
72: *
73: * @return Mage_XmlConnect_Model_Resource_Queue_Collection
74: */
75: protected function _joinTemplateName()
76: {
77: $this->getSelect()->joinLeft(
78: array('t' => $this->getTable('xmlconnect/template')),
79: 't.template_id = main_table.template_id',
80: array('template_name' => 't.name')
81: );
82: return $this;
83: }
84:
85: /**
86: * Join Application Name to collection
87: *
88: * @return Mage_XmlConnect_Model_Resource_Queue_Collection
89: */
90: protected function _joinApplicationName()
91: {
92: $this->getSelect()->joinLeft(
93: array('app' => $this->getTable('xmlconnect/application')),
94: 'app.application_id = t.application_id',
95: array('application_name' => 'app.name')
96: );
97: return $this;
98: }
99:
100: /**
101: * Add filter by only ready fot sending item
102: *
103: * @return Mage_XmlConnect_Model_Resource_Queue_Collection
104: */
105: public function addOnlyForSendingFilter()
106: {
107: $this->getSelect()->where('main_table.status in (?)', array(Mage_XmlConnect_Model_Queue::STATUS_IN_QUEUE))
108: ->where('main_table.exec_time < ?', Mage::getSingleton('core/date')->gmtDate())
109: ->order(new Zend_Db_Expr('main_table.exec_time ' . Zend_Db_Select::SQL_ASC)
110: );
111: return $this;
112: }
113: }
114: