<?php
/*
* This file is part of EC-CUBE
*
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
*
* http://www.ec-cube.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Customize\Form\Type\Front;
use Eccube\Common\EccubeConfig;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormError;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Customize\Repository\SchoolRepository;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
class SchoolCertificationType extends AbstractType
{
/**
* @var EccubeConfig
*/
protected $eccubeConfig;
protected $session;
/**
* @var SchoolRepository
*/
protected $schoolRepository;
/**
* EntryType constructor.
*
* @param EccubeConfig $eccubeConfig
*/
public function __construct(EccubeConfig $eccubeConfig, SchoolRepository $schoolRepository, SessionInterface $session)
{
$this->eccubeConfig = $eccubeConfig;
$this->schoolRepository = $schoolRepository;
$this->session = $session;
}
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('school_key', TextType::class, array(
'label' => '学校キー',
'attr' => [
'placeholder' => '学校キー',
],
'required' => false,
));
$School = null;
$SchoolId = $this->session->get('eccube.school');
if ($SchoolId > 0) {
$School = $this->schoolRepository->find($SchoolId);
}
if ($School == null) {
$builder->add('School', EntityType::class, array(
'required' => true,
'label' => '学校',
'class' => 'Customize\Entity\School',
'choice_label' => 'school_name',
'placeholder' => '選択してください',
'query_builder' => function (\Customize\Repository\SchoolRepository $sr) {
return $sr->createQueryBuilder('s')
->andWhere('s.visible_flg = 1')
->orderBy('s.school_order', 'ASC');
}
));
}
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
}
/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return 'school_certification';
}
}