<?php

namespace KupShop\CatalogBundle\Admin\Tabs;

use KupShop\AdminBundle\Admin\WindowTab;
use Query\Operator;

class ProductsDescriptionPlusImages extends WindowTab
{
    use \DatabaseCommunication;

    protected $title = 'flapDescriptionPlusPhotos';
    protected $template = 'window/products.description.plus.photos.tpl';

    public static function getTypes()
    {
        return [
            'products' => 1,
        ];
    }

    public static function isAllowed()
    {
        return findModule(\Modules::PRODUCTS, \Modules::SUB_DESCR_PLUS);
    }

    public function isVisible()
    {
        $qb = sqlQueryBuilder()
        ->select('COUNT(*)')
        ->from('photos_products_descr_plus_relation')
        ->where(Operator::equals(['id_product' => getVal('ID')]))
        ->execute();
        if (empty($qb->fetchColumn())) {
            return false;
        }

        return $this->getAction() != 'add';
    }

    public function getLabel()
    {
        return translate($this->title, 'products');
    }
}
