/** * Get all categories from database arranged by parents * * @param mixed $categories * @param mixed $parent * @param mixed $indent * @param mixed $include_subs * @param mixed $exclude * @param mixed $order */ public function categos_list(&$categories, $parent = 0, $indent = 0, $include_subs = true, $exclude = 0, $order = "id_cat DESC") { $db = XoopsDatabaseFactory::getDatabaseConnection(); $sql = "SELECT * FROM " . $db->prefix("shop_categories") . " WHERE parent='{$parent}' ORDER BY {$order}"; $result = $db->query($sql); while ($row = $db->fetchArray($result)) { if ($row['id_cat'] == $exclude) { continue; } $row['indent'] = $indent; $cat = new ShopCategory(); $cat->assignVars($row); $row['link'] = $cat->permalink(); $categories[] = $row; if ($include_subs) { ShopFunctions::categos_list($categories, $row['id_cat'], $indent + 1, $include_subs, $exclude); } } }
/** * Elimina una categoría de la base de datos. * Las subcategorías pertenecientes a esta categoría no son eliminadas, * sino que son asignadas a la categoría superior. */ function shop_delete_category() { global $xoopsSecurity, $xoopsModule; $cats = rmc_server_var($_POST, 'cats', array()); if (empty($cats)) { redirectMsg('categories.php', __('You must select one category at least!', 'shop'), 1); die; } if (!$xoopsSecurity->check()) { redirectMsg('categories.php', __("Session token expired!", 'mw_categories'), 1); die; } $db = XoopsDatabaseFactory::getDatabaseConnection(); $sql = "SELECT * FROM " . $db->prefix("shop_categories") . " WHERE id_cat IN (" . implode(",", $cats) . ")"; $result = $db->query($sql); while ($row = $db->fetchArray($result)) { $cat = new ShopCategory(); $cat->assignVars($row); if (!$cat->delete()) { showMessage(__('Category "%s" could not be deleted', 'shop'), 1); } } redirectMsg('categories.php', __('Database updated!', 'shop'), 0); }
/** * Devuelve los nombres de las categorías a las que pertenece * el post actual * @param bool $asList Detemina si se muestra en forma de lista o de array * @param string $delimiter Delimitador para la lista * @param bool Get names with links. Only works when $asList equal true * @param string Section for link. It can be front or admin. Only works when $asList equal true * @return string or array */ public function get_categories_names($asList = true, $delimiter = ',', $links = true, $section = 'front') { if (empty($this->lcats)) { $this->get_categos('data'); } $rtn = $asList ? '' : array(); $url = ShopFunctions::get_url(); foreach ($this->lcats as $cat) { if ($asList) { if ($links) { $category = new ShopCategory(); $category->assignVars($cat); $rtn .= $rtn == '' ? '' : "{$delimiter}"; $rtn .= '<a href="' . ($section == 'front' ? $category->permalink() : 'products.php?cat=' . $cat['id_cat']) . '">' . $cat['name'] . '</a>'; } else { $rtn .= $rtn == '' ? $cat['name'] : "{$delimiter} {$cat['name']}"; } } else { $rtn[] = $row['nombre']; } } return $rtn; }