PHP code example of andanteproject / period-bundle

1. Go to this page and download the library: Download andanteproject/period-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

andanteproject / period-bundle example snippets


return [
    /// bundles...
    Andante\PeriodBundle\AndantePeriodBundle::class => ['all' => true],
    /// bundles...
];



namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use League\Period\Duration;
use League\Period\Period;
use League\Period\Sequence;

/**
 * @ORM\Entity()
 */
class Meeting
{
    /**
     * @ORM\Column(type="period", nullable=true)
     */
    private ?Period $period = null;
    
    /**
     * @ORM\Column(type="duration", nullable=true)
     */
    private ?Duration $duration = null;
    
    /**
     * @ORM\Column(type="sequence", nullable=true)
     */
    private ?Sequence $sequence = null;
}



namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use League\Period\Period;

/**
 * @ORM\Entity()
 */
class Meeting
{
    /**
     * @ORM\Embedded(class="League\Period\Period", columnPrefix="period_")
     */
    private ?Period $period = null;
}



declare(strict_types=1);

use Andante\PeriodBundle\Form\PeriodType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type;
use Symfony\Component\Form\FormBuilderInterface;

class EventType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('name', Type\TextType::class)
            ->add('period', PeriodType::class)
        ;
    }
}

$builder->add('period', PeriodType::class, [
    'default_boundary_type' => '()',
]);

$builder->add('period', PeriodType::class, [
    'boundary_type_choice' => true,
]);

$builder->add('period', PeriodType::class, [
    'start_date_child_name' => 'custom_start_date_form_child_name',
]);

$builder->add('period', PeriodType::class, [
    'end_date_child_name' => 'custom_end_date_form_child_name',
]);

$builder->add('period', PeriodType::class, [
    'boundary_type_child_name' => 'custom_boundary_type_form_child_name',
]);

use App\Form\MyDateTimeType;

$builder->add('period', PeriodType::class, [
    'start_date_form_type' => MyDateTimeType::class,
]);

use App\Form\MyDateTimeType;

$builder->add('period', PeriodType::class, [
    'end_date_form_type' => MyDateTimeType::class,
]);

$builder->add('period', PeriodType::class, [
    'start_date_options' => [
        'label' => 'A different Label',
        // + whatever option allowed by DateTimeType
    ],
]);

$builder->add('period', PeriodType::class, [
    'end_date_options' => [
        'label' => 'A different Label',
        // + whatever option allowed by DateTimeType
    ],
]);

$builder->add('period', PeriodType::class, [
    'boundary_type_options' => [
        'label' => 'A different Label',
        // + whatever option allowed by Andante\PeriodBundle\Form\BoundaryTypeChoiceType
    ],
]);

$builder->add('period', PeriodType::class, [
    'allow_null' => false,
    // Allow to trigger an error when your Period property is not nullable.
]);