1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27: 28: 29: 30: 31: 32: 33:
34:
35: class Mage_Adminhtml_Block_Rating_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form
36: {
37: 38: 39: 40: 41:
42: protected function _prepareForm()
43: {
44: $form = new Varien_Data_Form();
45: $this->setForm($form);
46:
47: $fieldset = $form->addFieldset('rating_form', array(
48: 'legend'=>Mage::helper('rating')->__('Rating Title')
49: ));
50:
51: $fieldset->addField('rating_code', 'text', array(
52: 'name' => 'rating_code',
53: 'label' => Mage::helper('rating')->__('Default Value'),
54: 'class' => 'required-entry',
55: 'required' => true,
56: ));
57:
58: foreach (Mage::getSingleton('adminhtml/system_store')->getStoreCollection() as $store) {
59: $fieldset->addField('rating_code_' . $store->getId(), 'text', array(
60: 'label' => $store->getName(),
61: 'name' => 'rating_codes[' . $store->getId() . ']',
62: ));
63: }
64:
65: if (Mage::getSingleton('adminhtml/session')->getRatingData()) {
66: $form->setValues(Mage::getSingleton('adminhtml/session')->getRatingData());
67: $data = Mage::getSingleton('adminhtml/session')->getRatingData();
68: if (isset($data['rating_codes'])) {
69: $this->_setRatingCodes($data['rating_codes']);
70: }
71: Mage::getSingleton('adminhtml/session')->setRatingData(null);
72: } elseif (Mage::registry('rating_data')) {
73: $form->setValues(Mage::registry('rating_data')->getData());
74: if (Mage::registry('rating_data')->getRatingCodes()) {
75: $this->_setRatingCodes(Mage::registry('rating_data')->getRatingCodes());
76: }
77: }
78:
79: if (Mage::registry('rating_data')) {
80: $collection = Mage::getModel('rating/rating_option')
81: ->getResourceCollection()
82: ->addRatingFilter(Mage::registry('rating_data')->getId())
83: ->load();
84:
85: $i = 1;
86: foreach ($collection->getItems() as $item) {
87: $fieldset->addField('option_code_' . $item->getId() , 'hidden', array(
88: 'required' => true,
89: 'name' => 'option_title[' . $item->getId() . ']',
90: 'value' => ($item->getCode()) ? $item->getCode() : $i,
91: ));
92:
93: $i ++;
94: }
95: } else {
96: for ($i = 1; $i <= 5; $i++) {
97: $fieldset->addField('option_code_' . $i, 'hidden', array(
98: 'required' => true,
99: 'name' => 'option_title[add_' . $i . ']',
100: 'value' => $i,
101: ));
102: }
103: }
104:
105: $fieldset = $form->addFieldset('visibility_form', array(
106: 'legend' => Mage::helper('rating')->__('Rating Visibility')
107: ));
108:
109: $field = $fieldset->addField('stores', 'multiselect', array(
110: 'label' => Mage::helper('rating')->__('Visible In'),
111: 'name' => 'stores[]',
112: 'values' => Mage::getSingleton('adminhtml/system_store')->getStoreValuesForForm()
113: ));
114: $renderer = $this->getLayout()->createBlock('adminhtml/store_switcher_form_renderer_fieldset_element');
115: $field->setRenderer($renderer);
116:
117: $fieldset->addField('position', 'text', array(
118: 'label' => Mage::helper('rating')->__('Sort Order'),
119: 'name' => 'position',
120: ));
121:
122: if (Mage::registry('rating_data')) {
123: $form->getElement('position')->setValue(Mage::registry('rating_data')->getPosition());
124: $form->getElement('stores')->setValue(Mage::registry('rating_data')->getStores());
125: }
126:
127: return parent::_prepareForm();
128: }
129:
130: protected function _setRatingCodes($ratingCodes) {
131: foreach($ratingCodes as $store=>$value) {
132: if($element = $this->getForm()->getElement('rating_code_' . $store)) {
133: $element->setValue($value);
134: }
135: }
136: }
137:
138: protected function _toHtml()
139: {
140: return $this->_getWarningHtml() . parent::_toHtml();
141: }
142:
143: protected function _getWarningHtml()
144: {
145: return '<div>
146: <ul class="messages">
147: <li class="notice-msg">
148: <ul>
149: <li>'.Mage::helper('rating')->__('If you do not specify a rating title for a store, the default value will be used.').'</li>
150: </ul>
151: </li>
152: </ul>
153: </div>';
154: }
155:
156:
157: }
158: