[Arcturus] Automatic exchange values

Raizer

Active Member
Feb 21, 2019
144
76
Hi Devbest members,

Tonight I was busy making something for my CMS and that is that you can easily create an exchange-value page without any difficulty.
You can find my live example here: marketplace

I can add catalog_pages in my housekeeping value manager which i want to use under my exchange value category.
(Pages is just a field in with arrays)

Code:
INSERT INTO `website_rare_values` VALUES (1, 'catalogue-rares', 'Catalogue Rares', '[348, 327]', '0');
INSERT INTO `website_rare_values` VALUES (5, 'limited-edition', 'Limited Edition', '[520, 311]', '0');

rhaj09x-Sui4inh4E8c3EA.png


You can change the value of the items when you click on the edit button
In my housekeeping it look like this:

When you change the value, the rate will automatically adjust (up/down).

Important
This is just an idea how you can do it in housekeeping, the script I am about to release only shows an array that you can use.

API
If you have no idea how to implement this, you can also use my API catalogue based on Arcturus Morningstar.
If you gonna use this, be aware that this is only shows the Morningstar catalogue with currencys (0,5,103).


@param [catalog_pages:id, [catalog_pages:id] .. (you can add as many as you want by adding a *).

Source
I'm using a QueryBuilder so you need to change the queries to get this working.
If you need some help ask me.

PHP:
<?php
new Querybuilder;

class Value
{
    public static $allItems = array();
    public static $allSubItems = array();

    /** Indexing my currencys */

    const currencys = array('duckets' => 0, 'diamonds' => 5, 'belcredits' => 103);

    public static function ifSubpageExists($id)
    {
        return QueryBuilder::table('catalog_pages')->select('id')->where('parent_id, $id)->first();
    }

    public static function getCatalogItemsByParentId($id)
    {
        return QueryBuilder::query("SELECT id from catalog_pages WHERE parent_id IN ($id)")->get();
    }

    public static function getAllCatalogItems($page_id)
    {
        return QueryBuilder::query("SELECT DISTINCT catalog_items.*, (SELECT COUNT(*) FROM items WHERE item_id = catalog_items.id) AS amount FROM catalog_items WHERE page_id IN ($page_id)")->get();
    }

    public static function getValues($values)
    {
        /** Check if page has a subpage */

        foreach($values as $page_id) {
            (!empty(self::ifSubpageExists($page_id))) ? $subPage[] = $page_id : $page[] = $page_id;
        }

       /**  Get all furni id's from page */

        if(!empty($page)) {
            self::$allItems = (self::getAllCatalogItems(join(',', array_map('intval', $page))));
        }

        /**  If page has a subpage get item id's */

        if(!empty($subPage)) {
            $catalogSubpage = self::getCatalogItemsByParentId(join(',', array_map('intval', $subPage)));
        }

        /** Get all furni id's from subpage */

        if(!empty($catalogSubpage)) {
            foreach($catalogSubpage as $items) {
                $item[] = $items->id;
            }
            self::$allSubItems = self::getAllCatalogItems(join(',', array_map('intval', $item)));
        }

        /** Merge if subpage exists otherwise return page */

        $itemList = (!empty(self::$allSubItems)) ? array_merge_recursive(self::$allItems, self::$allSubItems) : self::$allItems;

        /** Get related item data */

        foreach($itemList as $item) {
            $getCurrencys = array_flip(self::currencys);

            if($item->cost_points > 0) {
                $item->cost_points = ($item->points_type != 0) ? $item->cost_points . ' (' . ucfirst($getCurrencys[$item->points_type]) . ')' : null;
            }
        }
        return $itemList;;
    }
}

//* the numbers are the id from your catalog_pages
print_r(Value::getValues(array(69, 520)));

I will add this soon for AsteroidCMS>


Thanks!
Raizer
 
Last edited:

JayC

Always Learning
Aug 8, 2013
5,493
1,398
Looks great but a few concerns,

Are you able to be online while you redeem? If yes, how do you properly handling of the item being removed from the inventory. What happens if I reload directly after?

You can view this page without logging in. Where are you doing a search for how many of those items are in the users inventory, are you validating their session?
 

Raizer

Active Member
Feb 21, 2019
144
76
Hello Jay,

For the first one i will take a look of that,

The second one, i do nothing with sessions. Its an inner join with a count in it to see how many items stored by by item_id
 
Last edited:

JayC

Always Learning
Aug 8, 2013
5,493
1,398
Hello Jay,

For the first one i will take a look of that,

The second one, i do nothing with sessions. Its an inner join with a count in it to see how many items stored by by item_id
okay so that's not how many the user has its how many are in the game? Maybe j don't understand what this system would be used for? I assummed it wasn't just a rare value system but also allowed the users to exchange their rares for diamonds
 

Raizer

Active Member
Feb 21, 2019
144
76
okay so that's not how many the user has its how many are in the game? Maybe j don't understand what this system would be used for? I assummed it wasn't just a rare value system but also allowed the users to exchange their rares for diamonds
How many Are in game indeed. This just for your website to show all the values with a rate (up/down) based when the value changed. Exchange isnt the right word for this i think. I'm gonna use this for a online marketplace where you can buy special items with discount (also hidden items).
 
Last edited:

Users who are viewing this thread

Top