Perception_Bannerpro - Version 1.0.0

Version Notes

First Release

All in One Banner Pro – Magento Extension by Perception System

All in One Banner Pro Extension allows you to manage unlimited banners with list of sliding effects will make up your site effective and attractive in look.

Support 26 effects with jQuery

Blind X, Blind Y, Blind Z, Cover, Curtain X, Curtain Y, Fade, Fade Zoom, Grow X, Grow Y, Scroll Up, Scroll Down, Scroll Left, Scroll Right, Scroll Horizontal, Scroll Vertical, Shuffle, Toss, Turn Up, Turn Down, Turn Left, Turn Right, Uncover, Wipe, Zoom

Download this release

Release Info

Developer Magento Core Team
Extension Perception_Bannerpro
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

Files changed (42) hide show
  1. app/code/local/Perception/Bannerpro/Block/Adminhtml/Bannerpro.php +12 -0
  2. app/code/local/Perception/Bannerpro/Block/Adminhtml/Bannerpro/Edit.php +45 -0
  3. app/code/local/Perception/Bannerpro/Block/Adminhtml/Bannerpro/Edit/Form.php +19 -0
  4. app/code/local/Perception/Bannerpro/Block/Adminhtml/Bannerpro/Edit/Tab/Form.php +108 -0
  5. app/code/local/Perception/Bannerpro/Block/Adminhtml/Bannerpro/Edit/Tabs.php +24 -0
  6. app/code/local/Perception/Bannerpro/Block/Adminhtml/Bannerpro/Grid.php +182 -0
  7. app/code/local/Perception/Bannerpro/Block/Adminhtml/Grid/Renderer/Image.php +14 -0
  8. app/code/local/Perception/Bannerpro/Block/Bannerpro.php +16 -0
  9. app/code/local/Perception/Bannerpro/Block/Widget/Grid/Column.php +58 -0
  10. app/code/local/Perception/Bannerpro/Block/Widget/Grid/Column/Filter/Image.php +31 -0
  11. app/code/local/Perception/Bannerpro/Block/Widget/Grid/Column/Renderer/Action.php +77 -0
  12. app/code/local/Perception/Bannerpro/Block/Widget/Grid/Column/Renderer/Image.php +84 -0
  13. app/code/local/Perception/Bannerpro/Helper/Data.php +16 -0
  14. app/code/local/Perception/Bannerpro/Helper/Image.php +345 -0
  15. app/code/local/Perception/Bannerpro/Helper/Wysiwyg/Images.php +41 -0
  16. app/code/local/Perception/Bannerpro/Model/Bannerpro.php +10 -0
  17. app/code/local/Perception/Bannerpro/Model/Entity/Attribute/Source/Boolean/Config.php +42 -0
  18. app/code/local/Perception/Bannerpro/Model/Image.php +508 -0
  19. app/code/local/Perception/Bannerpro/Model/Mysql4/Bannerpro.php +158 -0
  20. app/code/local/Perception/Bannerpro/Model/Mysql4/Bannerpro/Collection.php +123 -0
  21. app/code/local/Perception/Bannerpro/Model/Status.php +15 -0
  22. app/code/local/Perception/Bannerpro/Model/System/Backend/Links.php +40 -0
  23. app/code/local/Perception/Bannerpro/Model/System/Config/Source/Effect.php +70 -0
  24. app/code/local/Perception/Bannerpro/Model/Wysiwyg/Config.php +100 -0
  25. app/code/local/Perception/Bannerpro/Model/Wysiwyg/Images/Storage.php +37 -0
  26. app/code/local/Perception/Bannerpro/Model/Wysiwyg/Images/Storage/Collection.php +37 -0
  27. app/code/local/Perception/Bannerpro/controllers/Adminhtml/BannerproController.php +246 -0
  28. app/code/local/Perception/Bannerpro/controllers/IndexController.php +9 -0
  29. app/code/local/Perception/Bannerpro/etc/config.xml +171 -0
  30. app/code/local/Perception/Bannerpro/etc/system.xml +61 -0
  31. app/code/local/Perception/Bannerpro/sql/bannerpro_setup/mysql4-install-1.0.3.php +30 -0
  32. app/design/adminhtml/default/default/layout/bannerpro.xml +8 -0
  33. app/design/frontend/default/default/layout/bannerpro.xml +15 -0
  34. app/design/frontend/default/default/template/bannerpro/bannerpro.phtml +67 -0
  35. app/etc/modules/Perception_Bannerpro.xml +9 -0
  36. package.xml +56 -0
  37. skin/frontend/default/default/banner/banner_effects.js +1567 -0
  38. skin/frontend/default/default/banner/bannerpro.css +30 -0
  39. skin/frontend/default/default/banner/bannerpro.js +155 -0
  40. skin/frontend/default/default/banner/images/next-prev-btn.png +0 -0
  41. skin/frontend/default/default/banner/images/pause.png +0 -0
  42. skin/frontend/default/default/banner/images/play.png +0 -0
