<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of SellerCreation
 *
 * @author Lengy Gilles
 */

namespace ArtabanMarketplace\Form;

use ArtabanMarketplace\ArtabanMarketplace;
use Symfony\Component\Validator\Constraints\NotBlank;
use Thelia\Form\BaseForm;
use Thelia\Model\Admin;
use Thelia\Model\AdminQuery;

/**
 * Class SellerAdminForm
 * @package ArtabanMarketplace\Form
 */
class SellerAdminForm extends BaseForm {

    /**
     *
     * in this function you add all the fields you need for your Form.
     * Form this you have to call add method on $this->formBuilder attribute :
     *
     * $this->formBuilder->add("name", "text")
     *   ->add("email", "email", array(
     *           "attr" => array(
     *               "class" => "field"
     *           ),
     *           "label" => "email",
     *           "constraints" => array(
     *               new \Symfony\Component\Validator\Constraints\NotBlank()
     *           )
     *       )
     *   )
     *   ->add('age', 'integer');
     *
     * @return null
     */
    protected function buildForm() {
        $this->formBuilder
                ->add("seller_id", "hidden", array(
                    "required" => true,
                    "constraints" => array(new NotBlank(),),
                    "attr" => array()
                ))
                ->add("admin_id", "choice", array(
                    "choices" => $this->getAdminSellers(),
                    "label" => $this->translator->trans("User", []),
                    "label_attr" => ["for" => "seller.admin"],
                    "attr" => array()
                ));
    }

    protected function getAdminSellers() {
        $admins = AdminQuery::create()->find();
        $retour = [0 => ""];
        /** @var ADMIN $admin */
        foreach ($admins as $admin) {
            $retour[$admin->getId()] = $admin->getFirstname() . " " . $admin->getLastname();
        }

        return $retour;
    }

    public function getName() {
        return "seller_admin_create";
    }

}
