private function _displayFormApplicationCriterion() { include_once dirname(__FILE__) . '/ProductCommentCriterion.php'; $criterions = ProductCommentCriterion::getCriterions($this->context->language->id, false, true); $id_criterion = (int) Tools::getValue('updateCriterion'); if ($id_criterion) { $criterion = new ProductCommentCriterion((int) $id_criterion); if ($criterion->id_product_comment_criterion_type == 2) { $categories = Category::getSimpleCategories($this->context->language->id); $criterion_categories = $criterion->getCategories(); } else { if ($criterion->id_product_comment_criterion_type == 3) { $criterion_products = $criterion->getProducts(); $products = Product::getSimpleProducts($this->context->language->id); } } } foreach ($criterions as $key => $foo) { if ($foo['id_product_comment_criterion_type'] == 1) { unset($criterions[$key]); } } if (count($criterions)) { $this->_html .= ' <fieldset class="width2"> <legend><img src="' . $this->_path . 'img/note_go.png" alt="" title="" />' . $this->l('Manage criterions scope') . '</legend> <p style="margin-bottom: 15px;">' . $this->l('Only criterions restricted to categories or products can be configured below:') . '</p> <form action="' . Tools::safeOutput($this->_baseUrl) . '" method="post" name="product_criterion_form"> <label>' . $this->l('Criterion') . '</label> <div class="margin-form"> "> <select name="id_product_comment_criterion" id="id_product_comment_criterion" onchange="window.location=\'' . Tools::safeOutput($this->_baseUrl) . '&updateCriterion=\'+$(\'#id_product_comment_criterion option:selected\').val()"> <option value="--">-- ' . $this->l('Choose a criterion') . ' --</option>'; foreach ($criterions as $foo) { $this->_html .= '<option value="' . (int) $foo['id_product_comment_criterion'] . '" ' . ($foo['id_product_comment_criterion'] == $id_criterion ? 'selected="selected"' : '') . '>' . $foo['name'] . '</option>'; } $this->_html .= '</select> </div> </form>'; if ($id_criterion && $criterion->id_product_comment_criterion_type != 1) { $this->_html .= '<label for="id_product_comment_criterion">' . ($criterion->id_product_comment_criterion_type == 3 ? $this->l('Products') : $this->l('Categories')) . '</label> <form action="' . Tools::safeOutput($this->_baseUrl) . '" method="post" name="comment_form"> <div id="product_criterions" class="margin-form"> <input type="hidden" name="id_criterion" id="id_criterion" value="' . (int) $id_criterion . '" /> <br /><table class="table" border="0" cellspacing="0" cellpadding="0"> <thead> <tr> <th><input class="noborder" type="checkbox" name="id_product[]" onclick="checkDelBoxes(this.form, \'id_product[]\', this.checked);" /></th> <th style="width: 30px;">' . $this->l('ID') . '</th> <th style="width: 550px;">' . ($criterion->id_product_comment_criterion_type == 3 ? $this->l('Product Name') : $this->l('Category Name')) . '</th> </tr> </thead> <tbody>'; if ($criterion->id_product_comment_criterion_type == 3) { foreach ($products as $product) { $this->_html .= '<tr><td><input class="noborder" type="checkbox" value="' . (int) $product['id_product'] . '" name="id_product[]" ' . (in_array($product['id_product'], $criterion_products) ? 'checked="checked"' : '') . ' /></td> <td>' . (int) $product['id_product'] . '</td><td>' . $product['name'] . '</td></tr>'; } } else { if ($criterion->id_product_comment_criterion_type == 2) { foreach ($categories as $category) { $this->_html .= '<tr><td><input class="noborder" type="checkbox" value="' . (int) $category['id_category'] . '" name="id_product[]" ' . (in_array($category['id_category'], $criterion_categories) ? 'checked="checked"' : '') . ' /></td> <td>' . (int) $category['id_category'] . '</td><td>' . $category['name'] . '</td></tr>'; } } } $this->_html .= '</tbody> </table> </div> <div class="margin-form clear"> <input type="submit" name="submitApplicationCriterion" value="' . $this->l('Save') . '" class="button" /> </div> </form>'; } $this->_html .= '</fieldset>'; } }
public function initCategoriesAssociation($id_root = null, $id_criterion = 0) { if (is_null($id_root)) { $id_root = Configuration::get('PS_ROOT_CATEGORY'); } $id_shop = (int) Tools::getValue('id_shop'); $shop = new Shop($id_shop); if ($id_criterion == 0) { $selected_cat = array(); } else { $pdc_object = new ProductCommentCriterion($id_criterion); $selected_cat = $pdc_object->getCategories(); } if (Shop::getContext() == Shop::CONTEXT_SHOP && Tools::isSubmit('id_shop')) { $root_category = new Category($shop->id_category); } else { $root_category = new Category($id_root); } $root_category = array('id_category' => $root_category->id, 'name' => $root_category->name[$this->context->language->id]); $helper = new Helper(); return $helper->renderCategoryTree($root_category, $selected_cat, 'categoryBox', false, true); }