From a23e7dc2c26135a65330acec16caf991d59ed837 Mon Sep 17 00:00:00 2001 From: Marion Muszynski Date: Thu, 15 Dec 2016 17:30:05 +0100 Subject: [PATCH] add module --- .../AdminAntCreationcategories.php | 204 ++++++++++++++++++ .../ant_creationcategories.php | 40 ++++ 2 files changed, 244 insertions(+) create mode 100644 modules/ant_creationcategories/AdminAntCreationcategories.php create mode 100644 modules/ant_creationcategories/ant_creationcategories.php diff --git a/modules/ant_creationcategories/AdminAntCreationcategories.php b/modules/ant_creationcategories/AdminAntCreationcategories.php new file mode 100644 index 00000000..70b870d5 --- /dev/null +++ b/modules/ant_creationcategories/AdminAntCreationcategories.php @@ -0,0 +1,204 @@ +id_parent = 1; + $category->active = 1; + $category->name[2] = $name; + $category->name[3] = $name; + $category->description[2] = $date; + $category->description[3] = $date; + + if($category->add()) { + if(Tools::getValue('subcategories')) { + $subcategories = Tools::getValue('subcategories'); + $subcategories = explode(',',$subcategories); + foreach ($subcategories as $key => $name) { + $subcategory = new Category(); + $subcategory->id_parent = $category->id; + $subcategory->active = 1; + $subcategory->name[2] = $name; + $subcategory->name[3] = $name; + $subcategory->description[2] = $date; + $subcategory->description[3] = $date; + $subcategory->add(); + } + } + } + Category::regenerateEntireNtree(); + HelperFormBootstrap::echoConfirmation('Catégories créées'); + } + } elseif(Tools::isSubmit('submitAddSubCategories')) { + if(Tools::getValue('id_parent')) { + $id_parent = (int) Tools::getValue('id_parent'); + if(Tools::getValue('subcategories2')) { + $subcategories = Tools::getValue('subcategories2'); + $subcategories = explode(',',$subcategories); + foreach ($subcategories as $key => $name) { + $subcategory = new Category(); + $subcategory->id_parent = $id_parent; + $subcategory->active = 1; + $subcategory->name[2] = $name; + $subcategory->name[3] = $name; + $subcategory->description[2] = $date; + $subcategory->description[3] = $date; + $subcategory->add(); + } + Category::regenerateEntireNtree(); + HelperFormBootstrap::echoConfirmation('Sous catégories créées'); + } else { + HelperFormBootstrap::echoError('Vous devez renseigner au moins une sous catégorie'); + } + } else { + HelperFormBootstrap::echoError('Vous devez selectionner une catégorie parente'); + } + } + } + + public function display() { + global $cookie, $currentIndex; + + $form = ''; + + $base_link = $currentIndex . '&token='.Tools::getAdminTokenLite('AdminAntCreationcategories'); + $helperForm = new HelperFormBootstrap(); + $helperForm->_inputTag = true; + $helperForm->_select2 = true; + + $id_categories = array(); + foreach(Db::getInstance()->ExecuteS(' + SELECT c.`id_category`, cl.`name` + FROM `'._DB_PREFIX_.'category` c + LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (cl.`id_category` = c.`id_category`) + WHERE cl.`id_lang` = '.$cookie->id_lang.' + AND c.active = 1 + ORDER BY c.`id_category` DESC + ') as $row) { + $id_categories[] = array( + 'label' => '#'.$row['id_category'].' - '.$row['name'], + 'value' => (int) $row['id_category'] + ); + } + $helperForm->_forms = array( + array( + 'action' => $base_link, + 'title' => $this->l('Creation Catégories'), + 'icon' => ' ', + 'class' => 'form-horizontal', + 'class_div' => 'col-md-12', + 'information' => 'Création de catégories multiples', + 'sections' => array( + array( + 'inputs' => array( + array( + 'type' => 'simpleText', + 'label' => $this->l('Catégorie : '), + 'label-class' => 'col-md-2', + 'input-class' => 'col-md-6', + 'name' => 'category', + ), + array( + 'type' => 'tag', + 'label' => $this->l('Sous Catégorie : '), + 'label-class' => 'col-md-2', + 'input-class' => 'col-md-6', + 'name' => 'subcategories', + 'id_tag' => 'tag_subcategories', + ), + ), + ), + ), + 'actions' => array( + array( + 'type' => 'submit', + 'class' => 'btn-primary', + 'name' => 'submitAddCategories', + 'value' => $this->l('Ajouter les catégories') + ) + ), + 'actions-class' => 'text-right', + ), + array( + 'action' => $base_link, + 'title' => $this->l('Creation Sous Catégories'), + 'icon' => ' ', + 'class' => 'form-horizontal', + 'class_div' => 'col-md-12', + 'information' => 'Création de sous-catégories ayant un parent existant', + 'sections' => array( + array( + 'inputs' => array( + array( + 'type' => 'select2', + 'label' => $this->l('Catégorie Parente'), + 'select-class' => 'col-md-6', + 'label-class' => 'col-md-2', + 'options' => $id_categories, + 'name' => 'id_parent', + ), + array( + 'type' => 'tag', + 'label' => $this->l('Sous Catégorie : '), + 'label-class' => 'col-md-2', + 'input-class' => 'col-md-6', + 'name' => 'subcategories2', + 'id_tag' => 'tag_subcategories2', + ), + ), + ), + ), + 'actions' => array( + array( + 'type' => 'submit', + 'class' => 'btn-primary', + 'name' => 'submitAddSubCategories', + 'value' => $this->l('Ajouter les sous catégories') + ) + ), + 'actions-class' => 'text-right', + ) + ); + $helperForm->_js .=' + '; + $form .= $helperForm->renderStyle(); + $form .= '
'.$helperForm->renderForm(false, NULL, NULL, true).'
'; + $form .= $helperForm->renderScript(); + + echo $form; + } +} \ No newline at end of file diff --git a/modules/ant_creationcategories/ant_creationcategories.php b/modules/ant_creationcategories/ant_creationcategories.php new file mode 100644 index 00000000..3eaedf68 --- /dev/null +++ b/modules/ant_creationcategories/ant_creationcategories.php @@ -0,0 +1,40 @@ +name = 'ant_creationcategories'; + $this->tab = 'administration'; + $this->author = 'Antadis'; + $this->version = '1.0'; + $this->need_instance = 0; + + parent::__construct(); + + $this->displayName = $this->l('Creation de catégories multiple'); + $this->description = $this->l('Permet de créer une catégorie et ses sous catégories en même temps'); + } + + public function install() + { + + if(!(parent::install())) { + return false; + } + return true; + } + + public function uninstall() { + + if(parent::uninstall() == false) { + return false; + } + + return true; + } + +}