Пример #1
0
    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>';
        }
    }
 function renderCriterionForm($id_criterion = 0)
 {
     $types = ProductCommentCriterion::getTypes();
     $query = array();
     foreach ($types as $key => $value) {
         $query[] = array('id' => $key, 'label' => $value);
     }
     $criterion = new ProductCommentCriterion((int) $id_criterion);
     $selected_categories = $criterion->getCategories();
     $product_table_values = Product::getSimpleProducts($this->context->language->id);
     $selected_products = $criterion->getProducts();
     foreach ($product_table_values as $key => $product) {
         if (false !== array_search($product['id_product'], $selected_products)) {
             $product_table_values[$key]['selected'] = 1;
         }
     }
     if (version_compare(_PS_VERSION_, '1.6', '<')) {
         $field_category_tree = array('type' => 'categories_select', 'name' => 'categoryBox', 'label' => $this->l('Criterion will be restricted to the following categories'), 'category_tree' => $this->initCategoriesAssociation(null, $id_criterion));
     } else {
         $field_category_tree = array('type' => 'categories', 'label' => $this->l('Criterion will be restricted to the following categories'), 'name' => 'categoryBox', 'desc' => $this->l('Mark the boxes of categories to which this criterion applies.'), 'tree' => array('use_search' => false, 'id' => 'categoryBox', 'use_checkbox' => true, 'selected_categories' => $selected_categories), 'values' => array('trads' => array('Root' => Category::getTopCategory(), 'selected' => $this->l('Selected'), 'Collapse All' => $this->l('Collapse All'), 'Expand All' => $this->l('Expand All'), 'Check All' => $this->l('Check All'), 'Uncheck All' => $this->l('Uncheck All')), 'selected_cat' => $selected_categories, 'input_name' => 'categoryBox[]', 'use_radio' => false, 'use_search' => false, 'disabled_categories' => array(), 'top_category' => Category::getTopCategory(), 'use_context' => true));
     }
     $fields_form_1 = array('form' => array('legend' => array('title' => $this->l('Add new criterion'), 'icon' => 'icon-cogs'), 'input' => array(array('type' => 'hidden', 'name' => 'id_product_comment_criterion'), array('type' => 'text', 'lang' => true, 'label' => $this->l('Criterion name'), 'name' => 'name'), array('type' => 'select', 'name' => 'id_product_comment_criterion_type', 'label' => $this->l('Application scope of the criterion'), 'options' => array('query' => $query, 'id' => 'id', 'name' => 'label')), $field_category_tree, array('type' => 'products', 'label' => $this->l('The criterion will be restricted to the following products'), 'name' => 'ids_product', 'values' => $product_table_values), array('type' => 'switch', 'is_bool' => true, 'label' => $this->l('Active'), 'name' => 'active', 'values' => array(array('id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled'))))), 'submit' => array('title' => $this->l('Save'), 'class' => 'btn btn-default pull-right', 'name' => 'submitEditCriterion')));
     $helper = new HelperForm();
     $helper->show_toolbar = false;
     $helper->table = $this->name;
     $lang = new Language((int) Configuration::get('PS_LANG_DEFAULT'));
     $helper->default_form_language = $lang->id;
     $helper->module = $this;
     $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
     $helper->identifier = $this->identifier;
     $helper->submit_action = 'submitEditCriterion';
     $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false) . '&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name;
     $helper->token = Tools::getAdminTokenLite('AdminModules');
     $helper->tpl_vars = array('fields_value' => $this->getCriterionFieldsValues($id_criterion), 'languages' => $this->context->controller->getLanguages(), 'id_language' => $this->context->language->id);
     return $helper->generateForm(array($fields_form_1));
 }