<?php
/*************************************************************************************/
/*      This file is part of the Thelia package.                                     */
/*                                                                                   */
/*      Copyright (c) OpenStudio                                                     */
/*      email : dev@thelia.net                                                       */
/*      web : http://www.thelia.net                                                  */
/*                                                                                   */
/*      For the full copyright and license information, please view the LICENSE.txt  */
/*      file that was distributed with this source code.                             */
/*************************************************************************************/
/*************************************************************************************/

namespace ArtabanMarketplace\Loop;

use ArtabanMarketplace\Model\Map\AmpSellerAdminTableMap;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\ActiveQuery\Join;
use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Admin;
use Thelia\Model\Map\AdminTableMap;

/**
 * Class AmpAdminLoop
 * @package ArtabanMarketplace\Loop
 */
class AmpAdminLoop extends Admin
{
    /**
     * @inheritDoc
     */
    protected function getArgDefinitions()
    {
        /** @var ArgumentCollection $arguments */
        $arguments = parent::getArgDefinitions();

        $arguments->addArgument(
            Argument::createIntListTypeArgument("amp_seller_id")
        );

        return $arguments;
    }

    public function buildModelCriteria()
    {
        $query = parent::buildModelCriteria();

        if (null != $id = $this->getAmpSellerId()) {
            if (is_array($id)) {
                $id = implode(",", $id);
            }

            $ampAdminJoin = new Join(AdminTableMap::ID, AmpSellerAdminTableMap::ADMIN_ID, Criteria::LEFT_JOIN);
            $query
                ->addJoinObject($ampAdminJoin, "ampAdminJoin")
                ->where(AmpSellerAdminTableMap::AMP_SELLER_ID . " " . Criteria::IN . " (" . $id . ")");
        }

        return $query;
    }
}
