class MCWA_Master
{
    private static $cache = array();

    public static function get_id($master_type, $master_code)
    {
        global $wpdb;

        $master_type = strtoupper(sanitize_text_field($master_type));
        $master_code = strtoupper(sanitize_text_field($master_code));
        $cache_key   = $master_type . ':' . $master_code;

        if (isset(self::$cache[$cache_key])) {
            return (int) self::$cache[$cache_key];
        }

        $table = $wpdb->prefix . 'mcwa_master';

        $master_id = (int) $wpdb->get_var(
            $wpdb->prepare(
                "
                SELECT master_id
                FROM {$table}
                WHERE master_type = %s
                  AND master_code = %s
                LIMIT 1
                ",
                $master_type,
                $master_code
            )
        );

        self::$cache[$cache_key] = $master_id;

        return $master_id;
    }

    public static function get_name($master_id)
    {
        global $wpdb;

        $master_id = absint($master_id);

        if (!$master_id) {
            return '';
        }

        $cache_key = 'name:' . $master_id;

        if (isset(self::$cache[$cache_key])) {
            return self::$cache[$cache_key];
        }

        $table = $wpdb->prefix . 'mcwa_master';

        $name = (string) $wpdb->get_var(
            $wpdb->prepare(
                "
                SELECT master_name
                FROM {$table}
                WHERE master_id = %d
                LIMIT 1
                ",
                $master_id
            )
        );

        self::$cache[$cache_key] = $name;

        return $name;
    }

    public static function get_active_values($master_type)
    {
        global $wpdb;

        $table = $wpdb->prefix . 'mcwa_master';

        return $wpdb->get_results(
            $wpdb->prepare(
                "
                SELECT master_id, master_code, master_name
                FROM {$table}
                WHERE master_type = %s
                  AND is_active = 1
                ORDER BY sort_order, master_name
                ",
                strtoupper($master_type)
            )
        );
    }

    public static function normalize_ids($ids, $master_type)
    {
        global $wpdb;

        $ids = is_array($ids) ? $ids : explode(',', (string) $ids);
        $ids = array_values(array_unique(array_filter(array_map('absint', $ids))));

        if (!$ids) {
            return '';
        }

        $placeholders = implode(',', array_fill(0, count($ids), '%d'));
        $table        = $wpdb->prefix . 'mcwa_master';

        $params = array_merge(
            array(strtoupper($master_type)),
            $ids
        );

        $valid_ids = $wpdb->get_col(
            $wpdb->prepare(
                "
                SELECT master_id
                FROM {$table}
                WHERE master_type = %s
                  AND is_active = 1
                  AND master_id IN ({$placeholders})
                ORDER BY master_id
                ",
                $params
            )
        );

        return implode(',', array_map('intval', $valid_ids));
    }

    public static function get_names_from_ids($ids, $master_type)
    {
        global $wpdb;

        $ids = array_values(
            array_unique(
                array_filter(
                    array_map('absint', explode(',', (string) $ids))
                )
            )
        );

        if (!$ids) {
            return array();
        }

        $placeholders = implode(',', array_fill(0, count($ids), '%d'));
        $table        = $wpdb->prefix . 'mcwa_master';

        $params = array_merge(
            array(strtoupper($master_type)),
            $ids
        );

        return $wpdb->get_col(
            $wpdb->prepare(
                "
                SELECT master_name
                FROM {$table}
                WHERE master_type = %s
                  AND master_id IN ({$placeholders})
                ORDER BY sort_order, master_name
                ",
                $params
            )
        );
    }
}<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="//mirayacreations.in/main-sitemap.xsl"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
	<sitemap>
		<loc>https://mirayacreations.in/post-sitemap.xml</loc>
		<lastmod>2026-04-27T05:44:22+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://mirayacreations.in/page-sitemap.xml</loc>
		<lastmod>2026-06-18T09:13:41+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://mirayacreations.in/product-sitemap1.xml</loc>
		<lastmod>2026-06-18T20:56:04+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://mirayacreations.in/product-sitemap2.xml</loc>
		<lastmod>2026-06-18T20:56:04+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://mirayacreations.in/product-sitemap3.xml</loc>
		<lastmod>2026-06-18T20:56:04+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://mirayacreations.in/product-sitemap4.xml</loc>
		<lastmod>2026-06-18T20:56:04+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://mirayacreations.in/product-sitemap5.xml</loc>
		<lastmod>2026-06-18T20:56:04+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://mirayacreations.in/product-sitemap6.xml</loc>
		<lastmod>2026-06-18T20:56:04+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://mirayacreations.in/product-sitemap7.xml</loc>
		<lastmod>2026-06-18T20:56:04+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://mirayacreations.in/product-sitemap8.xml</loc>
		<lastmod>2026-06-18T20:56:04+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://mirayacreations.in/goal_footer-sitemap.xml</loc>
		<lastmod>2026-03-31T08:12:23+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://mirayacreations.in/goal_megamenu-sitemap.xml</loc>
		<lastmod>2024-05-28T20:28:30+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://mirayacreations.in/goal_header-sitemap.xml</loc>
		<lastmod>2026-03-25T09:20:09+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://mirayacreations.in/category-sitemap.xml</loc>
		<lastmod>2026-04-27T05:44:22+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://mirayacreations.in/product_brand-sitemap.xml</loc>
		<lastmod>2026-06-18T20:56:04+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://mirayacreations.in/product_cat-sitemap.xml</loc>
		<lastmod>2026-06-18T20:56:04+00:00</lastmod>
	</sitemap>
</sitemapindex>
<!-- XML Sitemap generated by Rank Math SEO Plugin (c) Rank Math - rankmath.com -->