<?php
// src/AppBundle/Admin/CompagnyAdmin.php
namespace AppBundle\Admin;

use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Form\FormMapper;

use Oh\GoogleMapFormTypeBundle\Form\Type\GoogleMapType;

class JobAdmin extends AbstractAdmin
{
	//configure which fields are displayed on the edit and create actions. 
	//The FormMapper behaves similar to the FormBuilder of the Symfony Form component;
    protected function configureFormFields(FormMapper $formMapper)
    {
        $formMapper
			->with('Informations', array(
                    'class'       => 'col-md-6',
                    'box_class'   => 'box box-solid',
                    'description' => '',
                ))
			->add('name', 'text')
			->add('job_description','textarea',array('attr' => array('rows' => '12')))
			->add('sector','text',['required'=>false])
            /*,'entity', array(
				'class' => 'AppBundle\Entity\Sector',
				'choice_label' => 'name',
				'required'=>false
			))*/
			->add('company')
			->add('company_description','textarea',array('attr' => array('rows' => '8')))
			/*->add('skills',null, array(
				
			))*/
			->add('deadline','date', array(
							'placeholder' => array(
								'year' => 'Année', 'month' => 'Mois', 'day' => 'Jour'
							),
							'format' => 'd M y',
							'model_timezone' => 'Europe/Paris',
							'years' => range(Date('Y'),Date('Y')+10)
					))
			->add('contact','text',array('label'=>'Nom du contact'))
			->add('authoremail','text',array( 'label'=>'Email','required'=>false))
			->add('authorphonenumber','text',array('label'=>'Numéro de téléphone','required'=>false))
			->add('linkedinURL','text',array('label'=>'URL Linkedin','required'=>false))
			->add('published',null,array( 'data' => true,'label'=>'Publié'))
			->end();
			$formMapper->with('Localisation', array(
                    'class'       => 'col-md-6',
                    'box_class'   => 'box box-solid location-box',
                    'description' => '',
                ))
				//->add('location_adresse')
				->add('street')
				->add('number')
				->add('zip')
				->add('city')
				->add('latlng', GoogleMapType::class, array(
				'label' 		 => 'Posistion sur google map',
				'map_width'      => '100%',     // the width of the map
				'map_height'     => '350px',     // the height of the map
				'default_lat'    => 46.2043907,    // the starting position on the map
				'default_lng'    => 6.143157699, // the starting position on the map
				))
		->end();
    }

	// This method configures the filters, used to filter and sort the list of models;
    protected function configureDatagridFilters(DatagridMapper $datagridMapper)
    {
       $datagridMapper->add('id')->add('published');
	   $datagridMapper->add('name');
       $datagridMapper->add('company')
	   			->add('deadline', null, array(), 'date', array(
                'label'=>'Date limite',
            ));
       $datagridMapper->add('contact');
    }
	//Here you specify which fields are shown when all models are listed 
	//(the addIdentifier() method means that this field will link to the show/edit page of this particular model).
    protected function configureListFields(ListMapper $listMapper)
    {
        $listMapper
			->addIdentifier('id')
			->add('published',null,array('label'=>'Publié','editable' => true))
			->add('slug', 'string',array('label' => 'lien', 'template' => 'AppBundle:Admin:link_event.html.twig','path'=>'application_page_job') )

			->addIdentifier('name','string', array('label'=>'Nom'))
			->add('company','string', array('label'=>'Entreprise'))
			->add('deadline','date', array(
				'label'=>'Date limite',
                'pattern' => constant('IntlDateFormatter::SHORT'),
                'locale' => 'fr',
                'timezone' => 'Europe/Paris',
		))
			->add('contact');
    }
	
	public function toString($object)
    {
        return ($object->getName()!=null)
            ? $object->getName()
            : 'Job'; // shown in the breadcrumb on the create view
    }

	
}
?>