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_Adminhtml
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: * Synchronize button renderer
30: *
31: * @category Mage
32: * @package Mage_Adminhtml
33: * @author Magento Core Team <core@magentocommerce.com>
34: */
35: class Mage_Adminhtml_Block_System_Config_System_Storage_Media_Synchronize
36: extends Mage_Adminhtml_Block_System_Config_Form_Field
37: {
38: /*
39: * Set template
40: */
41: protected function _construct()
42: {
43: parent::_construct();
44: $this->setTemplate('system/config/system/storage/media/synchronize.phtml');
45: }
46:
47: /**
48: * Remove scope label
49: *
50: * @param Varien_Data_Form_Element_Abstract $element
51: * @return string
52: */
53: public function render(Varien_Data_Form_Element_Abstract $element)
54: {
55: $element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue();
56: return parent::render($element);
57: }
58:
59: /**
60: * Return element html
61: *
62: * @param Varien_Data_Form_Element_Abstract $element
63: * @return string
64: */
65: protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
66: {
67: return $this->_toHtml();
68: }
69:
70: /**
71: * Return ajax url for synchronize button
72: *
73: * @return string
74: */
75: public function getAjaxSyncUrl()
76: {
77: return Mage::getSingleton('adminhtml/url')->getUrl('*/system_config_system_storage/synchronize');
78: }
79:
80: /**
81: * Return ajax url for synchronize button
82: *
83: * @return string
84: */
85: public function getAjaxStatusUpdateUrl()
86: {
87: return Mage::getSingleton('adminhtml/url')->getUrl('*/system_config_system_storage/status');
88: }
89:
90: /**
91: * Generate synchronize button html
92: *
93: * @return string
94: */
95: public function getButtonHtml()
96: {
97: $button = $this->getLayout()->createBlock('adminhtml/widget_button')
98: ->setData(array(
99: 'id' => 'synchronize_button',
100: 'label' => $this->helper('adminhtml')->__('Synchronize'),
101: 'onclick' => 'javascript:synchronize(); return false;'
102: ));
103:
104: return $button->toHtml();
105: }
106:
107: /**
108: * Retrieve last sync params settings
109: *
110: * Return array format:
111: * array (
112: * => storage_type int,
113: * => connection_name string
114: * )
115: *
116: * @return array
117: */
118: public function getSyncStorageParams()
119: {
120: $flag = Mage::getSingleton('core/file_storage')->getSyncFlag();
121: $flagData = $flag->getFlagData();
122:
123: if ($flag->getState() == Mage_Core_Model_File_Storage_Flag::STATE_NOTIFIED
124: && is_array($flagData)
125: && isset($flagData['destination_storage_type']) && $flagData['destination_storage_type'] != ''
126: && isset($flagData['destination_connection_name'])
127: ) {
128: $storageType = $flagData['destination_storage_type'];
129: $connectionName = $flagData['destination_connection_name'];
130: } else {
131: $storageType = Mage_Core_Model_File_Storage::STORAGE_MEDIA_FILE_SYSTEM;
132: $connectionName = '';
133: }
134:
135: return array(
136: 'storage_type' => $storageType,
137: 'connection_name' => $connectionName
138: );
139: }
140: }
141: