Skip to content
Snippets Groups Projects
Select Git revision
  • 9709d3a1a738dd8aa45b9d365b7ca80a1c7ec539
  • main default protected
  • (Gagafeee)
3 results

Item.php

Blame
  • Item.php 6.13 KiB
    <?php
    class Item{
        private string $label;
        private string $cssClassName;
        private $representation;
        private string $type;
        private string $displayName;
        private array $enchants;
    
        /**
         * @throws Exception
         */
        public function __construct($itemInfos){
            if(is_array($itemInfos)){
                // On va vérifier qu'il s'agit bien d'un tableau contenant les infos d'un item
                if(!isset($itemInfos["type"])){
                    throw new Exception("Ce tableau n'est pas un item");
                }
                $this->type = strtolower($itemInfos['type']);
    
                // L'item peut avoir des caractéristiques particulières, comme des enchantements par exemple
                if(isset($itemInfos['meta'])){
                    if(isset($itemInfos['meta']['display-name'])){
                        $displayNameJson = json_decode($itemInfos['meta']['display-name'], true);
                        $this->displayName = $displayNameJson['text'];
                    }else{
                        $this->displayName = "";
                    }
                    if(isset($itemInfos['meta']['enchants'])){
                        $this->enchants = $itemInfos['meta']['enchants'];
                    }else{
                        $this->enchants = [];
                    }
                }else{
                    $this->displayName = "";
                    $this->enchants = [];
                }
            }else{
                // Ici on a un nom d'item
                $this->type=$itemInfos;
                $this->displayName = "";
                $this->enchants = [];
            }
            // On va chercher l'item dans la table d'association des items afin de récupérer les infos
            $query = BddConn::getPdo()->prepare("SELECT * FROM site_itemsAssoc WHERE name=?");
            $query->execute(array($this->type));
            $result= $query->fetch(PDO::FETCH_ASSOC);
            $this->label = $result['label'];
            $this->cssClassName = $result['css'];
            $this->representation = $result['representation'];
        }
        
        public function getLabel(): string
        {
            return $this->label;
        }
        
        public function getCssClassName(): string
        {
            return $this->cssClassName;
        }
        
        public function getType(): string
        {
            return $this->type;
        }
    
        public function getRepresentation(): array
        {
            $return["texture"] = array();