app/code/local/Perception/Bannerpro/Block/Adminhtml/Bannerpro.php ADDED
@@ -0,0 +1,12 @@
1
+ <?php
2
+ class Perception_Bannerpro_Block_Adminhtml_Bannerpro extends Mage_Adminhtml_Block_Widget_Grid_Container
3
+ {
4
+ public function __construct()
5
+ {
6
+ $this->_controller = 'adminhtml_bannerpro';
7
+ $this->_blockGroup = 'bannerpro';
8
+ $this->_headerText = Mage::helper('bannerpro')->__('Banner Manager');
9
+ $this->_addButtonLabel = Mage::helper('bannerpro')->__('Add Banner');
10
+ parent::__construct();
11
+ }
12
+ }
app/code/local/Perception/Bannerpro/Block/Adminhtml/Bannerpro/Edit.php ADDED
@@ -0,0 +1,45 @@
1
+ <?php
2
+
3
+ class Perception_Bannerpro_Block_Adminhtml_Bannerpro_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
4
+ {
5
+ public function __construct()
6
+ {
7
+ parent::__construct();
8
+
9
+ $this->_objectId = 'id';
10
+ $this->_blockGroup = 'bannerpro';
11
+ $this->_controller = 'adminhtml_bannerpro';
12
+
13
+ $this->_updateButton('save', 'label', Mage::helper('bannerpro')->__('Save Banner'));
14
+ $this->_updateButton('delete', 'label', Mage::helper('bannerpro')->__('Delete Banner'));
15
+
16
+ $this->_addButton('saveandcontinue', array(
17
+ 'label' => Mage::helper('adminhtml')->__('Save And Continue Edit'),
18
+ 'onclick' => 'saveAndContinueEdit()',
19
+ 'class' => 'save',
20
+ ), -100);
21
+
22
+ $this->_formScripts[] = "
23
+ function toggleEditor() {
24
+ if (tinyMCE.getInstanceById('bannerpro_content') == null) {
25
+ tinyMCE.execCommand('mceAddControl', false, 'bannerpro_content');
26
+ } else {
27
+ tinyMCE.execCommand('mceRemoveControl', false, 'bannerpro_content');
28
+ }
29
+ }
30
+
31
+ function saveAndContinueEdit(){
32
+ editForm.submit($('edit_form').action+'back/edit/');
33
+ }
34
+ ";
35
+ }
36
+
37
+ public function getHeaderText()
38
+ {
39
+ if( Mage::registry('bannerpro_data') && Mage::registry('bannerpro_data')->getId() ) {
40
+ return Mage::helper('bannerpro')->__("Edit Banner '%s'", $this->htmlEscape(Mage::registry('bannerpro_data')->getTitle()));
41
+ } else {
42
+ return Mage::helper('bannerpro')->__('Add Banner');
43
+ }
44
+ }
45
+ }
app/code/local/Perception/Bannerpro/Block/Adminhtml/Bannerpro/Edit/Form.php ADDED
@@ -0,0 +1,19 @@
1
+ <?php
2
+
3
+ class Perception_Bannerpro_Block_Adminhtml_Bannerpro_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
4
+ {
5
+ protected function _prepareForm()
6
+ {
7
+ $form = new Varien_Data_Form(array(
8
+ 'id' => 'edit_form',
9
+ 'action' => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))),
10
+ 'method' => 'post',
11
+ 'enctype' => 'multipart/form-data'
12
+ )
13
+ );
14
+
15
+ $form->setUseContainer(true);
16
+ $this->setForm($form);
17
+ return parent::_prepareForm();
18
+ }
19
+ }
app/code/local/Perception/Bannerpro/Block/Adminhtml/Bannerpro/Edit/Tab/Form.php ADDED
@@ -0,0 +1,108 @@
1
+ <?php
2
+
3
+ class Perception_Bannerpro_Block_Adminhtml_Bannerpro_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form
4
+ {
5
+
6
+ protected function _prepareLayout()
7
+ {
8
+ parent::_prepareLayout();
9
+ if (Mage::getSingleton('bannerpro/wysiwyg_config')->isEnabled()) {
10
+ $this->getLayout()->getBlock('head')->setCanLoadTinyMce(true);
11
+ }
12
+ }
13
+
14
+ protected function _prepareForm()
15
+ {
16
+ $form = new Varien_Data_Form();
17
+ $this->setForm($form);
18
+
19
+ $fieldset = $form->addFieldset('bannerpro_form', array('legend'=>Mage::helper('bannerpro')->__('Banner Information')));
20
+
21
+ $fieldset->addField('title', 'text', array(
22
+ 'label' => Mage::helper('bannerpro')->__('Title'),
23
+ 'class' => 'required-entry',
24
+ 'required' => true,
25
+ 'name' => 'title',
26
+ ));
27
+
28
+ $fieldset->addField('filename', 'image', array(
29
+ 'label' => Mage::helper('bannerpro')->__('Banner Image'),
30
+ 'required' => false,
31
+ 'name' => 'filename',
32
+ ));
33
+
34
+ if (!Mage::app()->isSingleStoreMode()) {
35
+ $fieldset->addField('store_id', 'multiselect', array(
36
+ 'name' => 'stores[]',
37
+ 'label' => Mage::helper('cms')->__('Store View'),
38
+ 'title' => Mage::helper('cms')->__('Store View'),
39
+ 'required' => true,
40
+ 'values' => Mage::getSingleton('adminhtml/system_store')->getStoreValuesForForm(false, true),
41
+ 'disabled' => $isElementDisabled
42
+ ));
43
+ }
44
+
45
+ else {
46
+ $fieldset->addField('store_id', 'hidden', array(
47
+ 'name' => 'stores[]',
48
+ 'value' => Mage::app()->getStore(true)->getId()
49
+ ));
50
+ $model->setStoreId(Mage::app()->getStore(true)->getId());
51
+ }
52
+
53
+ $fieldset->addField('effects', 'select', array(
54
+ 'label' => Mage::helper('bannerpro')->__('Banner Effects'),
55
+ 'name' => 'effects',
56
+ 'values' => Mage::getSingleton('bannerpro/system_config_source_effect')->toOptionArray()
57
+ ));
58
+
59
+ $fieldset->addField('status', 'select', array(
60
+ 'label' => Mage::helper('bannerpro')->__('Status'),
61
+ 'name' => 'status',
62
+ 'values' => array(
63
+ array(
64
+ 'value' => 1,
65
+ 'label' => Mage::helper('bannerpro')->__('Enabled'),
66
+ ),
67
+
68
+ array(
69
+ 'value' => 2,
70
+ 'label' => Mage::helper('bannerpro')->__('Disabled'),
71
+ ),
72
+ ),
73
+ ));
74
+
75
+ $fieldset->addField('sorting_order', 'text', array(
76
+ 'label' => Mage::helper('bannerpro')->__('Sorting Order'),
77
+ 'required' => false,
78
+ 'style' => 'width:50px;',
79
+ 'name' => 'sorting_order',
80
+ ));
81
+
82
+ $fieldset->addField('weblink', 'text', array(
83
+ 'label' => Mage::helper('bannerpro')->__('Website Url'),
84
+ 'required' => false,
85
+ 'name' => 'weblink',
86
+ 'class' => 'validate-url',
87
+ ));
88
+
89
+ $fieldset->addField('text', 'editor', array(
90
+ 'name' => 'text',
91
+ 'label' => Mage::helper('bannerpro')->__('Content'),
92
+ 'title' => Mage::helper('bannerpro')->__('Content'),
93
+ 'style' => 'width:450px; height:400px;',
94
+ 'wysiwyg' => true,
95
+ 'required' => false,
96
+ 'config' => Mage::getSingleton('bannerpro/wysiwyg_config')->getConfig()
97
+ ));
98
+
99
+ if ( Mage::getSingleton('adminhtml/session')->getBannerproData() )
100
+ {
101
+ $form->setValues(Mage::getSingleton('adminhtml/session')->getBannerproData());
102
+ Mage::getSingleton('adminhtml/session')->setBannerproData(null);
103
+ } elseif ( Mage::registry('bannerpro_data') ) {
104
+ $form->setValues(Mage::registry('bannerpro_data')->getData());
105
+ }
106
+ return parent::_prepareForm();
107
+ }
108
+ }
app/code/local/Perception/Bannerpro/Block/Adminhtml/Bannerpro/Edit/Tabs.php ADDED
@@ -0,0 +1,24 @@
1
+ <?php
2
+
3
+ class Perception_Bannerpro_Block_Adminhtml_Bannerpro_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
4
+ {
5
+
6
+ public function __construct()
7
+ {
8
+ parent::__construct();
9
+ $this->setId('bannerpro_tabs');
10
+ $this->setDestElementId('edit_form');
11
+ $this->setTitle(Mage::helper('bannerpro')->__('Banner Information'));
12
+ }
13
+
14
+ protected function _beforeToHtml()
15
+ {
16
+ $this->addTab('form_section', array(
17
+ 'label' => Mage::helper('bannerpro')->__('Banner Information'),
18
+ 'title' => Mage::helper('bannerpro')->__('Banner Information'),
19
+ 'content' => $this->getLayout()->createBlock('bannerpro/adminhtml_bannerpro_edit_tab_form')->toHtml(),
20
+ ));
21
+
22
+ return parent::_beforeToHtml();
23
+ }
24
+ }
app/code/local/Perception/Bannerpro/Block/Adminhtml/Bannerpro/Grid.php ADDED
@@ -0,0 +1,182 @@
1
+ <?php
2
+
3
+ class Perception_Bannerpro_Block_Adminhtml_Bannerpro_Grid extends Mage_Adminhtml_Block_Widget_Grid
4
+ {
5
+ public function __construct()
6
+ {
7
+ parent::__construct();
8
+ $this->setId('bannerproGrid');
9
+ $this->setDefaultSort('bannerpro_id');
10
+ $this->setDefaultDir('ASC');
11
+ $this->setSaveParametersInSession(true);
12
+ }
13
+
14
+ protected function _prepareCollection()
15
+ {
16
+ $collection = Mage::getModel('bannerpro/bannerpro')->getCollection();
17
+ $this->setCollection($collection);
18
+ return parent::_prepareCollection();
19
+ }
20
+
21
+ protected function _prepareColumns()
22
+ {
23
+ $this->addColumn('bannerpro_id', array(
24
+ 'header' => Mage::helper('bannerpro')->__('ID'),
25
+ 'align' =>'right',
26
+ 'width' => '50px',
27
+ 'index' => 'bannerpro_id',
28
+ ));
29
+
30
+ $this->addColumn('filename', array(
31
+ 'header'=>Mage::helper('bannerpro')->__('Image'),
32
+ 'filter'=>false,
33
+ 'index'=>'filename',
34
+ 'align' => 'left',
35
+ 'width' => '50px',
36
+ 'renderer' => 'bannerpro/adminhtml_grid_renderer_image',
37
+ ));
38
+
39
+ $this->addColumn('title', array(
40
+ 'header' => Mage::helper('bannerpro')->__('Title'),
41
+ 'align' =>'left',
42
+ 'index' => 'title',
43
+ 'width' => '550px',
44
+ ));
45
+
46
+ $this->addColumn('text', array(
47
+ 'header' => Mage::helper('bannerpro')->__('Description'),
48
+ 'align' =>'left',
49
+ 'width' => '350px',
50
+ 'index' => 'text',
51
+ ));
52
+
53
+ $this->addColumn('effects', array(
54
+ 'header' => Mage::helper('bannerpro')->__('Effects'),
55
+ 'align' =>'center',
56
+ 'width' => '50px',
57
+ 'index' => 'effects',
58
+ ));
59
+
60
+ $this->addColumn('weblink', array(
61
+ 'header' => Mage::helper('bannerpro')->__('URL'),
62
+ 'align' =>'center',
63
+ 'width' => '50px',
64
+ 'index' => 'weblink',
65
+ ));
66
+
67
+ $this->addColumn('sorting_order', array(
68
+ 'header' => Mage::helper('bannerpro')->__('Sorting Order'),
69
+ 'align' =>'center',
70
+ 'width' => '50px',
71
+ 'index' => 'sorting_order',
72
+ ));
73
+
74
+ if (!Mage::app()->isSingleStoreMode()) {
75
+ $this->addColumn('store_id', array(
76
+ 'header' => Mage::helper('bannerpro')->__('Store View'),
77
+ 'index' => 'store_id',
78
+ 'type' => 'store',
79
+ 'store_all' => true,
80
+ 'store_view' => true,
81
+ 'sortable' => false,
82
+ 'filter_condition_callback'
83
+ => array($this, '_filterStoreCondition'),
84
+ ));
85
+ }
86
+
87
+ $this->addColumn('status', array(
88
+ 'header' => Mage::helper('bannerpro')->__('Status'),
89
+ 'align' => 'left',
90
+ 'width' => '80px',
91
+ 'index' => 'status',
92
+ 'type' => 'options',
93
+ 'options' => array(
94
+ 1 => 'Enabled',
95
+ 2 => 'Disabled',
96
+ ),
97
+ ));
98
+
99
+ $this->addColumn('action',
100
+ array(
101
+ 'header' => Mage::helper('bannerpro')->__('Action'),
102
+ 'width' => '100',
103
+ 'type' => 'action',
104
+ 'getter' => 'getId',
105
+ 'actions' => array(
106
+ array(
107
+ 'caption' => Mage::helper('bannerpro')->__('Edit'),
108
+ 'url' => array('base'=> '*/*/edit'),
109
+ 'field' => 'id'
110
+ )
111
+ ),
112
+ 'filter' => false,
113
+ 'sortable' => false,
114
+ 'index' => 'stores',
115
+ 'is_system' => true,
116
+ ));
117
+
118
+ $this->addExportType('*/*/exportCsv', Mage::helper('bannerpro')->__('CSV'));
119
+ $this->addExportType('*/*/exportXml', Mage::helper('bannerpro')->__('XML'));
120
+
121
+ return parent::_prepareColumns();
122
+ }
123
+
124
+ protected function _prepareMassaction()
125
+ {
126
+ $this->setMassactionIdField('bannerpro_id');
127
+ $this->getMassactionBlock()->setFormFieldName('bannerpro');
128
+
129
+ $this->getMassactionBlock()->addItem('delete', array(
130
+ 'label' => Mage::helper('bannerpro')->__('Delete'),
131
+ 'url' => $this->getUrl('*/*/massDelete'),
132
+ 'confirm' => Mage::helper('bannerpro')->__('Are you sure?')
133
+ ));
134
+
135
+ $statuses = Mage::getSingleton('bannerpro/status')->getOptionArray();
136
+
137
+ array_unshift($statuses, array('label'=>'', 'value'=>''));
138
+ $this->getMassactionBlock()->addItem('status', array(
139
+ 'label'=> Mage::helper('bannerpro')->__('Change status'),
140
+ 'url' => $this->getUrl('*/*/massStatus', array('_current'=>true)),
141
+ 'additional' => array(
142
+ 'visibility' => array(
143
+ 'name' => 'status',
144
+ 'type' => 'select',
145
+ 'class' => 'required-entry',
146
+ 'label' => Mage::helper('bannerpro')->__('Status'),
147
+ 'values' => $statuses
148
+ )
149
+ )
150
+ ));
151
+ return $this;
152
+ }
153
+
154
+ protected function _afterLoadCollection()
155
+ {
156
+ $this->getCollection()->walk('afterLoad');
157
+ parent::_afterLoadCollection();
158
+ }
159
+
160
+ protected function _filterStoreCondition($collection, $column)
161
+ {
162
+ if (!$value = $column->getFilter()->getValue()) {
163
+ return;
164
+ }
165
+
166
+ $this->getCollection()->addStoreFilter($value);
167
+ }
168
+
169
+ public function getRowUrl($row)
170
+ {
171
+ return $this->getUrl('*/*/edit', array('id' => $row->getId()));
172
+ }
173
+
174
+ public function getThumbnailSize()
175
+ {
176
+ $size = trim(Mage::getStoreConfig('bannerpro/info/backend_thumbnail_size'),' ');
177
+ $tmp = explode('-',$size);
178
+ if(sizeof($tmp)==2)
179
+ return array('width'=>is_numeric($tmp[0])?$tmp[0]:85,'height'=>is_numeric($tmp[1])?$tmp[1]:65);
180
+ return array('width'=>85,'height'=>65);
181
+ }
182
+ }
app/code/local/Perception/Bannerpro/Block/Adminhtml/Grid/Renderer/Image.php ADDED
@@ -0,0 +1,14 @@
1
+ <?php
2
+
3
+ class Perception_Bannerpro_Block_Adminhtml_Grid_Renderer_Image extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
4
+ {
5
+ public function render(Varien_Object $row)
6
+ {
7
+ if($row->getFilename()==""){
8
+ return "";
9
+ }
10
+ else{
11
+ return "<img src='".Mage::getBaseUrl("media").$row->getFilename()."' width='50' height='50'/>";
12
+ }
13
+ }
14
+ }
app/code/local/Perception/Bannerpro/Block/Bannerpro.php ADDED
@@ -0,0 +1,16 @@
1
+ <?php
2
+ class Perception_Bannerpro_Block_Bannerpro extends Mage_Core_Block_Template
3
+ {
4
+ public function _prepareLayout()
5
+ {
6
+ return parent::_prepareLayout();
7
+ }
8
+
9
+ public function getBannerpro()
10
+ {
11
+ if (!$this->hasData('bannerpro')) {
12
+ $this->setData('bannerpro', Mage::registry('bannerpro'));
13
+ }
14
+ return $this->getData('bannerpro');
15
+ }
16
+ }
app/code/local/Perception/Bannerpro/Block/Widget/Grid/Column.php ADDED
@@ -0,0 +1,58 @@
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
+ * @category Mage
16
+ * @package TBT_MassRelater
17
+ * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
18
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
+ */
20
+
21
+ /**
22
+ * Grid column block
23
+ *
24
+ * @category Mage
25
+ * @package TBT_MassRelater
26
+ * @author Magento Core Team <core@magentocommerce.com>
27
+ */
28
+ class Perception_Bannerpro_Block_Widget_Grid_Column extends Mage_Adminhtml_Block_Widget_Grid_Column
29
+ {
30
+
31
+
32
+ protected function _getRendererByType()
33
+ {
34
+ switch (strtolower($this->getType())) {
35
+ case 'image':
36
+ $rendererClass = 'bannerpro/widget_grid_column_renderer_image';
37
+ break;
38
+ default:
39
+ $rendererClass = parent::_getRendererByType();
40
+ break;
41
+ }
42
+ return $rendererClass;
43
+ }
44
+
45
+ protected function _getFilterByType()
46
+ {
47
+ switch (strtolower($this->getType())) {
48
+ case 'image':
49
+ $filterClass = 'bannerpro/widget_grid_column_filter_image';
50
+ break;
51
+ default:
52
+ $filterClass = parent::_getFilterByType();
53
+ break;
54
+ }
55
+ return $filterClass;
56
+ }
57
+
58
+ }
app/code/local/Perception/Bannerpro/Block/Widget/Grid/Column/Filter/Image.php ADDED
@@ -0,0 +1,31 @@
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
+ * @category Mage
16
+ * @package TBT_MassRelater
17
+ * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
18
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
+ */
20
+
21
+ /**
22
+ * Checkbox grid column filter
23
+ *
24
+ * @category Mage
25
+ * @package TBT_MassRelater
26
+ * @author Magento Core Team <core@magentocommerce.com>
27
+ */
28
+ class Perception_Bannerpro_Block_Widget_Grid_Column_Filter_Image extends Mage_Adminhtml_Block_Widget_Grid_Column_Filter_Text
29
+ {
30
+
31
+ }
app/code/local/Perception/Bannerpro/Block/Widget/Grid/Column/Renderer/Action.php ADDED
@@ -0,0 +1,77 @@
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
+ * @category Mage
16
+ * @package TBT_MassRelater
17
+ * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
18
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
+ */
20
+
21
+ /**
22
+ * Grid column widget for rendering action grid cells
23
+ *
24
+ * @category Mage
25
+ * @package TBT_MassRelater
26
+ * @author Magento Core Team <core@magentocommerce.com>
27
+ */
28
+ class Perception_Bannerpro_Block_Widget_Grid_Column_Renderer_Action extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Action
29
+ {
30
+
31
+ /**
32
+ * Prepares action data for html render
33
+ *
34
+ * @param array $action
35
+ * @param string $actionCaption
36
+ * @param Varien_Object $row
37
+ * @return Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Action
38
+ */
39
+ protected function _transformActionData(&$action, &$actionCaption, Varien_Object $row)
40
+ {
41
+ foreach ( $action as $attibute => $value ) {
42
+ if(isset($action[$attibute]) && !is_array($action[$attibute])) {
43
+ $this->getColumn()->setFormat($action[$attibute]);
44
+ $action[$attibute] = parent::render($row);
45
+ } else {
46
+ $this->getColumn()->setFormat(null);
47
+ }
48
+
49
+ switch ($attibute) {
50
+ case 'caption':
51
+ $actionCaption = $action['caption'];
52
+ unset($action['caption']);
53
+ break;
54
+
55
+ case 'url':
56
+ if(is_array($action['url'])) {
57
+ $params = array($action['field']=>$this->_getValue($row));
58
+ if(isset($action['url']['params'])) {
59
+ $params = array_merge($action['url']['params'], $params);
60
+ }
61
+ $action['href'] = $this->getUrl($action['url']['base'], $params);
62
+ unset($action['field']);
63
+ } else {
64
+ $action['href'] = $action['url'];
65
+ }
66
+ unset($action['url']);
67
+ break;
68
+
69
+ case 'popup':
70
+ $action['onclick'] = 'popWin(this.href, \'windth=800,height=700,resizable=1,scrollbars=1\');return false;';
71
+ break;
72
+
73
+ }
74
+ }
75
+ return $this;
76
+ }
77
+ }
app/code/local/Perception/Bannerpro/Block/Widget/Grid/Column/Renderer/Image.php ADDED
@@ -0,0 +1,84 @@
1
+ <?php
2
+ /**
3
+ * WDCA
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
+ * @category WDCA
16
+ * @package TBT_Enhancedgrid
17
+ * @copyright Copyright (c) 2008-2010 WDCA (http://www.wdca.ca)
18
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
+ */
20
+
21
+ /**
22
+ * Grid checkbox column renderer
23
+ *
24
+ * @category WDCA
25
+ * @package TBT_Enhancedgrid
26
+ * @author WDCA <contact@wdca.ca>
27
+ */
28
+ class Perception_Bannerpro_Block_Widget_Grid_Column_Renderer_Image extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
29
+ {
30
+ protected static $showImagesUrl = null;
31
+ protected static $showByDefault = null;
32
+ protected static $width = null;
33
+ protected static $height = null;
34
+
35
+ public function __construct() {
36
+
37
+ }
38
+
39
+ /**
40
+ * Renders grid column
41
+ *
42
+ * @param Varien_Object $row
43
+ * @return string
44
+ */
45
+ public function render(Varien_Object $row)
46
+ {
47
+
48
+ return $this->_getValue($row);
49
+ }
50
+
51
+ /*
52
+ public function renderProperty(Varien_Object $row)
53
+ {
54
+ $val = $row->getData($this->getColumn()->getIndex());
55
+ $val = Mage::helper('imagebyurl')->getImageUrl($val);
56
+ $out = parent::renderProperty(). ' onclick="showImage('.$val.')" ';
57
+ return $out;
58
+ }
59
+
60
+ */
61
+ protected function _getValue(Varien_Object $row)
62
+ {
63
+
64
+ if ($getter = $this->getColumn()->getGetter()) {
65
+ $val = $row->$getter();
66
+ }
67
+ $val = $val2 = $row->getData($this->getColumn()->getIndex());
68
+ $val = str_replace("no_selection", "", $val);
69
+ $val2 = str_replace("no_selection", "", $val2);
70
+
71
+ $url = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).$val;
72
+
73
+ $filename = $val;
74
+
75
+ $out = "<img src=". $url ." width='". 100 ."' height='". 100 ."' />";
76
+
77
+ //die( $this->helper('catalog/image')->init($_product, 'small_image')->resize(135, 135));
78
+
79
+
80
+ return $out;
81
+ }
82
+
83
+
84
+ }
app/code/local/Perception/Bannerpro/Helper/Data.php ADDED
@@ -0,0 +1,16 @@
1
+ <?php
2
+ class Perception_Bannerpro_Helper_Data extends Mage_Core_Helper_Abstract
3
+ {
4
+ public function isInStore($itemId) {
5
+ $currentStoreId = Mage::app()->getStore()->getId();
6
+ $item = Mage::getModel('bannerpro/bannerpro')->load($itemId);
7
+ $itemStores = $item->getStoreId();
8
+ $stores = explode(',', $itemStores);
9
+ if(in_array($currentStoreId, $stores) || in_array(0, $stores)) {
10
+ return true;
11
+ }
12
+ else {
13
+ return false;
14
+ }
15
+ }
16
+ }
app/code/local/Perception/Bannerpro/Helper/Image.php ADDED
@@ -0,0 +1,345 @@
1
+ <?php
2
+
3
+ class Perception_Bannerpro_Helper_Image extends Mage_Core_Helper_Abstract
4
+ {
5
+ protected $_model;
6
+ protected $_scheduleResize = false;
7
+ protected $_scheduleWatermark = false;
8
+ protected $_scheduleRotate = false;
9
+ protected $_angle;
10
+ protected $_watermark;
11
+ protected $_watermarkPosition;
12
+ protected $_watermarkSize;
13
+ protected $_imageFile;
14
+ protected $_placeholder;
15
+ protected $set_background_color;
16
+ protected $_view_mode;
17
+ /**
18
+ * Reset all previos data
19
+ */
20
+ protected function _reset()
21
+ {
22
+ $this->_model = null;
23
+ $this->_scheduleResize = false;
24
+ $this->_scheduleWatermark = false;
25
+ $this->_scheduleRotate = false;
26
+ $this->_angle = null;
27
+ $this->_watermark = null;
28
+ $this->_watermarkPosition = null;
29
+ $this->_watermarkSize = null;
30
+ $this->_imageFile = null;
31
+ return $this;
32
+ }
33
+
34
+ public function init($imageFile, $mode="detail")
35
+ {
36
+ $this->_reset();
37
+ $this->_view_mode = $mode;
38
+ $this->_setModel(Mage::getModel('bannerpro/image'));
39
+ $this->keepTransparency(true);
40
+ $this->_getModel()->setBackgroundColor($this->getStoreBackgroundColor());
41
+ $this->setImageFile($imageFile);
42
+ return $this;
43
+ }
44
+
45
+ /**
46
+ * Schedule resize of the image
47
+ * $width *or* $height can be null - in this case, lacking dimension will be calculated.
48
+ *
49
+ * @see Mage_Catalog_Model_Product_Image
50
+ * @param int $width
51
+ * @param int $height
52
+ * @return Perception_Bannerpro_Helper_Image
53
+ */
54
+ public function resize($width, $height = null, $background = true)
55
+ {
56
+ $this->_getModel()->setWidth($width)->setHeight($height);
57
+ $this->_scheduleResize = true;
58
+ $this->set_background_color = $background;
59
+ return $this;
60
+ }
61
+
62
+
63
+ /**
64
+ * Guarantee, that image picture width/height will not be distorted.
65
+ * Applicable before calling resize()
66
+ * It is true by default.
67
+ *
68
+ * @see Mage_Catalog_Model_Product_Image
69
+ * @param bool $flag
70
+ * @return Perception_Bannerpro_Helper_Image
71
+ */
72
+ public function keepAspectRatio($flag)
73
+ {
74
+ $this->_getModel()->setKeepAspectRatio($flag);
75
+ return $this;
76
+ }
77
+
78
+ /**
79
+ * Guarantee, that image will have dimensions, set in $width/$height
80
+ * Applicable before calling resize()
81
+ * Not applicable, if keepAspectRatio(false)
82
+ *
83
+ * $position - TODO, not used for now - picture position inside the frame.
84
+ *
85
+ * @see Mage_Catalog_Model_Product_Image
86
+ * @param bool $flag
87
+ * @param array $position
88
+ * @return Perception_Bannerpro_Helper_Image
89
+ */
90
+ public function keepFrame($flag, $position = array('center', 'middle'))
91
+ {
92
+ $this->_getModel()->setKeepFrame($flag);
93
+ return $this;
94
+ }
95
+
96
+ /**
97
+ * Guarantee, that image will not lose transparency if any.
98
+ * Applicable before calling resize()
99
+ * It is true by default.
100
+ *
101
+ * $alphaOpacity - TODO, not used for now
102
+ *
103
+ * @see Mage_Catalog_Model_Product_Image
104
+ * @param bool $flag
105
+ * @param int $alphaOpacity
106
+ * @return Perception_Bannerpro_Helper_Image
107
+ */
108
+ public function keepTransparency($flag, $alphaOpacity = null)
109
+ {
110
+ $this->_getModel()->setKeepTransparency($flag);
111
+ return $this;
112
+ }
113
+
114
+ /**
115
+ * Guarantee, that image picture will not be bigger, than it was.
116
+ * Applicable before calling resize()
117
+ * It is false by default
118
+ *
119
+ * @param bool $flag
120
+ * @return Perception_Bannerpro_Helper_Image
121
+ */
122
+ public function constrainOnly($flag)
123
+ {
124
+ $this->_getModel()->setConstrainOnly($flag);
125
+ return $this;
126
+ }
127
+
128
+ /**
129
+ * Set color to fill image frame with.
130
+ * Applicable before calling resize()
131
+ * The keepTransparency(true) overrides this (if image has transparent color)
132
+ * It is white by default.
133
+ *
134
+ * @param array $colorRGB
135
+ * @return Perception_Bannerpro_Helper_Image
136
+ */
137
+ public function backgroundColor($colorRGB)
138
+ {
139
+ // assume that 3 params were given instead of array
140
+ if (!is_array($colorRGB)) {
141
+ $colorRGB = func_get_args();
142
+ }
143
+ $this->_getModel()->setBackgroundColor($colorRGB);
144
+ return $this;
145
+ }
146
+
147
+ public function rotate($angle)
148
+ {
149
+ $this->setAngle($angle);
150
+ $this->_getModel()->setAngle($angle);
151
+ $this->_scheduleRotate = true;
152
+ return $this;
153
+ }
154
+
155
+ public function watermark($fileName, $position, $size=null)
156
+ {
157
+ $this->setWatermark($fileName)
158
+ ->setWatermarkPosition($position)
159
+ ->setWatermarkSize($size);
160
+ $this->_scheduleWatermark = true;
161
+ return $this;
162
+ }
163
+
164
+ public function placeholder($fileName)
165
+ {
166
+ $this->_placeholder = $fileName;
167
+ }
168
+
169
+ public function getPlaceholder()
170
+ {
171
+ if (!$this->_placeholder) {
172
+ $attr = $this->_getModel()->getDestinationSubdir();
173
+ $this->_placeholder = 'images/catalog/product/placeholder/'.$attr.'.jpg';
174
+ }
175
+ return $this->_placeholder;
176
+ }
177
+
178
+ public function __toString()
179
+ {
180
+ try {
181
+ if( $this->getImageFile() ) {
182
+ $this->_getModel()->setBaseFile( $this->getImageFile() );
183
+ }
184
+
185
+ if(!$this->set_background_color || $this->_view_mode=='detail'?!strlen(Mage::getStoreConfig('bannerpro/info/photo_background_color')):!strlen(Mage::getStoreConfig('bannerpro/info/simple_photo_background_color'))){
186
+ $info = getimagesize($this->_getModel()->getBaseFile());
187
+
188
+ $oldWidth = $info[0];
189
+ $oldHeight = $info[1];
190
+ $newWidth = $this->_getModel()->getWidth();
191
+ $newHeight = $this->_getModel()->getHeight();
192
+
193
+ if($oldWidth*1.0/$newWidth < $oldHeight*1.0/$newHeight) $newWidth = 1.0*$oldWidth * $newHeight/$oldHeight;
194
+ else $newHeight = 1.0*$oldHeight * $newWidth/$oldWidth;
195
+
196
+ $this->_getModel()->setWidth($newWidth);
197
+ $this->_getModel()->setHeight($newHeight);
198
+ }
199
+
200
+ if( $this->_getModel()->isCached() ) {
201
+ return $this->_getModel()->getUrl();
202
+ } else {
203
+ if( $this->_scheduleRotate ) {
204
+ $this->_getModel()->rotate( $this->getAngle() );
205
+ }
206
+
207
+ if ($this->_scheduleResize) {
208
+ $this->_getModel()->resize();
209
+ }
210
+
211
+ if( $this->_scheduleWatermark ) {
212
+ $this->_getModel()
213
+ ->setWatermarkPosition( $this->getWatermarkPosition() )
214
+ ->setWatermarkSize($this->parseSize($this->getWatermarkSize()))
215
+ ->setWatermark($this->getWatermark(), $this->getWatermarkPosition());
216
+ } else {
217
+ if( $watermark = Mage::getStoreConfig("design/watermark/{$this->_getModel()->getDestinationSubdir()}_image") ) {
218
+ $this->_getModel()
219
+ ->setWatermarkPosition( $this->getWatermarkPosition() )
220
+ ->setWatermarkSize($this->parseSize($this->getWatermarkSize()))
221
+ ->setWatermark($watermark, $this->getWatermarkPosition());
222
+ }
223
+ }
224
+ $url = $this->_getModel()->saveFile()->getUrl();
225
+ }
226
+ } catch( Exception $e ) {
227
+ //Mage::log($e);
228
+ $url = Mage::getDesign()->getSkinUrl($this->getPlaceholder());
229
+ }
230
+ return $url;
231
+ }
232
+
233
+ /**
234
+ * Enter description here...
235
+ *
236
+ * @return Perception_Bannerpro_Helper_Image
237
+ */
238
+ protected function _setModel($model)
239
+ {
240
+ $this->_model = $model;
241
+ return $this;
242
+ }
243
+
244
+ /**
245
+ * Enter description here...
246
+ *
247
+ * @return Mage_Catalog_Model_Product_Image
248
+ */
249
+ protected function _getModel()
250
+ {
251
+ return $this->_model;
252
+ }
253
+
254
+ protected function setAngle($angle)
255
+ {
256
+ $this->_angle = $angle;
257
+ return $this;
258
+ }
259
+
260
+ protected function getAngle()
261
+ {
262
+ return $this->_angle;
263
+ }
264
+
265
+ protected function setWatermark($watermark)
266
+ {
267
+ $this->_watermark = $watermark;
268
+ return $this;
269
+ }
270
+
271
+ protected function getWatermark()
272
+ {
273
+ return $this->_watermark;
274
+ }
275
+
276
+ protected function setWatermarkPosition($position)
277
+ {
278
+ $this->_watermarkPosition = $position;
279
+ return $this;
280
+ }
281
+
282
+ protected function getWatermarkPosition()
283
+ {
284
+ if( $this->_watermarkPosition ) {
285
+ return $this->_watermarkPosition;
286
+ } else {
287
+ return Mage::getStoreConfig("design/watermark/{$this->_getModel()->getDestinationSubdir()}_position");
288
+ }
289
+ }
290
+
291
+ public function setWatermarkSize($size)
292
+ {
293
+ $this->_watermarkSize = $size;
294
+ return $this;
295
+ }
296
+
297
+ protected function getWatermarkSize()
298
+ {
299
+ if( $this->_watermarkSize ) {
300
+ return $this->_watermarkSize;
301
+ } else {
302
+ return Mage::getStoreConfig("design/watermark/{$this->_getModel()->getDestinationSubdir()}_size");
303
+ }
304
+ }
305
+
306
+ protected function setImageFile($file)
307
+ {
308
+ $this->_imageFile = $file;
309
+ return $this;
310
+ }
311
+
312
+ protected function getImageFile()
313
+ {
314
+ return $this->_imageFile;
315
+ }
316
+
317
+ /**
318
+ * Enter description here...
319
+ *
320
+ * @return array
321
+ */
322
+ protected function parseSize($string)
323
+ {
324
+ $size = explode('x', strtolower($string));
325
+ if( sizeof($size) == 2 ) {
326
+ return array(
327
+ 'width' => ($size[0] > 0) ? $size[0] : null,
328
+ 'heigth' => ($size[1] > 0) ? $size[1] : null,
329
+ );
330
+ }
331
+ return false;
332
+ }
333
+ public function getStoreBackgroundColor()
334
+ {
335
+ $color = $this->_view_mode=="detail"?explode(',',Mage::getStoreConfig('bannerpro/info/photo_background_color')):explode(',',Mage::getStoreConfig('bannerpro/info/simple_photo_background_color'));
336
+ if(sizeof($color)==3)
337
+ {
338
+ foreach($color as $item){
339
+ if(!is_numeric($item) || $item >255) return array(192, 192, 192);
340
+ }
341
+ return array((int)$color[0], (int)$color[1], (int)$color[2]);
342
+ }
343
+ return array(192, 192, 192);
344
+ }
345
+ }
app/code/local/Perception/Bannerpro/Helper/Wysiwyg/Images.php ADDED
@@ -0,0 +1,41 @@
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_Cms
23
+ * @copyright Copyright (c) 2010 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
+ * Wysiwyg Images Helper
28
+ */
29
+ class Perception_Bannerpro_Helper_Wysiwyg_Images extends Mage_Cms_Helper_Wysiwyg_Images
30
+ {
31
+ /**
32
+ * Retrieve Template processor for Page Content
33
+ *
34
+ * @return Varien_Filter_Template
35
+ */
36
+ public function getPageTemplateProcessor()
37
+ {
38
+ $model = (string)Mage::getConfig()->getNode('global/cms/page/tempate_filter');
39
+ return Mage::getModel($model);
40
+ }
41
+ }
app/code/local/Perception/Bannerpro/Model/Bannerpro.php ADDED
@@ -0,0 +1,10 @@
1
+ <?php
2
+
3
+ class Perception_Bannerpro_Model_Bannerpro extends Mage_Core_Model_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ parent::_construct();
8
+ $this->_init('bannerpro/bannerpro');
9
+ }
10
+ }
app/code/local/Perception/Bannerpro/Model/Entity/Attribute/Source/Boolean/Config.php ADDED
@@ -0,0 +1,42 @@
1
+ <?php
2
+
3
+ /**
4
+ * aheadWorks Co.
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the EULA
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://ecommerce.aheadworks.com/LICENSE-M1.txt
12
+ *
13
+ * @category AW
14
+ * @package AW_Featuredproducts
15
+ * @copyright Copyright (c) 2008-2009 aheadWorks Co. (http://www.aheadworks.com)
16
+ * @license http://ecommerce.aheadworks.com/LICENSE-M1.txt
17
+ */
18
+
19
+ class Magestore_Bannerpro_Model_Entity_Attribute_Source_Boolean_Config extends Mage_Eav_Model_Entity_Attribute_Source_Boolean
20
+ {
21
+ /**
22
+ * Retrive all attribute options
23
+ *
24
+ * @return array
25
+ */
26
+ public function getAllOptions()
27
+ {
28
+ if (!$this->_options) {
29
+ $this->_options = array(
30
+ array(
31
+ 'label' => Mage::helper('bannerpro')->__('No'),
32
+ 'value' => 0
33
+ ),
34
+ array(
35
+ 'label' => Mage::helper('bannerpro')->__('Yes'),
36
+ 'value' => 1
37
+ )
38
+ );
39
+ }
40
+ return $this->_options;
41
+ }
42
+ }
app/code/local/Perception/Bannerpro/Model/Image.php ADDED
@@ -0,0 +1,508 @@
1
+ <?php
2
+ class Perception_Bannerpro_Model_Image extends Mage_Core_Model_Abstract
3
+ {
4
+ protected $_width;
5
+ protected $_height;
6
+
7
+ protected $_keepAspectRatio = true;
8
+ protected $_keepFrame = true;
9
+ protected $_keepTransparency = true;
10
+ protected $_constrainOnly = false;
11
+ protected $_backgroundColor = array(192, 192, 192);
12
+
13
+ protected $_baseFile;
14
+ protected $_newFile;
15
+ protected $_baseDir;
16
+ protected $_processor;
17
+ protected $_destinationSubdir;
18
+ protected $_angle;
19
+ protected $_watermarkPosition;
20
+ protected $_watermarkWidth;
21
+ protected $_watermarkHeigth;
22
+
23
+ /**
24
+ * @return Perception_Bannerpro_Model_Image
25
+ */
26
+ public function setWidth($width)
27
+ {
28
+ $this->_width = $width;
29
+ return $this;
30
+ }
31
+
32
+ public function getWidth()
33
+ {
34
+ return $this->_width;
35
+ }
36
+
37
+ /**
38
+ * @return Perception_Bannerpro_Model_Image
39
+ */
40
+ public function setHeight($height)
41
+ {
42
+ $this->_height = $height;
43
+ return $this;
44
+ }
45
+
46
+ public function getHeight()
47
+ {
48
+ return $this->_height;
49
+ }
50
+
51
+ /**
52
+ * @return Perception_Bannerpro_Model_Image
53
+ */
54
+ public function setKeepAspectRatio($keep)
55
+ {
56
+ $this->_keepAspectRatio = (bool)$keep;
57
+ return $this;
58
+ }
59
+
60
+ /**
61
+ * @return Perception_Bannerpro_Model_Image
62
+ */
63
+ public function setKeepFrame($keep)
64
+ {
65
+ $this->_keepFrame = (bool)$keep;
66
+ return $this;
67
+ }
68
+
69
+ /**
70
+ * @return Perception_Bannerpro_Model_Image
71
+ */
72
+ public function setKeepTransparency($keep)
73
+ {
74
+ $this->_keepTransparency = (bool)$keep;
75
+ return $this;
76
+ }
77
+
78
+ /**
79
+ * @return Perception_Bannerpro_Model_Image
80
+ */
81
+ public function setConstrainOnly($flag)
82
+ {
83
+ $this->_constrainOnly = (bool)$flag;
84
+ return $this;
85
+ }
86
+
87
+ /**
88
+ * @return Perception_Bannerpro_Model_Image
89
+ */
90
+ public function setBackgroundColor(array $rgbArray)
91
+ {
92
+ $this->_backgroundColor = $rgbArray;
93
+ return $this;
94
+ }
95
+
96
+ /**
97
+ * @return Perception_Bannerpro_Model_Image
98
+ */
99
+ public function setSize($size)
100
+ {
101
+ // determine width and height from string
102
+ list($width, $height) = explode('x', strtolower($size), 2);
103
+ foreach (array('width', 'height') as $wh) {
104
+ $wh = (int)$wh;
105
+ if (empty($wh))
106
+ $wh = null;
107
+ }
108
+
109
+ // set sizes
110
+ $this->setWidth($width)->setHeight($height);
111
+
112
+ return $this;
113
+ }
114
+
115
+ protected function _checkMemory($file = null)
116
+ {
117
+ // print '$this->_getMemoryLimit() = '.$this->_getMemoryLimit();
118
+ // print '$this->_getMemoryUsage() = '.$this->_getMemoryUsage();
119
+ // print '$this->_getNeedMemoryForBaseFile() = '.$this->_getNeedMemoryForBaseFile();
120
+
121
+ return $this->_getMemoryLimit() > ($this->_getMemoryUsage() + $this->_getNeedMemoryForFile($file));
122
+ }
123
+
124
+ protected function _getMemoryLimit()
125
+ {
126
+ $memoryLimit = ini_get('memory_limit');
127
+
128
+ if (!isSet($memoryLimit[0])){
129
+ $memoryLimit = "128M";
130
+ }
131
+
132
+ if (substr($memoryLimit, -1) == 'M') {
133
+ return (int)$memoryLimit * 1024 * 1024;
134
+ }
135
+ return $memoryLimit;
136
+ }
137
+
138
+ protected function _getMemoryUsage()
139
+ {
140
+ if (function_exists('memory_get_usage')) {
141
+ return memory_get_usage();
142
+ }
143
+ return 0;
144
+ }
145
+
146
+ protected function _getNeedMemoryForFile($file = null)
147
+ {
148
+ $file = is_null($file) ? $this->getBaseFile() : $file;
149
+ if (!$file) {
150
+ return 0;
151
+ }
152
+
153
+ if (!file_exists($file) || !is_file($file)) {
154
+ return 0;
155
+ }
156
+
157
+ $imageInfo = getimagesize($file);
158
+
159
+ if (!isset($imageInfo['channels'])) {
160
+ // if there is no info about this parameter lets set it for maximum
161
+ $imageInfo['channels'] = 4;
162
+ }
163
+ if (!isset($imageInfo['bits'])) {
164
+ // if there is no info about this parameter lets set it for maximum
165
+ $imageInfo['bits'] = 8;
166
+ }
167
+ return round(($imageInfo[0] * $imageInfo[1] * $imageInfo['bits'] * $imageInfo['channels'] / 8 + Pow(2, 16)) * 1.65);
168
+ }
169
+
170
+ /**
171
+ * Convert array of 3 items (decimal r, g, b) to string of their hex values
172
+ *
173
+ * @param array $rgbArray
174
+ * @return string
175
+ */
176
+ private function _rgbToString($rgbArray)
177
+ {
178
+ $result = array();
179
+ foreach ($rgbArray as $value) {
180
+ if (null === $value) {
181
+ $result[] = 'null';
182
+ }
183
+ else {
184
+ $result[] = sprintf('%02s', dechex($value));
185
+ }
186
+ }
187
+ return implode($result);
188
+ }
189
+
190
+ /**
191
+ * Set filenames for base file and new file
192
+ *
193
+ * @param string $file
194
+ * @return Perception_Bannerpro_Model_Image
195
+ */
196
+ public function setBaseFile($file)
197
+ {
198
+ $subDir = '';
199
+
200
+ if ($file) {
201
+ if (0 !== strpos($file, '/', 0)) {
202
+ $file = '/' . $file;
203
+ }
204
+
205
+ $pos = strripos($file, '/');
206
+ if ($pos!==false && $pos!==0) {
207
+ $subDir = substr($file, 0, $pos);
208
+ $file = substr($file, $pos);
209
+ }
210
+ }
211
+ //$baseDir = Mage::getSingleton('catalog/product_media_config')->getBaseMediaPath();
212
+ $baseDir = Mage::getBaseDir('media') . $subDir;
213
+ $this->_baseDir = Mage::getBaseDir('media') . DS;
214
+
215
+ if ('/no_selection' == $file) {
216
+ $file = null;
217
+ }
218
+ if ($file) {
219
+ if ((!file_exists($baseDir . $file)) || !$this->_checkMemory($baseDir . $file)) {
220
+ $file = null;
221
+ }
222
+ }
223
+
224
+ /*
225
+ if (!$file) {
226
+ // check if placeholder defined in config
227
+ $isConfigPlaceholder = Mage::getStoreConfig("catalog/placeholder/{$this->getDestinationSubdir()}_placeholder");
228
+ $configPlaceholder = '/placeholder/' . $isConfigPlaceholder;
229
+ if ($isConfigPlaceholder && file_exists($baseDir . $configPlaceholder)) {
230
+ $file = $configPlaceholder;
231
+ }
232
+ else {
233
+ // replace file with skin or default skin placeholder
234
+ $skinBaseDir = Mage::getDesign()->getSkinBaseDir();
235
+ $skinPlaceholder = "/images/catalog/product/placeholder/{$this->getDestinationSubdir()}.jpg";
236
+ $file = $skinPlaceholder;
237
+ if (file_exists($skinBaseDir . $file)) {
238
+ $baseDir = $skinBaseDir;
239
+ }
240
+ else {
241
+ $baseDir = Mage::getDesign()->getSkinBaseDir(array('_theme' => 'default'));
242
+ }
243
+ }
244
+ }
245
+ */
246
+
247
+ $baseFile = $baseDir . $file;
248
+
249
+ if ((!$file) || (!file_exists($baseFile))) {
250
+ throw new Exception(Mage::helper('catalog')->__('Image file not found'));
251
+ }
252
+ $this->_baseFile = $baseFile;
253
+
254
+ // build new filename (most important params)
255
+ $path = array(
256
+ 'bannerpro',
257
+ 'cache'
258
+ );
259
+ if((!empty($this->_width)) || (!empty($this->_height)))
260
+ $path[] = "{$this->_width}x{$this->_height}";
261
+ // add misc params as a hash
262
+ $path[] = md5(
263
+ implode('_', array(
264
+ ($this->_keepAspectRatio ? '' : 'non') . 'proportional',
265
+ ($this->_keepFrame ? '' : 'no') . 'frame',
266
+ ($this->_keepTransparency ? '' : 'no') . 'transparency',
267
+ ($this->_constrainOnly ? 'do' : 'not') . 'constrainonly',
268
+ $this->_rgbToString($this->_backgroundColor),
269
+ 'angle' . $this->_angle
270
+ ))
271
+ );
272
+ // append prepared filename
273
+ $this->_newFile = implode('/', $path) . $file; // the $file contains heading slash
274
+
275
+ return $this;
276
+ }
277
+
278
+ public function getBaseFile()
279
+ {
280
+ return $this->_baseFile;
281
+ }
282
+
283
+ public function getBaseDir()
284
+ {
285
+ return $this->_baseDir;
286
+ }
287
+
288
+ public function getNewFile()
289
+ {
290
+ return $this->_newFile;
291
+ }
292
+
293
+ /**
294
+ * @return Perception_Bannerpro_Model_Image
295
+ */
296
+ public function setImageProcessor($processor)
297
+ {
298
+ $this->_processor = $processor;
299
+ return $this;
300
+ }
301
+
302
+ /**
303
+ * @return Varien_Image
304
+ */
305
+ public function getImageProcessor()
306
+ {
307
+ if( !$this->_processor ) {
308
+ // var_dump($this->_checkMemory());
309
+ // if (!$this->_checkMemory()) {
310
+ // $this->_baseFile = null;
311
+ // }
312
+ $this->_processor = new Varien_Image($this->getBaseFile());
313
+ }
314
+ $this->_processor->keepAspectRatio($this->_keepAspectRatio);
315
+ $this->_processor->keepFrame($this->_keepFrame);
316
+ $this->_processor->keepTransparency($this->_keepTransparency);
317
+ $this->_processor->constrainOnly($this->_constrainOnly);
318
+ $this->_processor->backgroundColor($this->_backgroundColor);
319
+ return $this->_processor;
320
+ }
321
+
322
+ public function getKeepTransparency()
323
+ {
324
+ return $this->_keepTransparency;
325
+ }
326
+ /**
327
+ * @see Varien_Image_Adapter_Abstract
328
+ * @return Perception_Bannerpro_Model_Image
329
+ */
330
+ public function resize()
331
+ {
332
+ if (is_null($this->getWidth()) && is_null($this->getHeight())) {
333
+ return $this;
334
+ }
335
+ $this->getImageProcessor()->resize($this->_width, $this->_height);
336
+ return $this;
337
+ }
338
+
339
+ /**
340
+ * @return Perception_Bannerpro_Model_Image
341
+ */
342
+ public function rotate($angle)
343
+ {
344
+ $angle = intval($angle);
345
+ $this->getImageProcessor()->rotate($angle);
346
+ return $this;
347
+ }
348
+
349
+ /**
350
+ * Set angle for rotating
351
+ *
352
+ * This func actually affects only the cache filename.
353
+ *
354
+ * @param int $angle
355
+ * @return Perception_Bannerpro_Model_Image
356
+ */
357
+ public function setAngle($angle)
358
+ {
359
+ $this->_angle = $angle;
360
+ return $this;
361
+ }
362
+
363
+ /**
364
+ * @return Perception_Bannerpro_Model_Image
365
+ */
366
+ public function setWatermark($file, $position=null, $size=null, $width=null, $heigth=null)
367
+ {
368
+ $filename = false;
369
+
370
+ if( !$file ) {
371
+ return $this;
372
+ }
373
+
374
+ $baseDir = Mage::getSingleton('catalog/product_media_config')->getBaseMediaPath();
375
+
376
+ if( file_exists($baseDir . '/watermark/stores/' . Mage::app()->getStore()->getId() . $file) ) {
377
+ $filename = $baseDir . '/watermark/stores/' . Mage::app()->getStore()->getId() . $file;
378
+ } elseif ( file_exists($baseDir . '/watermark/websites/' . Mage::app()->getWebsite()->getId() . $file) ) {
379
+ $filename = $baseDir . '/watermark/websites/' . Mage::app()->getWebsite()->getId() . $file;
380
+ } elseif ( file_exists($baseDir . '/watermark/default/' . $file) ) {
381
+ $filename = $baseDir . '/watermark/default/' . $file;
382
+ } elseif ( file_exists($baseDir . '/watermark/' . $file) ) {
383
+ $filename = $baseDir . '/watermark/' . $file;
384
+ } else {
385
+ $baseDir = Mage::getDesign()->getSkinBaseDir();
386
+ if( file_exists($baseDir . $file) ) {
387
+ $filename = $baseDir . $file;
388
+ }
389
+ }
390
+
391
+ if( $filename ) {
392
+ $this->getImageProcessor()
393
+ ->setWatermarkPosition( ($position) ? $position : $this->getWatermarkPosition() )
394
+ ->setWatermarkWidth( ($width) ? $width : $this->getWatermarkWidth() )
395
+ ->setWatermarkHeigth( ($heigth) ? $heigth : $this->getWatermarkHeigth() )
396
+ ->watermark($filename);
397
+ }
398
+
399
+ return $this;
400
+ }
401
+
402
+ /**
403
+ * @return Perception_Bannerpro_Model_Image
404
+ */
405
+ public function saveFile()
406
+ {
407
+ $this->getImageProcessor()->save($this->getBaseDir().$this->getNewFile());
408
+ return $this;
409
+ }
410
+
411
+ /**
412
+ * @return string
413
+ */
414
+ public function getUrl()
415
+ {
416
+ $baseDir = Mage::getBaseDir('media');
417
+ $path = str_replace($baseDir . DS, "", $this->_newFile);
418
+ return Mage::getBaseUrl('media') . str_replace(DS, '/', $path);
419
+ }
420
+
421
+ public function push()
422
+ {
423
+ $this->getImageProcessor()->display();
424
+ }
425
+
426
+ /**
427
+ * @return Perception_Bannerpro_Model_Image
428
+ */
429
+ public function setDestinationSubdir($dir)
430
+ {
431
+ $this->_destinationSubdir = $dir;
432
+ return $this;
433
+ }
434
+
435
+ /**
436
+ * @return string
437
+ */
438
+ public function getDestinationSubdir()
439
+ {
440
+ return $this->_destinationSubdir;
441
+ }
442
+
443
+ public function isCached()
444
+ {
445
+ return file_exists($this->getBaseDir().$this->_newFile);
446
+ }
447
+
448
+ /**
449
+ * @return Perception_Bannerpro_Model_Image
450
+ */
451
+ public function setWatermarkPosition($position)
452
+ {
453
+ $this->_watermarkPosition = $position;
454
+ return $this;
455
+ }
456
+
457
+ public function getWatermarkPosition()
458
+ {
459
+ return $this->_watermarkPosition;
460
+ }
461
+
462
+ /**
463
+ * @return Perception_Bannerpro_Model_Image
464
+ */
465
+ public function setWatermarkSize($size)
466
+ {
467
+ if( is_array($size) ) {
468
+ $this->setWatermarkWidth($size['width'])
469
+ ->setWatermarkHeigth($size['heigth']);
470
+ }
471
+ return $this;
472
+ }
473
+
474
+ /**
475
+ * @return Perception_Bannerpro_Model_Image
476
+ */
477
+ public function setWatermarkWidth($width)
478
+ {
479
+ $this->_watermarkWidth = $width;
480
+ return $this;
481
+ }
482
+
483
+ public function getWatermarkWidth()
484
+ {
485
+ return $this->_watermarkWidth;
486
+ }
487
+
488
+ /**
489
+ * @return Perception_Bannerpro_Model_Image
490
+ */
491
+ public function setWatermarkHeigth($heigth)
492
+ {
493
+ $this->_watermarkHeigth = $heigth;
494
+ return $this;
495
+ }
496
+
497
+ public function getWatermarkHeigth()
498
+ {
499
+ return $this->_watermarkHeigth;
500
+ }
501
+
502
+ public function clearCache()
503
+ {
504
+ $directory = Mage::getBaseDir('media') . DS.'bannerpro'.DS.'cache'.DS;
505
+ $io = new Varien_Io_File();
506
+ $io->rmdir($directory, true);
507
+ }
508
+ }
app/code/local/Perception/Bannerpro/Model/Mysql4/Bannerpro.php ADDED
@@ -0,0 +1,158 @@
1
+ <?php
2
+
3
+ class Perception_Bannerpro_Model_Mysql4_Bannerpro extends Mage_Core_Model_Mysql4_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ // Note that the bannerpro_id refers to the key field in your database table.
8
+ $this->_init('bannerpro/bannerpro', 'bannerpro_id');
9
+ }
10
+
11
+ /**
12
+ * Process page data before saving
13
+ *
14
+ * @param Mage_Core_Model_Abstract $object
15
+ */
16
+ protected function _beforeSave(Mage_Core_Model_Abstract $object)
17
+ {
18
+
19
+ if (! $object->getId() && $object->getCreationTime() == "") {
20
+ $object->setCreationTime(Mage::getSingleton('core/date')->gmtDate());
21
+ }
22
+
23
+ $format = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
24
+ if ($date = $object->getData('creation_time')) {
25
+ $object->setData('creation_time', Mage::app()->getLocale()->date($date, $format, null, false)
26
+ ->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)
27
+ );
28
+ }
29
+ $object->setUpdateTime(Mage::getSingleton('core/date')->gmtDate());
30
+
31
+ return $this;
32
+ }
33
+
34
+ /**
35
+ *
36
+ * @param Mage_Core_Model_Abstract $object
37
+ */
38
+ protected function _afterLoad(Mage_Core_Model_Abstract $object)
39
+ {
40
+ $select = $this->_getReadAdapter()->select()
41
+ ->from($this->getTable('bannerpro_store'))
42
+ ->where('bannerpro_id = ?', $object->getId());
43
+
44
+ if ($data = $this->_getReadAdapter()->fetchAll($select)) {
45
+ $storesArray = array();
46
+ foreach ($data as $row) {
47
+ $storesArray[] = $row['store_id'];
48
+ }
49
+ $object->setData('store_id', $storesArray);
50
+ }
51
+
52
+ return parent::_afterLoad($object);
53
+ }
54
+
55
+ /**
56
+ * Assign page to store views
57
+ *
58
+ * @param Mage_Core_Model_Abstract $object
59
+ */
60
+ protected function _afterSave(Mage_Core_Model_Abstract $object)
61
+ {
62
+ $condition = $this->_getWriteAdapter()->quoteInto('bannerpro_id = ?', $object->getId());
63
+ $this->_getWriteAdapter()->delete($this->getTable('bannerpro_store'), $condition);
64
+
65
+ foreach ((array)$object->getData('stores') as $store) {
66
+ $storeArray = array();
67
+ $storeArray['bannerpro_id'] = $object->getId();
68
+ $storeArray['store_id'] = $store;
69
+ $this->_getWriteAdapter()->insert($this->getTable('bannerpro_store'), $storeArray);
70
+ }
71
+
72
+ return parent::_afterSave($object);
73
+ }
74
+
75
+ /**
76
+ * Retrieve select object for load object data
77
+ *
78
+ * @param string $field
79
+ * @param mixed $value
80
+ * @return Zend_Db_Select
81
+ */
82
+ protected function _getLoadSelect($field, $value, $object)
83
+ {
84
+ $select = parent::_getLoadSelect($field, $value, $object);
85
+
86
+ if ($object->getStoreId()) {
87
+ $select->join(
88
+ array('bannerpro' => $this->getTable('bannerpro_store')),
89
+ $this->getMainTable().'.bannerpro_id = `bannerpro`.bannerpro_id'
90
+ )
91
+ ->where('is_active=1 AND `bannerpro`.store_id in (' . Mage_Core_Model_App::ADMIN_STORE_ID . ', ?) ', $object->getStoreId())
92
+ ->order('store_id DESC')
93
+ ->limit(1);
94
+ }
95
+ return $select;
96
+ }
97
+
98
+ /**
99
+ * Check if page identifier exist for specific store
100
+ * return page id if page exists
101
+ *
102
+ * @param string $identifier
103
+ * @param int $storeId
104
+ * @return int
105
+ */
106
+ public function checkIdentifier($bannerpro_id, $storeId)
107
+ {
108
+ $select = $this->_getReadAdapter()->select()->from(array('main_table'=>$this->getMainTable()), 'bannerpro_id')
109
+ ->join(
110
+ array('bannerpro' => $this->getTable('bannerpro_store')),
111
+ 'main_table.bannerpro_id = `bannerpro`.bannerpro_id'
112
+ )
113
+ ->where('main_table.bannerpro_id=?', $bannerpro_id)
114
+ ->where('main_table.is_active=1 AND `bannerpro`.store_id in (' . Mage_Core_Model_App::ADMIN_STORE_ID . ', ?) ', $storeId)
115
+ ->order('store_id DESC');
116
+
117
+ return $this->_getReadAdapter()->fetchOne($select);
118
+ }
119
+
120
+ /**
121
+ * Get store ids to which specified item is assigned
122
+ *
123
+ * @param int $id
124
+ * @return array
125
+
126
+ */
127
+ public function lookupStoreIds($id)
128
+ {
129
+ return $this->_getReadAdapter()->fetchCol($this->_getReadAdapter()->select()
130
+ ->from($this->getTable('bannerpro_store'), 'store_id')
131
+ ->where("{$this->getIdFieldName()} = ?", $id)
132
+ );
133
+ }
134
+
135
+ /**
136
+ * Set store model
137
+ *
138
+ * @param Mage_Core_Model_Store $store
139
+ * @return Mage_Cms_Model_Mysql4_Page
140
+ */
141
+ public function setStore($store)
142
+ {
143
+ $this->_store = $store;
144
+ return $this;
145
+ }
146
+
147
+ /**
148
+ * Retrieve store model
149
+ *
150
+ * @return Mage_Core_Model_Store
151
+ */
152
+ public function getStore()
153
+ {
154
+ return Mage::app()->getStore($this->_store);
155
+ }
156
+
157
+
158
+ }
app/code/local/Perception/Bannerpro/Model/Mysql4/Bannerpro/Collection.php ADDED
@@ -0,0 +1,123 @@
1
+ <?php
2
+
3
+ class Perception_Bannerpro_Model_Mysql4_Bannerpro_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
4
+ {
5
+ protected $_previewFlag;
6
+
7
+ public function _construct()
8
+ {
9
+ parent::_construct();
10
+ $this->_init('bannerpro/bannerpro');
11
+ $this->_map['fields']['bannerpro_id'] = 'main_table.bannerpro_id';
12
+ }
13
+
14
+ public function setFirstStoreFlag($flag = false)
15
+ {
16
+ $this->_previewFlag = $flag;
17
+ return $this;
18
+ }
19
+
20
+ protected function _afterLoad()
21
+ {
22
+ if ($this->_previewFlag) {
23
+ $items = $this->getColumnValues('bannerpro_id');
24
+
25
+ if (count($items)) {
26
+ $select = $this->getConnection()->select()
27
+ ->from($this->getTable('bannerpro_store'))
28
+ ->where($this->getTable('bannerpro_store').'.bannerpro_id IN (?)', $items);
29
+
30
+ if ($result = $this->getConnection()->fetchPairs($select)) {
31
+
32
+ foreach ($this as $item) {
33
+
34
+ if (!isset($result[$item->getData('bannerpro_id')])) {
35
+ continue;
36
+ }
37
+
38
+ if ($result[$item->getData('bannerpro_id')] == 0) {
39
+ $stores = Mage::app()->getStores(false, true);
40
+ $storeId = current($stores)->getId();
41
+ $storeCode = key($stores);
42
+ } else {
43
+ $storeId = $result[$item->getData('bannerpro_id')];
44
+ $storeCode = Mage::app()->getStore($storeId)->getCode();
45
+ }
46
+
47
+ $item->setData('_first_store_id', $storeId);
48
+ $item->setData('store_code', $storeCode);
49
+ }
50
+ }
51
+
52
+ }
53
+ }
54
+
55
+ parent::_afterLoad();
56
+ }
57
+
58
+ /**
59
+ * Add Filter by store
60
+ *
61
+ * @param int|Mage_Core_Model_Store $store
62
+ * @return Mage_Cms_Model_Mysql4_Page_Collection
63
+ */
64
+
65
+ public function addStoreFilter($store, $withAdmin = true)
66
+ {
67
+ if (!$this->getFlag('store_filter_added')) {
68
+
69
+ if ($store instanceof Mage_Core_Model_Store) {
70
+ $store = array($store->getId());
71
+ }
72
+
73
+ $this->getSelect()->join(
74
+ array('store_table' => $this->getTable('bannerpro_store')),
75
+ 'main_table.bannerpro_id = store_table.bannerpro_id',
76
+ array()
77
+ )->where('store_table.store_id in (?)', ($withAdmin ? array(0, $store) : $store))
78
+ ->group('main_table.bannerpro_id');
79
+
80
+ $this->setFlag('store_filter_added', true);
81
+ }
82
+
83
+ return $this;
84
+ }
85
+
86
+ public function prepareSummary()
87
+ {
88
+ $this->setConnection($this->getResource()->getReadConnection());
89
+ $this->getSelect()
90
+ ->from(array('main_table'=>'bannerpro'),'*')
91
+ ->where('status = ?', 1)
92
+ ->order('date','asc');
93
+ return $this;
94
+ }
95
+
96
+ public function getDetalle($bannerpro_id)
97
+ {
98
+ $this->setConnection($this->getResource()->getReadConnection());
99
+ $this->getSelect()
100
+ ->from(array('main_table'=>'bannerpro'),'*')
101
+ ->where('bannerpro_id = ?', $bannerpro_id);
102
+ return $this;
103
+ }
104
+
105
+ public function getbannerpro()
106
+ {
107
+ $this->setConnection($this->getResource()->getReadConnection());
108
+ $this->getSelect()
109
+ ->from(array('main_table'=>'bannerpro'),'*')
110
+ ->where('status = ?', 1)
111
+ ->order('date DESC')
112
+ ->limit(5);
113
+ return $this;
114
+ }
115
+
116
+ public function prepareResult($word)
117
+ {
118
+ $sql = "SELECT title,text FROM bannerpro where title like '%$word%' OR text like '%$word%'";
119
+ $data = Mage::getSingleton('core/resource')->getConnection('core_read')->fetchAll($sql);
120
+ return $data;
121
+ }
122
+
123
+ }
app/code/local/Perception/Bannerpro/Model/Status.php ADDED