<?php

/* * ********************************************************************************** */
/*      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\AmpSellerAdmin;
use ArtabanMarketplace\Model\AmpSellerAdminQuery;
use ArtabanMarketplace\Model\Map\AmpSellerAdminTableMap;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\ActiveQuery\Join;
use Thelia\Core\Template\Element\BaseI18nLoop;
use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Element\PropelSearchLoopInterface;
use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;

/**
 * Class SellerAdminLoop
 * @package ArtabanMarketplace\Loop
 */
class SellerAdminLoop extends BaseI18nLoop implements PropelSearchLoopInterface {

    /**
     * @inheritDoc
     */
    protected function getArgDefinitions() {
        return new ArgumentCollection(
                Argument::createIntListTypeArgument('id'), Argument::createIntListTypeArgument('admin_id'), Argument::createIntListTypeArgument('amp_seller_id')
        );
    }

    /**
     * @param LoopResult $loopResult
     *
     * @return LoopResult
     */
    public function parseResults(LoopResult $loopResult) {
        /** @var AmpSellerAdmin $item */
        foreach ($loopResult->getResultDataCollection() as $item) {
            $loopResultRow = new LoopResultRow($item);

            $loopResultRow
                    ->set('ID', $item->getId())
                    ->set("ADMIN_ID", $item->getAdminId())
                    ->set("SELLER_ID", $item->getAmpSellerId())
                    ->set("CREATE_DATE", $item->getCreatedAt())
                    ->set("UPDATE_DATE", $item->getUpdatedAt())
            ;

            $loopResult->addRow($loopResultRow);
        }

        return $loopResult;
    }

    /**
     * @inheritdoc
     */
    public function buildModelCriteria() {
        $query = AmpSellerAdminQuery::create();

        if (null != $id = $this->getId()) {
            $query->filterById($id);
        }

        if (null != $admin_id = $this->getAdminId()) {
            $query->filterByAdminId($admin_id);
        }

        if (null != $seller_id = $this->getAmpSellerId()) {
            $query->filterByAmpSellerId($seller_id);
        }

        if ($this->getBackendContext() === true) {
            $query = $this->getAdminArtabanMarketplace($query);
        }

        return $query;
    }

}
