1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27: 28: 29: 30: 31: 32: 33:
34: class Mage_Downloadable_Block_Customer_Products_List extends Mage_Core_Block_Template
35: {
36:
37: 38: 39:
40: public function __construct()
41: {
42: parent::__construct();
43: $session = Mage::getSingleton('customer/session');
44: $purchased = Mage::getResourceModel('downloadable/link_purchased_collection')
45: ->addFieldToFilter('customer_id', $session->getCustomerId())
46: ->addOrder('created_at', 'desc');
47: $this->setPurchased($purchased);
48: $purchasedIds = array();
49: foreach ($purchased as $_item) {
50: $purchasedIds[] = $_item->getId();
51: }
52: if (empty($purchasedIds)) {
53: $purchasedIds = array(null);
54: }
55: $purchasedItems = Mage::getResourceModel('downloadable/link_purchased_item_collection')
56: ->addFieldToFilter('purchased_id', array('in' => $purchasedIds))
57: ->addFieldToFilter('status',
58: array(
59: 'nin' => array(
60: Mage_Downloadable_Model_Link_Purchased_Item::LINK_STATUS_PENDING_PAYMENT,
61: Mage_Downloadable_Model_Link_Purchased_Item::LINK_STATUS_PAYMENT_REVIEW
62: )
63: )
64: )
65: ->setOrder('item_id', 'desc');
66: $this->setItems($purchasedItems);
67: }
68:
69: 70: 71: 72: 73:
74: protected function _prepareLayout()
75: {
76: parent::_prepareLayout();
77:
78: $pager = $this->getLayout()->createBlock('page/html_pager', 'downloadable.customer.products.pager')
79: ->setCollection($this->getItems());
80: $this->setChild('pager', $pager);
81: $this->getItems()->load();
82: foreach ($this->getItems() as $item) {
83: $item->setPurchased($this->getPurchased()->getItemById($item->getPurchasedId()));
84: }
85: return $this;
86: }
87:
88: 89: 90: 91: 92: 93:
94: public function getOrderViewUrl($orderId)
95: {
96: return $this->getUrl('sales/order/view', array('order_id' => $orderId));
97: }
98:
99: 100: 101: 102: 103:
104: public function getBackUrl()
105: {
106: if ($this->getRefererUrl()) {
107: return $this->getRefererUrl();
108: }
109: return $this->getUrl('customer/account/');
110: }
111:
112: 113: 114: 115: 116:
117: public function getRemainingDownloads($item)
118: {
119: if ($item->getNumberOfDownloadsBought()) {
120: $downloads = $item->getNumberOfDownloadsBought() - $item->getNumberOfDownloadsUsed();
121: return $downloads;
122: }
123: return Mage::helper('downloadable')->__('Unlimited');
124: }
125:
126: 127: 128: 129: 130: 131:
132: public function getDownloadUrl($item)
133: {
134: return $this->getUrl('*/download/link', array('id' => $item->getLinkHash(), '_secure' => true));
135: }
136:
137: 138: 139: 140: 141:
142: public function getIsOpenInNewWindow()
143: {
144: return Mage::getStoreConfigFlag(Mage_Downloadable_Model_Link::XML_PATH_TARGET_NEW_WINDOW);
145: }
146:
147: }
148: