<?php

namespace YSquare\GiftCert\Model;

use OxidEsales\Eshop\Core\Registry;

class Article extends Article_parent{

    /**
     * Check if the article is a gift certificate
     * @return bool
     */
    public function isGiftCertArticle(){
        // Is the article itself a giftcert article?
        // Well then we go for it
        if($this->oxarticles__ys_giftcert->value > 0){
            return true;
        }

        // If the article is a child and the parent is a giftcert
        // we also treat the child as a giftcert
        $oParent = $this->getParentArticle();
        if($oParent && $oParent->oxarticles__ys_giftcert->value > 0){
            return true;
        }

        return false;
    }

    public function isOfflineGiftCert() {
        // Is this article marked as an explicit offline giftcert...
        if($this->oxarticles__ys_giftcert_offline->value > 0){
            return true;
        }

        // ... or is his parent ...
        $oParent = $this->getParentArticle();
        if($oParent && $oParent->oxarticles__ys_giftcert_offline->value > 0){
            return true;
        }

        // ... or not at all?
        return false;
    }

    public function isBusinessGiftCert() {
        // Is this article marked as an explicit business giftcert...
        if($this->oxarticles__ys_giftcert_business->value > 0){
            return true;
        }

        // ... or is his parent ...
        $oParent = $this->getParentArticle();
        if($oParent && $oParent->oxarticles__ys_giftcert_business->value > 0){
            return true;
        }

        // ... or not at all?
        return false;
    }

    public function getMinGiftcertValue() {
        $value = Registry::getConfig()->getConfigParam('dYsGiftcertMinValue');
        $value = round($value,2);
        return $value;
    }

    public function getPictureGallery() {
        // TODO Make position configurable

        $pictureGallery = parent::getPictureGallery();
        $icons = $pictureGallery["Icons"];
        $pics = $pictureGallery["Pics"];

        unset($icons[12]);
        unset($pics[12]);

        $pictureGallery["Icons"] = $icons;
        $pictureGallery["Pics"] = $pics;
        return $pictureGallery;
    }
}