<?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\Controller;

use ArtabanMarketplace\Controller\Base\BaseController;
use ArtabanMarketplace\ArtabanMarketplace as ArtabanMarketplaceModule;
use ArtabanMarketplace\Model\AmpSellerAdmin;
use ArtabanMarketplace\Model\AmpSellerAdminQuery;
use Propel\Runtime\Propel;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Thelia\Core\HttpFoundation\JsonResponse;
use Thelia\Core\Security\AccessManager;
use Thelia\Core\Security\Resource\AdminResources;
use Thelia\Tools\URL;

/**
 * Class SellerController
 * @package ArtabanMarketplace\Controller
 */
class SellerLinkAdminController extends BaseController {

    /**
     * Load an existing object from the database
     */
    protected function getExistingObject() {
        return AmpSellerAdminQuery::create()->findOneById($this->getRequest()->query->get("id"));
        //return AmpSellerAdminQuery::create()->findOneById(9);
    }

    /**
     * Hydrate the update form for this object, before passing it to the update template
     *
     * @param mixed $object
     */
    protected function hydrateObjectForm($object) {
        $data = array(
            "id" => $object->getId(),
            "admin_id" => $object->getAdminId(),
            "seller_id" => $object->getAmpSellerId(),
        );

        return $this->getUpdateForm($data);
    }

    const CONTROLLER_ENTITY_NAME = "sellerlinkadmin";

    /**
     * Use to get render of list
     * @return mixed
     */
    protected function getListRenderTemplate() {
        return $this->render("sellers");
    }

    /**
     * Use to get Edit render
     * @return mixed
     */
    protected function getEditRenderTemplate() {
        return $this->render("seller-link-admin-edit");
    }

    /**
     * Use to get Create render
     * @return mixed
     */
    protected function getCreateRenderTemplate() {
        // TODO: Implement getCreateRenderTemplate() method.
    }

    /**
     * @return mixed
     */
    protected function getObjectId($object) {
        /** @var AmpSellerAdmin $object */
        return $object->getId();
    }

    protected function redirectToListTemplate() {
        return new RedirectResponse(URL::getInstance()->absoluteUrl("/admin/module/artabanmarketplace/sellers"));
    }

    protected function redirectToEditionTemplate() {
        $id = $this->getRequest()->query->get("seller_id");
        return new RedirectResponse(URL::getInstance()->absoluteUrl("/admin/module/artabanmarketplace/seller/link/admin/edit", ["seller_id" => $id,]));
    }

   

}
