context = $context; } /** * @param int $shotLang */ public function setShotLang($shotLang) { $this->shotLang = $shotLang; } /** * @param string $moduleImgPath */ public function setModuleImgPath($moduleImgPath) { $this->moduleImgPath = $moduleImgPath; } /** * @param array $googleCategoriesMap */ public function setGoogleCategoriesMap($googleCategoriesMap) { $this->googleCategoriesMap = $googleCategoriesMap; } /** * @param int $feedId */ public function setFeedId($feedId) { $this->feedId = $feedId; } public function save($feedId, $genderCategories) { Db::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'blmod_xml_gender_map WHERE feed_id = '.(int)$feedId); if (empty($genderCategories)) { return true; } foreach ($genderCategories as $cateogyrId => $name) { if (empty($name)) { continue; } Db::getInstance()->Execute('INSERT INTO '._DB_PREFIX_.'blmod_xml_gender_map (`feed_id`, `category_id`, `name`) VALUE ("'.(int)$feedId.'", "'.(int)$cateogyrId.'", "'.pSQL($name).'")'); } return true; } public function get($feedId) { $categories = Db::getInstance()->ExecuteS('SELECT * FROM '._DB_PREFIX_.'blmod_xml_gender_map WHERE feed_id = '.(int)$feedId); $values = []; foreach ($categories as $c) { $values[$c['category_id']] = $c['name']; } return $values; } public function categoriesTree($selected = false, $isGoogleCat = false, $checkboxName = 'categoryBox', $isGender = false) { $this->isGoogle = $isGoogleCat; $this->isGender = $isGender; $this->recurseDone = []; $langId = !empty($this->shopLang) ? $this->shopLang : $this->context->language->id; if (!empty($selected)) { $sel_array = explode(',', $selected); } else { $sel_array = []; } $margin = 'margin-right: 9px;'; $border = ''; $checkDelBoxes = "checkDelBoxes(this.form, '".$checkboxName."[]', this.checked)"; $hideMessage = '
'.$this->l('[Hide]').'
'; $selectBox = ''; $this->htmlCategory = ''; if ($this->isGoogle || $this->isGender) { $margin = ''; $border = 'border: 0px; margin-top: 6px;'; $hideMessage = ''; $selectBox = ''; } if ($this->isGender) { $this->genderValues = $this->get($this->feedId); } $this->htmlCategory .= '
'.$selectBox.' '; $categories = Category::getCategories($langId, false); if (!empty($categories)) { $categories[0][1] = isset($categories[0][1]) ? $categories[0][1] : false; $this->recurseCategoryForIncludePref(null, $categories, $categories[0][1], 1, null, $sel_array, $checkboxName); } $this->htmlCategory .= '
'.$this->l('ID').' '.$this->l('Name').'
'.$hideMessage.'
'; return $this->htmlCategory; } protected function recurseCategoryForIncludePref($indexedCategories, $categories, $current, $id_category = 1, $id_category_default = null, $selected = array(), $checkboxName = 'categoryBox') { $img_type = 'png'; static $irow; if (!isset($this->recurseDone[$current['infos']['id_parent']])) { $this->recurseDone[$current['infos']['id_parent']] = 0; } $this->recurseDone[$current['infos']['id_parent']] += 1; $categories[$current['infos']['id_parent']] = isset($categories[$current['infos']['id_parent']]) ? $categories[$current['infos']['id_parent']] : false; $todo = count($categories[$current['infos']['id_parent']]); $doneC = $this->recurseDone[$current['infos']['id_parent']]; $level = $current['infos']['level_depth'] + 1; $img = $level == 1 ? 'lv1.'.$img_type : 'lv'.$level.'_'.($todo == $doneC ? 'f' : 'b').'.'.$img_type; $levelImg = ''; if ($level > 5) { $levelSpace = (($level - 2) * 24) - 12; $levelImg = '

'; $levelImg .= '

'; } $checked = false; if (in_array($id_category, $selected)) { $checked = 'checked="yes"'; } $selectBox = ' '; $selectBoxW = ''; $inputField = ''; if ($this->isGoogle) { $selectBox = ''; $selectBoxW = 'width: 25px;'; $googleCatValue = ''; if (!empty($this->googleCategoriesMap[$id_category])) { $googleCatValue = $this->googleCategoriesMap[$id_category]['name']; } $inputField = '
'; } if ($this->isGender) { $selectBox = ''; $selectBoxW = 'width: 25px;'; $inputField = '
'; } $this->htmlCategory .= ' '.$selectBox.' '.$id_category.'
'.$levelImg.'
'.$inputField.' '; if (isset($categories[$id_category])) { foreach ($categories[$id_category] as $key => $row) { if ($key != 'infos') { $this->recurseCategoryForIncludePref($indexedCategories, $categories, $categories[$id_category][$key], $key, null, $selected, $checkboxName); } } } } protected function l($string) { return $string; } }