Zitec_Site_Branding - Version 0.1.0

Version Notes

This is the first stable release of the official Zitec Site Branding extension for Magento. It should work for all versions from Magento 1.7 upwards.

Download this release

Release Info

Developer Alexandru Enciu
Extension Zitec_Site_Branding
Version 0.1.0
Comparing to
See all releases


Version 0.1.0

app/code/community/Zitec/Branding/Block/Adminhtml/Branding.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Zitec_Branding_Block_Adminhtml_Branding extends Mage_Adminhtml_Block_Widget_Grid_Container
4
+ {
5
+
6
+ public function __construct()
7
+ {
8
+ $this->_controller = 'adminhtml_branding';
9
+ $this->_blockGroup = 'zitec_branding';
10
+ $this->_headerText = Mage::helper('zitec_branding')->__('Manage Branding');
11
+ $this->_addButtonLabel = Mage::helper('zitec_branding')->__('Add New Branding');
12
+
13
+ parent::__construct();
14
+ }
15
+
16
+ }
app/code/community/Zitec/Branding/Block/Adminhtml/Branding/Edit.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Zitec_Branding_Block_Adminhtml_Branding_Edit
3
+ extends Mage_Adminhtml_Block_Widget_Form_Container
4
+ {
5
+ /**
6
+ * Object constructor
7
+ */
8
+ public function __construct()
9
+ {
10
+ $this->_controller = 'adminhtml_branding';
11
+ $this->_blockGroup = 'zitec_branding';
12
+ $this->_headerText = Mage::helper('zitec_branding')->__('Edit Branding');
13
+
14
+ return parent::__construct();
15
+ }
16
+ }
app/code/community/Zitec/Branding/Block/Adminhtml/Branding/Edit/Form.php ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Zitec_Branding_Block_Adminhtml_Branding_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
3
+ {
4
+ /**
5
+ * Constructs the form for branding edit.
6
+ *
7
+ * @return $this
8
+ */
9
+ protected function _prepareForm()
10
+ {
11
+ $model = Mage::registry('current_branding');
12
+
13
+ $form = new Varien_Data_Form(array(
14
+ 'id' => 'edit_form',
15
+ 'action' => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))),
16
+ 'method' => 'post',
17
+ 'enctype' => 'multipart/form-data'
18
+ ));
19
+ $form->setUseContainer(true);
20
+ $fieldset = $form->addFieldset('main', array(
21
+ 'legend'=>Mage::helper('zitec_branding')->__('Branding')
22
+ ));
23
+ if ($model->getId()) {
24
+ $fieldset->addField('entity_id', 'hidden', array(
25
+ 'name' => 'entity_id',
26
+ ));
27
+ }
28
+
29
+ $fieldset->addField('title', 'text', array(
30
+ 'name' => 'title',
31
+ 'label' => Mage::helper('zitec_branding')->__('Branding title'),
32
+ 'required' => true,
33
+ ));
34
+
35
+ $fieldset->addField('status', 'select', array(
36
+ 'label' => Mage::helper('zitec_branding')->__('Status'),
37
+ 'title' => Mage::helper('zitec_branding')->__('Status'),
38
+ 'name' => 'status',
39
+ 'required' => true,
40
+ 'options' => array(
41
+ '1' => Mage::helper('zitec_branding')->__('Active'),
42
+ '0' => Mage::helper('zitec_branding')->__('Inactive'),
43
+ ),
44
+ ));
45
+
46
+ if (Mage::app()->isSingleStoreMode()) {
47
+ $storeId = Mage::app()->getStore(true)->getId();
48
+ $fieldset->addField('store_ids', 'hidden', array(
49
+ 'name' => 'store_ids[]',
50
+ 'value' => $storeId
51
+ ));
52
+ } else {
53
+ $fieldset->addField('store_ids', 'multiselect', array(
54
+ 'name' => 'store_ids[]',
55
+ 'label' => Mage::helper('zitec_branding')->__('Stores'),
56
+ 'title' => Mage::helper('zitec_branding')->__('Stores'),
57
+ 'required' => true,
58
+ 'values' => Mage::helper('zitec_branding/system_store')->storesToOptions(
59
+ Mage::getSingleton('adminhtml/system_store')->getStoresStructure())
60
+ ));
61
+ }
62
+
63
+ $fieldset->addField('image_url', 'image', array(
64
+ 'name' => 'image_url',
65
+ 'label' => Mage::helper('zitec_branding')->__('Branding image'),
66
+ 'required' => true,
67
+ ));
68
+
69
+ $fieldset->addField('url', 'text', array(
70
+ 'name' => 'url',
71
+ 'label' => Mage::helper('zitec_branding')->__('Branding URL'),
72
+ ));
73
+
74
+ $fieldset->addField('start_date', 'date', array(
75
+ 'name' => 'start_date',
76
+ 'label' => Mage::helper('zitec_branding')->__('Branding start date'),
77
+ 'required' => true,
78
+ 'format' => Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT),
79
+ 'image' => Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN) . '/adminhtml/default/default/images/grid-cal.gif',
80
+ ));
81
+
82
+ $fieldset->addField('end_date', 'date', array(
83
+ 'name' => 'end_date',
84
+ 'label' => Mage::helper('zitec_branding')->__('Branding end date'),
85
+ 'required' => true,
86
+ 'format' => Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT),
87
+ 'image' => Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN) . '/adminhtml/default/default/images/grid-cal.gif',
88
+ ));
89
+
90
+ $data = Mage::getSingleton('adminhtml/session')->getBrandingData();
91
+
92
+ if (!$data)
93
+ {
94
+ if ($model->getId())
95
+ {
96
+ $data = $model->getData();
97
+ }
98
+ }
99
+
100
+ if ($data)
101
+ {
102
+ if (Mage::app()->isSingleStoreMode() && isset($data['store_ids']) && is_array($data['store_ids']))
103
+ {
104
+ $data['store_ids'] = reset($data['store_ids']);
105
+ }
106
+ $form->setValues($data);
107
+ Mage::getSingleton('adminhtml/session')->unsetData('branding_data');
108
+ }
109
+
110
+ $this->setForm($form);
111
+
112
+ return parent::_prepareForm();
113
+ }
114
+ }
app/code/community/Zitec/Branding/Block/Adminhtml/Branding/Grid.php ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Zitec_Branding_Block_Adminhtml_Branding_Grid
3
+ extends Mage_Adminhtml_Block_Widget_Grid
4
+ {
5
+ public function __construct()
6
+ {
7
+ parent::__construct();
8
+ $this->setId('brandingGrid');
9
+ $this->setUseAjax(true);
10
+ $this->setDefaultSort('entity_id');
11
+ $this->setSaveParametersInSession(true);
12
+ }
13
+
14
+ /**
15
+ * Prepare grid collection object
16
+ *
17
+ * @return this
18
+ */
19
+ protected function _prepareCollection()
20
+ {
21
+ $collection = Mage::getModel('zitec_branding/branding')->getCollection();
22
+ $collection->addStoresToResult();
23
+ $this->setCollection($collection);
24
+
25
+ return parent::_prepareCollection($collection);
26
+ }
27
+
28
+ /**
29
+ * Prepare grid column
30
+ *
31
+ * @return $this
32
+ */
33
+ public function _prepareColumns()
34
+ {
35
+ $this->addColumn('entity_id', array(
36
+ 'header' => Mage::helper('zitec_branding')->__('ID'),
37
+ 'width' => '50px',
38
+ 'index' => 'entity_id',
39
+ 'type' => 'number',
40
+ ));
41
+
42
+ $this->addColumn('title', array(
43
+ 'header' => Mage::helper('zitec_branding')->__('Title'),
44
+ 'index' => 'title',
45
+ 'type' => 'text',
46
+ ));
47
+
48
+ $this->addColumn('url', array(
49
+ 'header' => Mage::helper('zitec_branding')->__('URL'),
50
+ 'index' => 'url',
51
+ 'type' => 'text',
52
+ ));
53
+
54
+ $this->addColumn('start_date', array(
55
+ 'header' => Mage::helper('zitec_branding')->__('Start date'),
56
+ 'index' => 'start_date',
57
+ 'type' => 'date',
58
+ 'renderer' => 'zitec_branding/adminhtml_widget_grid_column_renderer_date',
59
+ 'use_plain' => TRUE
60
+ ));
61
+
62
+ $this->addColumn('end_date', array(
63
+ 'header' => Mage::helper('zitec_branding')->__('End date'),
64
+ 'index' => 'end_date',
65
+ 'type' => 'date',
66
+ 'renderer' => 'zitec_branding/adminhtml_widget_grid_column_renderer_date',
67
+ 'use_plain' => TRUE
68
+ ));
69
+ $this->addColumn('status', array(
70
+ 'header' => Mage::helper('zitec_branding')->__('Status'),
71
+ 'index' => 'status',
72
+ 'type' => 'options',
73
+ 'options' => array(
74
+ 0 => $this->__('Inactive'),
75
+ 1 => $this->__('Active'),
76
+ )
77
+ ));
78
+
79
+
80
+ $this->addColumn('store_id', array(
81
+ 'header' => Mage::helper('zitec_branding')->__('Store'),
82
+ 'align' => 'center',
83
+ 'width' => '80px',
84
+ 'type' => 'options',
85
+ 'options' => Mage::getSingleton('adminhtml/system_store')->getStoreOptionHash(FALSE),
86
+ 'index' => 'store_ids',
87
+ ));
88
+
89
+ return parent::_prepareColumns();
90
+ }
91
+
92
+ /**
93
+ * Return row url for js event handlers
94
+ *
95
+ * @param Varien_Object
96
+ * @return string
97
+ */
98
+ public function getRowUrl($row)
99
+ {
100
+ return $this->getUrl('*/*/edit', array('entity_id' => $row->getId()));
101
+ }
102
+ }
app/code/community/Zitec/Branding/Block/Adminhtml/Widget/Grid/Column/Renderer/Date.php ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by JetBrains PhpStorm.
4
+ * User: alexandru.enciu
5
+ * Date: 27.05.2013
6
+ * Time: 15:40
7
+ * To change this template use File | Settings | File Templates.
8
+ */
9
+
10
+ class Zitec_Branding_Block_Adminhtml_Widget_Grid_Column_Renderer_Date
11
+ extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Date
12
+ {
13
+ /**
14
+ * Renders grid column
15
+ *
16
+ * @param Varien_Object $row
17
+ * @return string
18
+ */
19
+ public function render(Varien_Object $row)
20
+ {
21
+ if ($data = $row->getData($this->getColumn()->getIndex())) {
22
+ if ($this->getColumn()->getUsePlain())
23
+ {
24
+ return $data;
25
+ }
26
+
27
+ $format = $this->_getFormat();
28
+ try {
29
+ if($this->getColumn()->getGmtoffset()) {
30
+ $data = Mage::app()->getLocale()
31
+ ->date($data, Varien_Date::DATETIME_INTERNAL_FORMAT)->toString($format);
32
+ } else {
33
+ $data = Mage::getSingleton('core/locale')
34
+ ->date($data, Zend_Date::ISO_8601, null, false)->toString($format);
35
+ }
36
+ }
37
+ catch (Exception $e)
38
+ {
39
+ if($this->getColumn()->getTimezone()) {
40
+ $data = Mage::app()->getLocale()
41
+ ->date($data, Varien_Date::DATETIME_INTERNAL_FORMAT)->toString($format);
42
+ } else {
43
+ $data = Mage::getSingleton('core/locale')->date($data, null, null, false)->toString($format);
44
+ }
45
+ }
46
+ return $data;
47
+ }
48
+
49
+ return $this->getColumn()->getDefault();
50
+ }
51
+ }
app/code/community/Zitec/Branding/Block/Branding.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Zitec_Branding_Block_Branding extends Mage_Core_Block_Template
3
+ {
4
+ /**
5
+ * Adds the css for branding, if any.
6
+ */
7
+ protected function _prepareLayout()
8
+ {
9
+ $branding = Mage::helper('zitec_branding')->getActiveBranding();
10
+ if ($branding)
11
+ {
12
+ $this->setTemplate('z_branding/branding.phtml');
13
+ $head = $this->getLayout()->getBlock('head');
14
+ $head->addItem('skin_css', 'css/z_branding/z_branding.css');
15
+ $root = $this->getLayout()->getBlock('root');
16
+ $root->setBodyStyle("background-image: url('" . $branding->getImageUrl() . "')");
17
+ $this->setBranding($branding);
18
+ }
19
+
20
+ return parent::_prepareLayout();
21
+ }
22
+ }
app/code/community/Zitec/Branding/Helper/Data.php ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Zitec_Branding_Helper_Data extends
3
+ Mage_Core_Helper_Data
4
+ {
5
+ const BRANDING_DIR = 'branding';
6
+
7
+ /**
8
+ * Get image path for branding.
9
+ *
10
+ * @param string $filename
11
+ *
12
+ * @return string
13
+ */
14
+ public function getImagePath($filename)
15
+ {
16
+ return $this->getBaseDir() . DS . $filename;
17
+ }
18
+
19
+ /**
20
+ * Get image URL for branding.
21
+ *
22
+ * @param string $filename
23
+ *
24
+ * @return string
25
+ */
26
+ public function getImageUrl($filename)
27
+ {
28
+ return Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . self::BRANDING_DIR . '/' . $filename;
29
+ }
30
+
31
+ /**
32
+ *
33
+ */
34
+ public function getImage($imageUrl)
35
+ {
36
+ return str_replace(
37
+ Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . self::BRANDING_DIR . '/',
38
+ '',
39
+ $imageUrl);
40
+ }
41
+
42
+ /**
43
+ * Returns the base directory for branding image.
44
+ *
45
+ * @return string
46
+ */
47
+ public function getBaseDir()
48
+ {
49
+ return Mage::getBaseDir('media') . DS . self::BRANDING_DIR;
50
+ }
51
+
52
+ /**
53
+ * @return NULL | Zitec_Branding_Model_Branding
54
+ */
55
+ public function getActiveBranding()
56
+ {
57
+ $resourceModel = Mage::getResourceModel('zitec_branding/branding');
58
+ $date = date('Y-m-d', Mage::getSingleton('core/date')->timestamp());
59
+ $storeId = Mage::app()->getStore()->getId();
60
+ $branding = $resourceModel->getBrandingInPeriod($date, $date, $storeId);
61
+
62
+ return $branding;
63
+ }
64
+ }
app/code/community/Zitec/Branding/Helper/System/Store.php ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by JetBrains PhpStorm.
4
+ * User: alexandru.enciu
5
+ * Date: 26.07.2013
6
+ * Time: 14:39
7
+ * To change this template use File | Settings | File Templates.
8
+ */
9
+
10
+ class Zitec_Branding_Helper_System_Store {
11
+ /**
12
+ * Generates the stores structure that can be used in select
13
+ * form field.
14
+ *
15
+ * @param int $websiteId
16
+ * The website for which to retrieve the store
17
+ *
18
+ * @return array
19
+ * The stores and store views organized under groups
20
+ */
21
+ public function getStoresOptions($websiteId)
22
+ {
23
+ if (!$websiteId)
24
+ {
25
+ return array(
26
+ array(
27
+ 'label' => 'Admin',
28
+ 'value' => '0',
29
+ )
30
+ );
31
+ }
32
+ $structure = Mage::getSingleton('adminhtml/system_store')
33
+ ->getStoresStructure(FALSE, array(), array(), array($websiteId));
34
+
35
+ return $this->storesToOptions($structure);
36
+ }
37
+
38
+ /**
39
+ * Generates the stores structure that can be used in select
40
+ * form field.
41
+ *
42
+ * @param array $structure
43
+ * The website structure, as returned by
44
+ * Mage_Adminhtml_Model_System_Store::getStoresStructure
45
+ *
46
+ * @return array
47
+ * The stores and store views organized under groups
48
+ */
49
+ public function storesToOptions($structure)
50
+ {
51
+ $nonEscapableNbspChar = html_entity_decode('&#160;', ENT_NOQUOTES, 'UTF-8');
52
+ $options = array();
53
+
54
+ foreach ($structure as $websiteId => $website) {
55
+ $options[] = array(
56
+ 'label' => $website['label'],
57
+ 'value' => array(),
58
+ );
59
+
60
+ foreach ($website['children'] as $groupId => $group) {
61
+ $values = array();
62
+ foreach ($group['children'] as $storeId => $store) {
63
+ $values[] = array(
64
+ 'label' => str_repeat($nonEscapableNbspChar, 4) . $store['label'],
65
+ 'value' => $store['value']
66
+ );
67
+ }
68
+
69
+ $options[] = array(
70
+ 'label' => str_repeat($nonEscapableNbspChar, 4) . $group['label'],
71
+ 'value' => $values
72
+ );
73
+ }
74
+ }
75
+
76
+ return $options;
77
+ }
78
+ }
app/code/community/Zitec/Branding/Model/Branding.php ADDED
@@ -0,0 +1,147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Zitec_Branding_Model_Branding
3
+ extends Mage_Core_Model_Abstract
4
+ {
5
+ /**
6
+ * Pseudo constructor.
7
+ */
8
+ public function _construct()
9
+ {
10
+ $this->_init('zitec_branding/branding');
11
+ }
12
+
13
+ /**
14
+ * Validates data for branding.
15
+ *
16
+ * @return array
17
+ */
18
+ public function validate()
19
+ {
20
+ $errors = array();
21
+ $checkDates = TRUE;
22
+ if (!Zend_Validate::is( trim($this->getTitle()) , 'NotEmpty')) {
23
+ $errors[] = Mage::helper('zitec_branding')->__('The title cannot be empty.');
24
+ }
25
+ if (!Zend_Validate::is( trim($this->getImage()) , 'NotEmpty') && !$this->getFilesKey()) {
26
+ $errors[] = Mage::helper('zitec_branding')->__('The image cannot be empty.');
27
+ } elseif ($this->getFilesKey()) {
28
+ try {
29
+ $uploader = new Varien_File_Uploader($this->getFilesKey());
30
+ $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'png', 'gif')); //Allowed extension for file
31
+ $uploader->setAllowCreateFolders(true); //for creating the directory if not exists
32
+ $uploader->setAllowRenameFiles(false); //if true, uploaded file's name will be changed, if file with the same name already exists directory.
33
+ $uploader->setFilesDispersion(false);
34
+
35
+ if (!$uploader->checkAllowedExtension($uploader->getFileExtension()))
36
+ {
37
+ $errors[] = Mage::helper('zitec_branding')->__('The allowed file extensions are: jpg, jpeg, png, gif.');
38
+ }
39
+ $this->setUploader($uploader);
40
+ } catch (Exception $e) {
41
+ $errors[] = $e->getMessage();
42
+ }
43
+ }
44
+
45
+ if (!Zend_Validate::is( trim($this->getStartDate()) , 'NotEmpty')) {
46
+ $errors[] = Mage::helper('zitec_branding')->__('The start date cannot be empty.');
47
+ $checkDates = FALSE;
48
+ }
49
+ if (!Zend_Validate::is( trim($this->getEndDate()) , 'NotEmpty')) {
50
+ $errors[] = Mage::helper('zitec_branding')->__('The end date cannot be empty.');
51
+ $checkDates = FALSE;
52
+ }
53
+ if (!$this->getStoreIds()) {
54
+ $errors[] = Mage::helper('zitec_branding')->__('The store cannot be empty.');
55
+ } else {
56
+ if (!is_array($this->getStoreIds()))
57
+ {
58
+ $this->setStoreIds(explode(',', $this->getStoreIds()));
59
+ }
60
+ $availableStores = array_keys(Mage::app()->getStores());
61
+
62
+ if (array_diff($this->getStoreIds(), $availableStores))
63
+ {
64
+ $errors[] = Mage::helper('zitec_branding')->__('Some stores are invalid');
65
+ }
66
+ if ($checkDates)
67
+ {
68
+ if ($this->getStartDate() > $this->getEndDate())
69
+ {
70
+ $errors[] = Mage::helper('zitec_branding')->__('The start date must be smaller than end date.');
71
+ }
72
+
73
+ if ($this->getStatus())
74
+ {
75
+ foreach ($this->getStoreIds() as $storeId)
76
+ {
77
+ $existingBrandingId = $this->_getResource()
78
+ ->checkBrandingInPeriod($this->getStartDate(),
79
+ $this->getEndDate(),
80
+ $storeId,
81
+ $this->getId()
82
+ );
83
+
84
+ if ($existingBrandingId)
85
+ {
86
+ $errors[] = Mage::helper('zitec_branding')->__('A branding already exists in the selected period.');
87
+ break;
88
+ }
89
+ }
90
+ }
91
+ }
92
+ }
93
+
94
+ return $errors;
95
+ }
96
+
97
+ /**
98
+ * Checks if the branding image exists on disk.
99
+ *
100
+ * @return boolean
101
+ */
102
+ public function fileExists()
103
+ {
104
+ return file_exists($this->getImagePath());
105
+ }
106
+
107
+ /**
108
+ *
109
+ */
110
+ protected function _beforeSave()
111
+ {
112
+ if (!$this->getImage() || !$this->fileExists())
113
+ {
114
+ $this->uploadImage();
115
+ }
116
+
117
+ return parent::_beforeSave();
118
+ }
119
+
120
+ /**
121
+ * Uploads the image file for branding on disk.
122
+ *
123
+ * @return Zitec_Branding_Model_Branding
124
+ */
125
+ public function uploadImage()
126
+ {
127
+ $uploader = $this->getUploader();
128
+ if (!$uploader instanceof Varien_File_Uploader)
129
+ {
130
+ $uploader = new Varien_File_Uploader($this->getFilesKey());
131
+ $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'png', 'gif')); //Allowed extension for file
132
+ $uploader->setAllowCreateFolders(true); //for creating the directory if not exists
133
+ $uploader->setAllowRenameFiles(false); //if true, uploaded file's name will be changed, if file with the same name already exists directory.
134
+ $uploader->setFilesDispersion(false);
135
+ }
136
+
137
+ $path = Mage::helper('zitec_branding')->getBaseDir();
138
+
139
+ $result = $uploader->save($path);
140
+ if (!$result)
141
+ {
142
+ throw new Mage_Exception(Mage::helper('zitec_branding')->__("The file wasn't uploaded"));
143
+ }
144
+
145
+ $this->setImage($result['file']);
146
+ }
147
+ }
app/code/community/Zitec/Branding/Model/Resource/Branding.php ADDED
@@ -0,0 +1,262 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Zitec_Branding_Model_Resource_Branding extends Mage_Core_Model_Resource_Db_Abstract
3
+ {
4
+ /**
5
+ * Store associated with rule entities information map
6
+ *
7
+ * @var array
8
+ */
9
+ protected $_associatedEntitiesMap = array(
10
+ 'store' => array(
11
+ 'associations_table' => 'zitec_branding/store',
12
+ 'id_field' => 'branding_id',
13
+ 'entity_id_field' => 'store_id'
14
+ ),
15
+ );
16
+
17
+ /**
18
+ * Pseudo constructor.
19
+ */
20
+ public function _construct()
21
+ {
22
+ $this->_init('zitec_branding/branding', 'entity_id');
23
+ }
24
+ /**
25
+ * Add store ids to rule data after load
26
+ *
27
+ * @param Mage_Core_Model_Abstract $object
28
+ *
29
+ * @return Zitec_Branding_Model_Resource_Branding
30
+ */
31
+ protected function _afterLoad(Mage_Core_Model_Abstract $object)
32
+ {
33
+ $object->setData('store_ids', (array)$this->getStoreIds($object->getId()));
34
+ $object->setData('image_path', Mage::helper('zitec_branding')->getImagePath($object->getImage()));
35
+ $object->setData('image_url', Mage::helper('zitec_branding')->getImageUrl($object->getImage()));
36
+
37
+ return parent::_afterLoad($object);
38
+ }
39
+
40
+ /**
41
+ * Bind branding to store(s).
42
+ *
43
+ * @param Mage_Core_Model_Abstract $object
44
+ *
45
+ * @return Zitec_Branding_Model_Resource_Branding
46
+ */
47
+ protected function _afterSave(Mage_Core_Model_Abstract $object)
48
+ {
49
+ if ($object->hasStoreIds()) {
50
+ $storeIds = $object->getStoreIds();
51
+ if (!is_array($storeIds)) {
52
+ $storeIds = explode(',', (string)$storeIds);
53
+ }
54
+ $this->bindRuleToEntity($object->getId(), $storeIds, 'store');
55
+ }
56
+
57
+ parent::_afterSave($object);
58
+
59
+ return $this;
60
+ }
61
+
62
+ /**
63
+ * Retrieve store ids of specified branding
64
+ *
65
+ * @param int $ruleId
66
+ * @return array
67
+ */
68
+ public function getStoreIds($brandingId)
69
+ {
70
+ return $this->getAssociatedEntityIds($brandingId, 'store');
71
+ }
72
+
73
+ /**
74
+ * Returns the branding for the selected period.
75
+ *
76
+ * @param string $startDate
77
+ * The start date, in MySQL format: YYYY-MM-DD
78
+ *
79
+ * @param string $endDate
80
+ * The end date, in MySQL format: YYYY-MM-DD
81
+ *
82
+ * @return NULL | Zitec_Branding_Model_Branding
83
+ */
84
+ public function getBrandingInPeriod($startDate, $endDate, $storeId)
85
+ {
86
+ $readAdapter = $this->_getReadAdapter();
87
+ $select = $readAdapter->select()
88
+ ->from($this->getTable('zitec_branding/branding'))
89
+ ->where('start_date <= :start_date AND end_date >= :start_date OR
90
+ start_date <= :end_date AND end_date >= :end_date')
91
+ ->joinInner($this->getTable('zitec_branding/store'), 'branding_id=entity_id', NULL)
92
+ ->where('store_id=:store_id')
93
+ ->where('status=1')
94
+ ->limit(1);
95
+ $bind = array(
96
+ ':start_date' => $startDate,
97
+ ':end_date' => $endDate,
98
+ ':store_id' => $storeId,
99
+ );
100
+
101
+ $fields = $readAdapter->fetchRow($select, $bind);
102
+
103
+ if ($fields)
104
+ {
105
+ $object = Mage::getModel('zitec_branding/branding');
106
+ $object->setData($fields);
107
+ $this->_afterLoad($object);
108
+
109
+ return $object;
110
+ }
111
+
112
+ return NULL;
113
+ }
114
+ /**
115
+ * Returns the branding for the selected period.
116
+ *
117
+ * @param string $startDate
118
+ * The start date, in MySQL format: YYYY-MM-DD
119
+ *
120
+ * @param string $endDate
121
+ * The end date, in MySQL format: YYYY-MM-DD
122
+ *
123
+ * @return NULL | Zitec_Branding_Model_Branding
124
+ */
125
+ public function checkBrandingInPeriod($startDate, $endDate, $storeId, $entityId)
126
+ {
127
+ $readAdapter = $this->_getReadAdapter();
128
+ $select = $readAdapter->select()
129
+ ->from($this->getTable('zitec_branding/branding'), 'entity_id')
130
+ ->where('start_date <= :start_date AND end_date >= :start_date OR
131
+ start_date <= :end_date AND end_date >= :end_date OR
132
+ start_date >= :start_date AND end_date <= :end_date')
133
+ ->joinInner($this->getTable('zitec_branding/store'), 'branding_id=entity_id', NULL)
134
+ ->where('store_id=:store_id')
135
+ ->where('status=1')
136
+ ->where('entity_id !=:entity_id')
137
+ ->limit(1);
138
+ $bind = array(
139
+ ':start_date' => $startDate,
140
+ ':end_date' => $endDate,
141
+ ':store_id' => $storeId,
142
+ ':entity_id' => $entityId,
143
+ );
144
+
145
+ $entityId = $readAdapter->fetchOne($select, $bind);
146
+
147
+ return $entityId;
148
+ }
149
+
150
+ /**
151
+ * Bind specified rules to entities
152
+ *
153
+ * @param array|int|string $ids
154
+ * @param array|int|string $entityIds
155
+ * @param string $entityType
156
+ *
157
+ * @return Mage_Rule_Model_Resource_Abstract
158
+ */
159
+ public function bindRuleToEntity($ids, $entityIds, $entityType)
160
+ {
161
+ if (empty($ids) || empty($entityIds)) {
162
+ return $this;
163
+ }
164
+ $adapter = $this->_getWriteAdapter();
165
+ $entityInfo = $this->_getAssociatedEntityInfo($entityType);
166
+
167
+ if (!is_array($ids)) {
168
+ $ids = array((int) $ids);
169
+ }
170
+ if (!is_array($entityIds)) {
171
+ $entityIds = array((int) $entityIds);
172
+ }
173
+
174
+ $data = array();
175
+ $count = 0;
176
+
177
+ $adapter->beginTransaction();
178
+
179
+ try {
180
+ foreach ($ids as $id) {
181
+ foreach ($entityIds as $entityId) {
182
+ $data[] = array(
183
+ $entityInfo['entity_id_field'] => $entityId,
184
+ $entityInfo['id_field'] => $id
185
+ );
186
+ $count++;
187
+ if (($count % 1000) == 0) {
188
+ $adapter->insertOnDuplicate(
189
+ $this->getTable($entityInfo['associations_table']),
190
+ $data,
191
+ array($entityInfo['id_field'])
192
+ );
193
+ $data = array();
194
+ }
195
+ }
196
+ }
197
+ if (!empty($data)) {
198
+ $adapter->insertOnDuplicate(
199
+ $this->getTable($entityInfo['associations_table']),
200
+ $data,
201
+ array($entityInfo['id_field'])
202
+ );
203
+ }
204
+
205
+ $adapter->delete($this->getTable($entityInfo['associations_table']),
206
+ $adapter->quoteInto($entityInfo['id_field'] . ' IN (?) AND ', $ids) .
207
+ $adapter->quoteInto($entityInfo['entity_id_field'] . ' NOT IN (?)', $entityIds)
208
+ );
209
+ } catch (Exception $e) {
210
+ $adapter->rollback();
211
+ throw $e;
212
+
213
+ }
214
+
215
+ $adapter->commit();
216
+
217
+ return $this;
218
+ }
219
+
220
+ /**
221
+ * Retrieve branding's associated entity Ids by entity type
222
+ *
223
+ * @param int $id
224
+ * @param string $entityType
225
+ *
226
+ * @return array
227
+ */
228
+ public function getAssociatedEntityIds($id, $entityType)
229
+ {
230
+ $entityInfo = $this->_getAssociatedEntityInfo($entityType);
231
+
232
+ $select = $this->_getReadAdapter()->select()
233
+ ->from($this->getTable($entityInfo['associations_table']), array($entityInfo['entity_id_field']))
234
+ ->where($entityInfo['id_field'] . ' = ?', $id);
235
+
236
+ return $this->_getReadAdapter()->fetchCol($select);
237
+ }
238
+
239
+
240
+ /**
241
+ * Retrieve correspondent entity information (associations table name, columns names)
242
+ * of rule's associated entity by specified entity type
243
+ *
244
+ * @param string $entityType
245
+ *
246
+ * @return array
247
+ */
248
+ protected function _getAssociatedEntityInfo($entityType)
249
+ {
250
+ if (isset($this->_associatedEntitiesMap[$entityType])) {
251
+ return $this->_associatedEntitiesMap[$entityType];
252
+ }
253
+
254
+ $e = Mage::exception(
255
+ 'Mage_Core',
256
+ Mage::helper('core')->__(
257
+ 'There is no information about associated entity type "%s".', $entityType
258
+ )
259
+ );
260
+ throw $e;
261
+ }
262
+ }
app/code/community/Zitec/Branding/Model/Resource/Branding/Collection.php ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Zitec_Branding_Model_Resource_Branding_Collection extends
3
+ Mage_Core_Model_Resource_Db_Collection_Abstract
4
+ {
5
+ /**
6
+ * Store associated with rule entities information map
7
+ *
8
+ * @var array
9
+ */
10
+ protected $_associatedEntitiesMap = array(
11
+ 'store' => array(
12
+ 'associations_table' => 'zitec_branding/store',
13
+ 'id_field' => 'branding_id',
14
+ 'entity_id_field' => 'store_id'
15
+ ),
16
+ );
17
+ /**
18
+ * Pseudo constructor.
19
+ */
20
+ protected function _construct()
21
+ {
22
+ $this->_init('zitec_branding/branding');
23
+ }
24
+
25
+ /**
26
+ * Limit rules collection by specific websites
27
+ *
28
+ * @param int|array|Mage_Core_Model_Website $websiteId
29
+ *
30
+ * @return Zitec_Branding_Model_Resource_Branding
31
+ */
32
+ public function addStoreFilter($storeId)
33
+ {
34
+ $entityInfo = $this->_getAssociatedEntityInfo('store');
35
+ if (!$this->getFlag('is_store_table_joined')) {
36
+ $this->setFlag('is_store_table_joined', true);
37
+ if ($storeId instanceof Mage_Core_Model_Store) {
38
+ $storeId = $storeId->getId();
39
+ }
40
+
41
+ $subSelect = $this->getConnection()->select()
42
+ ->from(array('store' => $this->getTable($entityInfo['associations_table'])), '')
43
+ ->where('store.' . $entityInfo['entity_id_field'] . ' IN (?)', $storeId);
44
+ $this->getSelect()->exists(
45
+ $subSelect,
46
+ 'main_table.entity_id = store.' . $entityInfo['id_field']
47
+ );
48
+ }
49
+ return $this;
50
+ }
51
+
52
+ /**
53
+ * Provide support for website id filter
54
+ *
55
+ * @param string $field
56
+ * @param mixed $condition
57
+ *
58
+ * @return Zitec_Branding_Model_Resource_Branding
59
+ */
60
+ public function addFieldToFilter($field, $condition = null)
61
+ {
62
+ if ($field == 'store_ids') {
63
+ return $this->addStoreFilter($condition);
64
+ }
65
+
66
+ parent::addFieldToFilter($field, $condition);
67
+ return $this;
68
+ }
69
+
70
+ /**
71
+ * Init flag for adding rule website ids to collection result
72
+ *
73
+ * @param bool|null $flag
74
+ *
75
+ * @return Mage_Rule_Model_Resource_Rule_Collection_Abstract
76
+ */
77
+ public function addStoresToResult($flag = null)
78
+ {
79
+ $flag = ($flag === null) ? true : $flag;
80
+ $this->setFlag('add_stores_to_result', $flag);
81
+ return $this;
82
+ }
83
+
84
+ /**
85
+ * Add website ids to rules data
86
+ *
87
+ * @return Mage_Rule_Model_Resource_Rule_Collection_Abstract
88
+ */
89
+ protected function _afterLoad()
90
+ {
91
+ parent::_afterLoad();
92
+ if ($this->getFlag('add_stores_to_result') && $this->_items) {
93
+ /** @var Mage_Rule_Model_Abstract $item */
94
+ foreach ($this->_items as $item) {
95
+ $item->afterLoad();
96
+ }
97
+ }
98
+
99
+ return $this;
100
+ }
101
+
102
+ /**
103
+ * Retrieve correspondent entity information (associations table name, columns names)
104
+ * of rule's associated entity by specified entity type
105
+ *
106
+ * @param string $entityType
107
+ *
108
+ * @return array
109
+ */
110
+ protected function _getAssociatedEntityInfo($entityType)
111
+ {
112
+ if (isset($this->_associatedEntitiesMap[$entityType])) {
113
+ return $this->_associatedEntitiesMap[$entityType];
114
+ }
115
+
116
+ $e = Mage::exception(
117
+ 'Mage_Core',
118
+ Mage::helper('rule')->__(
119
+ 'There is no information about associated entity type "%s".', $entityType
120
+ )
121
+ );
122
+ throw $e;
123
+ }
124
+ }
app/code/community/Zitec/Branding/Model/Resource/Setup.php ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ <?php
2
+ class Zitec_Branding_Model_Resource_Setup extends
3
+ Mage_Core_Model_Resource_Setup
4
+ {
5
+
6
+ }
app/code/community/Zitec/Branding/controllers/Adminhtml/BrandingController.php ADDED
@@ -0,0 +1,172 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Zitec_Branding_Adminhtml_BrandingController extends Mage_Adminhtml_Controller_Action
4
+ {
5
+
6
+ /**
7
+ * Initializes the current branding model
8
+ *
9
+ * @param string $idFieldName
10
+ *
11
+ * @return Zitec_Branding_Model_Branding
12
+ */
13
+ protected function _initBranding($idFieldName = 'entity_id')
14
+ {
15
+ $brandingId = (int) $this->getRequest()->getParam($idFieldName);
16
+ $branding = Mage::getModel('zitec_branding/branding');
17
+
18
+ if ($brandingId) {
19
+ $branding->load($brandingId);
20
+ }
21
+
22
+ Mage::register('current_branding', $branding);
23
+
24
+ return $branding;
25
+ }
26
+
27
+ /**
28
+ * Customers list action
29
+ */
30
+ public function indexAction()
31
+ {
32
+ $this->_title($this->__('Branding'))->_title($this->__('Manage Branding'));
33
+
34
+ if ($this->getRequest()->getQuery('ajax')) {
35
+ $this->_forward('grid');
36
+ return;
37
+ }
38
+
39
+ $this->loadLayout();
40
+
41
+ /**
42
+ * Set active menu item
43
+ */
44
+ $this->_setActiveMenu('dacris/branding');
45
+
46
+ // /**
47
+ // * Append customers block to content
48
+ // */
49
+ // $this->_addContent(
50
+ // $this->getLayout()->createBlock('adminhtml/customer', 'customer')
51
+ // );
52
+
53
+ /**
54
+ * Add breadcrumb item
55
+ */
56
+ $this->_addBreadcrumb(Mage::helper('zitec_branding')->__('Customers'), Mage::helper('zitec_branding')->__('Branding'));
57
+ $this->_addBreadcrumb(Mage::helper('zitec_branding')->__('Manage Customers'), Mage::helper('zitec_branding')->__('Manage Branding'));
58
+
59
+ $this->renderLayout();
60
+ }
61
+
62
+ public function gridAction()
63
+ {
64
+ $this->loadLayout();
65
+ $this->renderLayout();
66
+ }
67
+
68
+ /**
69
+ * Customer edit action
70
+ */
71
+ public function editAction()
72
+ {
73
+ $branding = $this->_initBranding();
74
+ $this->loadLayout();
75
+
76
+ $this->_title($branding->getId() ? $branding->getTitle() : $this->__('New Branding'));
77
+
78
+ /**
79
+ * Set active menu item
80
+ */
81
+ $this->_setActiveMenu('dacris/branding/edit');
82
+
83
+ $this->renderLayout();
84
+ }
85
+
86
+ /**
87
+ * Create new customer action
88
+ */
89
+ public function newAction()
90
+ {
91
+ $this->_forward('edit');
92
+ }
93
+
94
+ /**
95
+ * Delete customer action
96
+ */
97
+ public function deleteAction()
98
+ {
99
+ $branding = $this->_initBranding();
100
+
101
+ if ($branding->getId()) {
102
+ try {
103
+ $branding->delete();
104
+ Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('zitec_adminhtml')->__('The branding has been deleted.'));
105
+ }
106
+ catch (Exception $e){
107
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
108
+ }
109
+ }
110
+
111
+ $this->_redirect('*/branding');
112
+ }
113
+
114
+ /**
115
+ * Save customer action
116
+ */
117
+ public function saveAction()
118
+ {
119
+ $data = $this->getRequest()->getPost();
120
+ if ($data) {
121
+ $branding = $this->_initBranding();
122
+ $data = $this->_filterDates($data, array('start_date', 'end_date'));
123
+ if (isset($data['image_url']) && isset($data['image_url']['value']))
124
+ {
125
+ $data['image_url'] = $data['image_url']['value'];
126
+ $data['image'] = Mage::helper('zitec_branding')->getImage($data['image_url']);
127
+ $data['image_path'] = Mage::helper('zitec_branding')->getImagePath($data['image']);
128
+ }
129
+
130
+ $branding->setData($data);
131
+
132
+ if (isset($_FILES['image_url']['tmp_name']) && $_FILES['image_url']['tmp_name'])
133
+ {
134
+ $branding->setFilesKey('image_url');
135
+ $branding->setImage(NULL);
136
+ }
137
+
138
+ try {
139
+ $errors = $branding->validate();
140
+
141
+ if ($errors)
142
+ {
143
+ foreach ($errors as $error)
144
+ {
145
+ $this->_getSession()->addError($error);
146
+ }
147
+
148
+ $this->_getSession()->setBrandingData($data);
149
+ $this->getResponse()->setRedirect($this->getUrl('*/branding/edit', array('entity_id' => $branding->getId())));
150
+ return;
151
+ }
152
+
153
+ $branding->save();
154
+ $this->_getSession()->addSuccess($this->__('The branding was saved successfully'));
155
+ } catch (Mage_Core_Exception $e) {
156
+ Mage::logException($e);
157
+ $this->_getSession()->addError($e->getMessage());
158
+ $this->_getSession()->setBrandingData($data);
159
+ $this->getResponse()->setRedirect($this->getUrl('*/branding/edit', array('entity_id' => $branding->getId())));
160
+ } catch (Exception $e) {
161
+ Mage::logException($e);
162
+ $this->_getSession()->addException($e,
163
+ Mage::helper('adminhtml')->__('An error occurred while saving the branding.'));
164
+ $this->_getSession()->setBrandingData($data);
165
+ $this->getResponse()->setRedirect($this->getUrl('*/branding/edit', array('entity_id'=>$branding->getId())));
166
+ return;
167
+ }
168
+ }
169
+
170
+ $this->getResponse()->setRedirect($this->getUrl('*/branding'));
171
+ }
172
+ }
app/code/community/Zitec/Branding/etc/adminhtml.xml ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <menu>
4
+ <zitec>
5
+ <title>Zitec</title>
6
+ <sort_order>99</sort_order>
7
+ <children>
8
+ <zitec_branding translate="title" module="zitec_branding">
9
+ <title>Brandings</title>
10
+ <sort_order>1</sort_order>
11
+ <action>adminhtml/branding</action>
12
+ </zitec_branding>
13
+ </children>
14
+ </zitec>
15
+ </menu>
16
+ <acl>
17
+ <resources>
18
+ <admin>
19
+ <children>
20
+ <zitec>
21
+ <children>
22
+ <zitec_branding>
23
+ <title>Brandings</title>
24
+ <sort_order>0</sort_order>
25
+ </zitec_branding>
26
+ </children>
27
+ </zitec>
28
+ </children>
29
+ </admin>
30
+ </resources>
31
+ </acl>
32
+ </config>
app/code/community/Zitec/Branding/etc/config.xml ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8" ?>
2
+ <config>
3
+ <modules>
4
+ <Zitec_Branding>
5
+ <version>0.1.0</version>
6
+ </Zitec_Branding>
7
+ </modules>
8
+ <global>
9
+ <models>
10
+ <zitec_branding>
11
+ <class>Zitec_Branding_Model</class>
12
+ <resourceModel>zitec_branding_resource</resourceModel>
13
+ </zitec_branding>
14
+ <zitec_branding_resource>
15
+ <class>Zitec_Branding_Model_Resource</class>
16
+ <entities>
17
+ <branding>
18
+ <table>zitec_branding</table>
19
+ </branding>
20
+ <store>
21
+ <table>zitec_branding_store</table>
22
+ </store>
23
+ </entities>
24
+ </zitec_branding_resource>
25
+ </models>
26
+ <resources>
27
+ <zitec_branding_setup>
28
+ <setup>
29
+ <module>Zitec_Branding</module>
30
+ <class>Zitec_Branding_Model_Resource_Setup</class>
31
+ </setup>
32
+ <connection>
33
+ <use>core_setup</use>
34
+ </connection>
35
+ </zitec_branding_setup>
36
+ </resources>
37
+ <blocks>
38
+ <zitec_branding>
39
+ <class>Zitec_Branding_Block</class>
40
+ </zitec_branding>
41
+ </blocks>
42
+ <helpers>
43
+ <zitec_branding>
44
+ <class>Zitec_Branding_Helper</class>
45
+ </zitec_branding>
46
+ </helpers>
47
+ </global>
48
+ <admin>
49
+ <routers>
50
+ <adminhtml>
51
+ <args>
52
+ <modules>
53
+ <zitec_branding before="Mage_Adminhtml">Zitec_Branding_Adminhtml</zitec_branding>
54
+ </modules>
55
+ </args>
56
+ </adminhtml>
57
+ </routers>
58
+ </admin>
59
+ <adminhtml>
60
+ <layout>
61
+ <updates>
62
+ <zitec_branding>
63
+ <file>z_branding.xml</file>
64
+ </zitec_branding>
65
+ </updates>
66
+ </layout>
67
+ <translate>
68
+ <modules>
69
+ <Zitec_Branding>
70
+ <files>
71
+ <default>Zitec_Branding.csv</default>
72
+ </files>
73
+ </Zitec_Branding>
74
+ </modules>
75
+ </translate>
76
+ </adminhtml>
77
+ <frontend>
78
+ <layout>
79
+ <updates>
80
+ <zitec_branding>
81
+ <file>z_branding.xml</file>
82
+ </zitec_branding>
83
+ </updates>
84
+ </layout>
85
+ </frontend>
86
+ </config>
app/code/community/Zitec/Branding/sql/zitec_branding_setup/install-0.1.0.php ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @var Zitec_Branding_Model_Resource_Setup $installer
4
+ */
5
+ $installer = $this;
6
+
7
+ $installer->startSetup();
8
+ $table = $installer->getConnection()
9
+ ->newTable($installer->getTable('zitec_branding/branding'))
10
+ ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, 'medium', array(
11
+ 'primary' => TRUE,
12
+ 'nullable' => FALSE,
13
+ 'identity' => TRUE,
14
+ 'unsigned' => TRUE,
15
+ ), 'The primary key')
16
+ ->addColumn('title', Varien_Db_Ddl_Table::TYPE_TEXT, '50', array(
17
+ 'nullable' => FALSE,
18
+ ), 'The branding title')
19
+ ->addColumn('image', Varien_Db_Ddl_Table::TYPE_TEXT, '50', array(
20
+ 'nullable' => FALSE,
21
+ ), 'The branding image')
22
+ ->addColumn('status', Varien_Db_Ddl_Table::TYPE_BOOLEAN, null, array(
23
+ 'nullable' => FALSE,
24
+ 'unsigned' => TRUE,
25
+ ), 'The branding status: 0 is inactive, 1 is active')
26
+ ->addColumn('start_date', Varien_Db_Ddl_Table::TYPE_DATE, null, array(
27
+ 'nullable' => FALSE,
28
+ ), 'The branding start date')
29
+ ->addColumn('end_date', Varien_Db_Ddl_Table::TYPE_DATE, null, array(
30
+ 'nullable' => FALSE,
31
+ ), 'The branding end date')
32
+ ->addColumn('url', Varien_Db_Ddl_Table::TYPE_TEXT, '100', array(
33
+ 'nullable' => TRUE,
34
+ ), 'The branding URL');
35
+
36
+ $installer->getConnection()->createTable($table);
37
+
38
+ $table = $installer->getConnection()
39
+ ->newTable($installer->getTable('zitec_branding/store'))
40
+ ->addColumn('branding_store_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
41
+ 'primary' => TRUE,
42
+ 'nullable' => FALSE,
43
+ 'identity' => TRUE,
44
+ 'unsigned' => TRUE,
45
+ ), 'The primary key')
46
+ ->addColumn('branding_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
47
+ 'nullable' => FALSE,
48
+ 'unsigned' => TRUE,
49
+ ), 'The branding id')
50
+ ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array(
51
+ 'unsigned' => TRUE,
52
+ 'nullable' => FALSE,
53
+ ), 'The primary key')
54
+ ->addForeignKey($installer->getFkName('zitec_branding/store', 'store_id', 'core/store', 'store_id'),
55
+ 'store_id', $installer->getTable('core/store'), 'store_id',
56
+ Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE
57
+ )
58
+ ->addForeignKey($installer->getFkName('zitec_branding/store', 'branding_id', 'zitec_branding/branding', 'entity_id'),
59
+ 'branding_id', $installer->getTable('zitec_branding/branding'), 'entity_id',
60
+ Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE
61
+ )
62
+ ->addIndex($installer->getIdxName('zitec_branding/store', array('branding_id', 'store_id'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE),
63
+ array('branding_id', 'store_id'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE));
64
+
65
+ $installer->getConnection()->createTable($table);
66
+ $installer->endSetup();
app/design/adminhtml/default/default/layout/z_branding.xml ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8" ?>
2
+ <layout>
3
+ <adminhtml_branding_index>
4
+ <reference name="content">
5
+ <block type="zitec_branding/adminhtml_branding" name="zitec_branding" />
6
+ </reference>
7
+ </adminhtml_branding_index>
8
+ <adminhtml_branding_grid>
9
+ <block type="core/text_list" name="root" output="toHtml">
10
+ <block type="zitec_branding/adminhtml_branding_grid" name="zitec_branding_grid" />
11
+ </block>
12
+ </adminhtml_branding_grid>
13
+ <adminhtml_branding_edit>
14
+ <reference name="content">
15
+ <block type="zitec_branding/adminhtml_branding_edit" name="zitec_branding.edit" />
16
+ </reference>
17
+ </adminhtml_branding_edit>
18
+ <adminhtml_branding_new>
19
+ <update handle="adminhtml_branding_edit" />
20
+ </adminhtml_branding_new>
21
+ </layout>
app/design/frontend/base/default/layout/z_branding.xml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8" ?>
2
+ <layout>
3
+ <default>
4
+ <reference name="after_body_start">
5
+ <block type="zitec_branding/branding" name="zitec_branding" />
6
+ </reference>
7
+ </default>
8
+ </layout>
app/design/frontend/base/default/template/z_branding/branding.phtml ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php if ($this->getBranding() && $this->getBranding()->getUrl()) : ?>
2
+ <div class="branding-link-below">
3
+ <a href="<?php print $this->getBranding()->getUrl() ?>" class="branding-link">&nbsp;</a>
4
+ </div>
5
+ <?php endif; ?>
app/etc/modules/Zitec_Branding.xml ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <modules>
4
+ <Zitec_Branding>
5
+ <version>0.1.0</version>
6
+ <codePool>community</codePool>
7
+ <active>true</active>
8
+ <depends>
9
+ <Mage_Adminhtml />
10
+ </depends>
11
+ </Zitec_Branding>
12
+ </modules>
13
+ </config>
package.xml ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Zitec_Site_Branding</name>
4
+ <version>0.1.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://opensource.org/licenses/osl-3.0.php">Open Software License (OSL)</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Offers the possibility to change the site background from the admin interface: flexible, easy to use.</summary>
10
+ <description>The site branding can be edited from admin. For a branding, the following settings are available:&#xD;
11
+ &#xD;
12
+ - background image&#xD;
13
+ - state: active or inactive&#xD;
14
+ - store views&#xD;
15
+ - URL to the page the branding may promote&#xD;
16
+ - start date&#xD;
17
+ - end date&#xD;
18
+ &#xD;
19
+ All fields are mandatory, with the exception of URL field.</description>
20
+ <notes>This is the first stable release of the official Zitec Site Branding extension for Magento. It should work for all versions from Magento 1.7 upwards.</notes>
21
+ <authors><author><name>Alexandru Enciu</name><user>alexenciu</user><email>alexandru.enciu@zitec.ro</email></author><author><name>Adina Nichitean</name><user>adinanichitean</user><email>adinanichitean@gmail.com</email></author></authors>
22
+ <date>2013-07-26</date>
23
+ <time>11:52:22</time>
24
+ <contents><target name="magecommunity"><dir name="Zitec"><dir name="Branding"><dir name="Block"><dir name="Adminhtml"><dir name="Branding"><dir name="Edit"><file name="Form.php" hash="5040e2111aa9184249ba8df84b0fbff7"/></dir><file name="Edit.php" hash="7f3cdf360c6da9a0ed0b162678ae55fe"/><file name="Grid.php" hash="8852b614d642e6fc856bf0745877285a"/></dir><file name="Branding.php" hash="1c271e903779651bf3426ef43e78dd65"/><dir name="Widget"><dir name="Grid"><dir name="Column"><dir name="Renderer"><file name="Date.php" hash="2c95f17ca869edec9aac64acf517996e"/></dir></dir></dir></dir></dir><file name="Branding.php" hash="0bba8bc9b7ae288b16dd6f185a3b43a1"/></dir><dir name="Helper"><file name="Data.php" hash="fa76d47b32fb1c8ca1254a7575bd2550"/><dir name="System"><file name="Store.php" hash="9b3aac0f9b00b11aca687f9a618e4bf5"/></dir></dir><dir name="Model"><file name="Branding.php" hash="ece3fad08f58371f3fb7bf75b9c3e68d"/><dir name="Resource"><dir name="Branding"><file name="Collection.php" hash="c6b61d885bb0edc037058a3bae2cd616"/></dir><file name="Branding.php" hash="e1461eb5ec644e8c24c097ad903b0672"/><file name="Setup.php" hash="3509aafe3572bbabb72b92e4a23024c8"/></dir></dir><dir name="controllers"><dir name="Adminhtml"><file name="BrandingController.php" hash="63557ef6ed49c8eff63c4d9988bdf329"/></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="7ed04eeb227099cc09fa21494f558c70"/><file name="config.xml" hash="46f17618d6be03a0938b404b55da230c"/></dir><dir name="sql"><dir name="zitec_branding_setup"><file name="install-0.1.0.php" hash="60ca96b0bf15221d25aa2929f7ac4d84"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="z_branding.xml" hash="5076878f4a334985e8cecc42388618a8"/></dir><dir name="template"><dir name="z_branding"><file name="branding.phtml" hash="94a281cca91157a38fcf97264e3a02c3"/></dir></dir></dir></dir></dir><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="z_branding.xml" hash="45879296ae63c8be8dcc9da817e0371d"/></dir></dir></dir></dir></target><target name="mageskin"><dir name="frontend"><dir name="base"><dir name="default"><dir name="css"><dir name="z_branding"><file name="z_branding.css" hash="0064c9953ec7efc1a381e6a45e1b2825"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir><dir name="modules"><file name="Zitec_Branding.xml" hash="cd5f34a956056afaf9460d5ef014e0fd"/></dir></dir></target></contents>
25
+ <compatible/>
26
+ <dependencies><required><php><min>5.2.0</min><max>5.4.0</max></php><package><name>Magento_Core_Modules</name><channel>community</channel><min>1.7.0.0</min><max>1.7.0.2</max></package></required></dependencies>
27
+ </package>
skin/frontend/base/default/css/z_branding/z_branding.css ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .branding-link-below {
2
+ position: relative;
3
+ z-index: 1;
4
+ width: 100%;
5
+ }
6
+ .branding-link-below a, .branding-link-below a:hover {
7
+ min-height: 890px;
8
+ width: 100%;
9
+ position: absolute;
10
+ top:0;
11
+ left:0;
12
+ }