upgraded to symfony 4 #74 (#81)

This commit is contained in:
Kevin Papst
2018-01-12 20:39:07 +01:00
committed by GitHub
parent c011b83b73
commit a87355695e
232 changed files with 5260 additions and 4231 deletions

View File

@@ -0,0 +1,81 @@
<?php
/*
* This file is part of the Kimai package.
*
* (c) Kevin Papst <kevin@kevinpapst.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Form;
use App\Form\Type\VisibilityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use App\Entity\Activity;
use App\Form\Type\ProjectType;
use App\Repository\ProjectRepository;
/**
* Defines the form used to manipulate Activities.
*
* @author Kevin Papst <kevin@kevinpapst.de>
*/
class ActivityEditForm extends AbstractType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
/** @var Activity $entry */
$entry = $options['data'];
$project = null;
if ($entry->getId() !== null) {
$project = $entry->getProject();
}
$builder
// string - length 255
->add('name', TextType::class, [
'label' => 'label.name',
])
// text
->add('comment', TextareaType::class, [
'label' => 'label.comment',
'required' => false,
])
// entity type: project
->add('project', ProjectType::class, [
'label' => 'label.project',
'query_builder' => function (ProjectRepository $repo) use ($project) {
return $repo->builderForEntityType($project);
},
])
// boolean
->add('visible', VisibilityType::class, [
'label' => 'label.visible',
])
;
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Activity::class,
'csrf_protection' => true,
'csrf_field_name' => '_token',
'csrf_token_id' => 'admin_activity_edit',
]);
}
}

View File

@@ -0,0 +1,139 @@
<?php
/*
* This file is part of the Kimai package.
*
* (c) Kevin Papst <kevin@kevinpapst.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Form;
use App\Form\Type\VisibilityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CountryType;
use Symfony\Component\Form\Extension\Core\Type\CurrencyType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\PercentType;
use Symfony\Component\Form\Extension\Core\Type\TelType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\TimezoneType;
use Symfony\Component\Form\Extension\Core\Type\UrlType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use App\Entity\Customer;
/**
* Defines the form used to edit Customer entities.
*
* @author Kevin Papst <kevin@kevinpapst.de>
*/
class CustomerEditForm extends AbstractType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
// string - length 255
->add('name', TextType::class, [
'label' => 'label.name',
])
// text
->add('comment', TextareaType::class, [
'label' => 'label.comment',
'required' => false,
])
// do not allow project selection:
// 1. it is a bad UX
// 2. what should happen if they are detached?
/*
->add('projects', EntityType::class, [
'label' => 'label.project',
'class' => 'Kimai:Project',
'multiple' => true,
'expanded' => true
])
*/
// boolean
->add('visible', VisibilityType::class, [
'label' => 'label.visible',
])
// string - length 255
->add('company', TextType::class, [
'label' => 'label.company',
'required' => false,
])
// string - length 255
->add('vat', PercentType::class, [
'label' => 'label.vat',
'type' => 'integer',
])
// string - length 255
->add('contact', TextType::class, [
'label' => 'label.contact',
'required' => false,
])
// string - length 255
->add('address', TextareaType::class, [
'label' => 'label.address',
'required' => false,
])
// string - length 2
->add('country', CountryType::class, [
'label' => 'label.country',
])
// string - length 3
->add('currency', CurrencyType::class, [
'label' => 'label.currency',
])
// string - length 255
->add('phone', TelType::class, [
'label' => 'label.phone',
'required' => false,
])
// string - length 255
->add('fax', TelType::class, [
'label' => 'label.fax',
'required' => false,
])
// string - length 255
->add('mobile', TelType::class, [
'label' => 'label.mobile',
'required' => false,
])
// string - length 255
->add('mail', EmailType::class, [
'label' => 'label.email',
'required' => false,
])
// string - length 255
->add('homepage', UrlType::class, [
'label' => 'label.homepage',
'required' => false,
])
// string - length 255
->add('timezone', TimezoneType::class, [
'label' => 'label.timezone',
])
;
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Customer::class,
'csrf_protection' => true,
'csrf_field_name' => '_token',
'csrf_token_id' => 'admin_customer_edit',
]);
}
}

View File

@@ -0,0 +1,88 @@
<?php
/*
* This file is part of the Kimai package.
*
* (c) Kevin Papst <kevin@kevinpapst.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Form;
use App\Form\Type\VisibilityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\MoneyType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use App\Entity\Customer;
use App\Entity\Project;
use App\Form\Type\CustomerType;
use App\Repository\CustomerRepository;
/**
* Defines the form used to edit Projects.
*
* @author Kevin Papst <kevin@kevinpapst.de>
*/
class ProjectEditForm extends AbstractType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
/** @var Project $entry */
$entry = $options['data'];
$customer = null;
if ($entry->getId() !== null) {
$customer = $entry->getCustomer();
}
$builder
// string - length 255
->add('name', TextType::class, [
'label' => 'label.name',
])
// text
->add('comment', TextareaType::class, [
'label' => 'label.comment',
])
// customer
->add('customer', CustomerType::class, [
'label' => 'label.customer',
'query_builder' => function (CustomerRepository $repo) use ($customer) {
return $repo->builderForEntityType($customer);
},
])
// boolean
->add('visible', VisibilityType::class, [
'label' => 'label.visible',
])
// string
->add('budget', MoneyType::class, [
'label' => 'label.budget',
'currency' => $builder->getOption('currency'),
])
;
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Project::class,
'csrf_protection' => true,
'csrf_field_name' => '_token',
'csrf_token_id' => 'admin_project_edit',
'currency' => Customer::DEFAULT_CURRENCY,
]);
}
}

View File

@@ -0,0 +1,40 @@
<?php
/*
* This file is part of the Kimai package.
*
* (c) Kevin Papst <kevin@kevinpapst.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Form;
use App\Form\Type\UserType;
use Symfony\Component\Form\FormBuilderInterface;
/**
* Defines the form used to administrate Timesheet entries.
*
* @author Kevin Papst <kevin@kevinpapst.de>
*/
class TimesheetAdminForm extends TimesheetEditForm
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
parent::buildForm($builder, $options);
$builder
// User
->add('user', UserType::class, [
'label' => 'label.user',
])
;
}
}

View File

@@ -0,0 +1,91 @@
<?php
/*
* This file is part of the Kimai package.
*
* (c) Kevin Papst <kevin@kevinpapst.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
use Symfony\Component\Form\Extension\Core\Type\MoneyType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use App\Entity\Customer;
use App\Entity\Timesheet;
use App\Form\Type\ActivityGroupedWithCustomerNameType;
use App\Repository\ActivityRepository;
/**
* Defines the form used to manipulate Timesheet entries.
*
* @author Kevin Papst <kevin@kevinpapst.de>
*/
class TimesheetEditForm extends AbstractType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
/** @var Timesheet $entry */
$entry = $options['data'];
$activity = null;
if ($entry->getId() !== null) {
$activity = $entry->getActivity();
}
$builder
// datetime
->add('begin', DateTimeType::class, [
'label' => 'label.begin',
'date_widget' => 'single_text',
])
// datetime
->add('end', DateTimeType::class, [
'label' => 'label.end',
'date_widget' => 'single_text',
'required' => false,
])
// Activity
->add('activity', ActivityGroupedWithCustomerNameType::class, [
'label' => 'label.activity',
'query_builder' => function (ActivityRepository $repo) use ($activity) {
return $repo->builderForEntityType($activity);
},
])
// customer
->add('description', TextareaType::class, [
'label' => 'label.description',
'required' => false,
])
// string
->add('rate', MoneyType::class, [
'label' => 'label.rate',
'currency' => $builder->getOption('currency'),
])
;
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Timesheet::class,
'csrf_protection' => true,
'csrf_field_name' => '_token',
'csrf_token_id' => 'timesheet_edit',
'currency' => Customer::DEFAULT_CURRENCY,
]);
}
}

View File

@@ -0,0 +1,33 @@
<?php
/*
* This file is part of the Kimai package.
*
* (c) Kevin Papst <kevin@kevinpapst.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Form\Toolbar;
use Symfony\Component\Form\AbstractType;
/**
* Defines the base form used for all toolbars.
*
* @author Kevin Papst <kevin@kevinpapst.de>
*/
abstract class AbstractToolbarForm extends AbstractType
{
/**
* Dirty hack to enable easy handling of GET form in controller and javascript.
*Cleans up the name of all form elents (and unfortunately of the form itself).
*
* @return null|string
*/
public function getBlockPrefix()
{
return '';
}
}

View File

@@ -0,0 +1,63 @@
<?php
/*
* This file is part of the Kimai package.
*
* (c) Kevin Papst <kevin@kevinpapst.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Form\Toolbar;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use App\Form\Type\ProjectType;
use App\Repository\Query\ActivityQuery;
/**
* Defines the form used for filtering the activities.
*
* @author Kevin Papst <kevin@kevinpapst.de>
*/
class ActivityToolbarForm extends ProjectToolbarForm
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
parent::buildForm($builder, $options);
/** @var ActivityQuery $query */
$query = $options['data'];
if ($query->getCustomer() === null) {
return;
}
$choices = [];
foreach ($query->getCustomer()->getProjects() as $project) {
$choices[] = $project;
}
$builder
->add('project', ProjectType::class, [
'required' => false,
'choices' => $choices,
]);
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => ActivityQuery::class,
'csrf_protection' => false,
]);
}
}

View File

@@ -0,0 +1,36 @@
<?php
/*
* This file is part of the Kimai package.
*
* (c) Kevin Papst <kevin@kevinpapst.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Form\Toolbar;
use App\Form\Toolbar\VisibilityToolbarForm;
use Symfony\Component\OptionsResolver\OptionsResolver;
use App\Repository\Query\CustomerQuery;
/**
* Defines the form used for filtering the customer.
*
* @author Kevin Papst <kevin@kevinpapst.de>
*/
class CustomerToolbarForm extends VisibilityToolbarForm
{
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => CustomerQuery::class,
'csrf_protection' => false,
]);
}
}

View File

@@ -0,0 +1,40 @@
<?php
/*
* This file is part of the Kimai package.
*
* (c) Kevin Papst <kevin@kevinpapst.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Form\Toolbar;
use App\Form\Type\PageSizeType;
use Symfony\Component\Form\FormBuilderInterface;
use App\Repository\Query\CustomerQuery;
/**
* Defines the base form used for all toolbars with pageSizes.
*
* @author Kevin Papst <kevin@kevinpapst.de>
*/
class PagedToolbarForm extends AbstractToolbarForm
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
/** @var CustomerQuery $query */
$query = $options['data'];
$builder
->add('pageSize', PageSizeType::class, [
'required' => false,
])
;
}
}

View File

@@ -0,0 +1,60 @@
<?php
/*
* This file is part of the Kimai package.
*
* (c) Kevin Papst <kevin@kevinpapst.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Form\Toolbar;
use App\Form\Toolbar\VisibilityToolbarForm;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use App\Form\Type\CustomerType;
use App\Repository\CustomerRepository;
use App\Repository\Query\CustomerQuery;
use App\Repository\Query\ProjectQuery;
/**
* Defines the form used for filtering the projects.
*
* @author Kevin Papst <kevin@kevinpapst.de>
*/
class ProjectToolbarForm extends VisibilityToolbarForm
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
parent::buildForm($builder, $options);
$builder
->add('customer', CustomerType::class, [
'required' => false,
'query_builder' => function (CustomerRepository $repo) {
$query = new CustomerQuery();
$query->setVisibility(CustomerQuery::SHOW_BOTH); // this field is the reason for the query here
$query->setResultType(CustomerQuery::RESULT_TYPE_QUERYBUILDER);
return $repo->findByQuery($query);
},
])
;
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => ProjectQuery::class,
'csrf_protection' => false,
]);
}
}

View File

@@ -0,0 +1,81 @@
<?php
/*
* This file is part of the Kimai package.
*
* (c) Kevin Papst <kevin@kevinpapst.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Form\Toolbar;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use App\Form\Type\ActivityType;
use App\Repository\Query\TimesheetQuery;
/**
* Defines the form used for filtering the timesheet.
*
* @author Kevin Papst <kevin@kevinpapst.de>
*/
class TimesheetToolbarForm extends ActivityToolbarForm
{
/**
* @inheritdoc
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('state', ChoiceType::class, [
'label' => 'label.entryState',
'choices' => [
'entryState.all' => TimesheetQuery::STATE_ALL,
'entryState.running' => TimesheetQuery::STATE_RUNNING,
'entryState.stopped' => TimesheetQuery::STATE_STOPPED
],
])
;
parent::buildForm($builder, $options);
$this->addActivityChoice($builder, $options['data']);
$builder->remove('visibility');
}
/**
* @param FormBuilderInterface $builder
* @param TimesheetQuery $query
*/
protected function addActivityChoice(FormBuilderInterface $builder, TimesheetQuery $query)
{
if ($query->getProject() === null) {
return;
}
$choices = [];
foreach ($query->getProject()->getActivities() as $activity) {
$choices[] = $activity;
}
$builder
->add('activity', ActivityType::class, [
'required' => false,
'choices' => $choices,
]);
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => TimesheetQuery::class,
'csrf_protection' => false,
]);
}
}

View File

@@ -0,0 +1,51 @@
<?php
/*
* This file is part of the Kimai package.
*
* (c) Kevin Papst <kevin@kevinpapst.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Form\Toolbar;
use App\Form\Type\UserRoleType;
use App\Repository\Query\UserQuery;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
/**
* Defines the form used for filtering the user.
*
* @author Kevin Papst <kevin@kevinpapst.de>
*/
class UserToolbarForm extends VisibilityToolbarForm
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
parent::buildForm($builder, $options);
$builder
->add('role', UserRoleType::class, [
'required' => false,
])
;
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => UserQuery::class,
'csrf_protection' => false,
]);
}
}

View File

@@ -0,0 +1,38 @@
<?php
/*
* This file is part of the Kimai package.
*
* (c) Kevin Papst <kevin@kevinpapst.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Form\Toolbar;
use App\Form\Type\VisibilityType;
use Symfony\Component\Form\FormBuilderInterface;
/**
* Defines the form used for filtering entities with a "visibility" field.
*
* @author Kevin Papst <kevin@kevinpapst.de>
*/
class VisibilityToolbarForm extends PagedToolbarForm
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
parent::buildForm($builder, $options);
$builder
->add('visibility', VisibilityType::class, [
'required' => false,
])
;
}
}

View File

@@ -0,0 +1,43 @@
<?php
/*
* This file is part of the Kimai package.
*
* (c) Kevin Papst <kevin@kevinpapst.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Form\Type;
use App\Entity\Activity;
/**
* Custom form field type to select an activity which are grouped by their Projects, preceeded by their customer names.
*
* @author Kevin Papst <kevin@kevinpapst.de>
*/
class ActivityGroupedWithCustomerNameType extends ActivityType
{
/**
* @param Activity $activity
* @param $key
* @param $index
* @return string
*/
public function groupBy(Activity $activity, $key, $index)
{
return $activity->getProject()->getCustomer()->getName();
}
/**
* @param Activity $activity
* @return string
*/
public function choiceLabel(Activity $activity)
{
return $activity->getProject()->getName() . ': ' . $activity->getName();
}
}

View File

@@ -0,0 +1,67 @@
<?php
/*
* This file is part of the Kimai package.
*
* (c) Kevin Papst <kevin@kevinpapst.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Form\Type;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use App\Entity\Activity;
use App\Repository\ActivityRepository;
/**
* Custom form field type to select an activity.
*
* @author Kevin Papst <kevin@kevinpapst.de>
*/
class ActivityType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function groupBy(Activity $activity, $key, $index)
{
return '[' . $activity->getProject()->getId() . '] ' . $activity->getProject()->getName();
}
/**
* {@inheritdoc}
*/
public function choiceLabel(Activity $activity)
{
return $activity->getName();
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'label' => 'label.activity',
'class' => 'Kimai:Activity',
'choice_label' => [$this, 'choiceLabel'],
'group_by' => [$this, 'groupBy'],
'query_builder' => function (ActivityRepository $repo) {
return $repo->builderForEntityType(null);
},
]);
}
/**
* {@inheritdoc}
*/
public function getParent()
{
return EntityType::class;
}
}

View File

@@ -0,0 +1,50 @@
<?php
/*
* This file is part of the Kimai package.
*
* (c) Kevin Papst <kevin@kevinpapst.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Form\Type;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use App\Repository\CustomerRepository;
use App\Repository\Query\CustomerQuery;
/**
* Custom form field type to select a customer.
*
* @author Kevin Papst <kevin@kevinpapst.de>
*/
class CustomerType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'label' => 'label.customer',
'class' => 'Kimai:Customer',
'choice_label' => 'name',
'query_builder' => function (CustomerRepository $repo) {
return $repo->builderForEntityType(null);
},
]);
}
/**
* {@inheritdoc}
*/
public function getParent()
{
return EntityType::class;
}
}

View File

@@ -0,0 +1,66 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Form\Type;
use App\Utils\MomentFormatConverter;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\OptionsResolver;
/**
* Defines the custom form field type used to manipulate datetime values across
* Bootstrap Date\Time Picker javascript plugin.
* See http://symfony.com/doc/current/cookbook/form/create_custom_field_type.html
*
* @author Yonel Ceruto <yonelceruto@gmail.com>
*/
class DateTimePickerType extends AbstractType
{
/**
* @var MomentFormatConverter
*/
private $formatConverter;
public function __construct()
{
$this->formatConverter = new MomentFormatConverter();
}
/**
* {@inheritdoc}
*/
public function buildView(FormView $view, FormInterface $form, array $options)
{
$view->vars['attr']['data-date-format'] = $this->formatConverter->convert($options['format']);
$view->vars['attr']['data-date-locale'] = \Locale::getDefault();
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'widget' => 'single_text',
]);
}
/**
* {@inheritdoc}
*/
public function getParent()
{
return DateTimeType::class;
}
}

View File

@@ -0,0 +1,46 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Intl\Intl;
use Symfony\Component\OptionsResolver\OptionsResolver;
/**
* Custom form field type to select the language.
*
* @author Kevin Papst <kevin@kevinpapst.de>
*/
class LanguageType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'choices' => array(
Intl::getLocaleBundle()->getLocaleName('de', 'de') => 'de'
)
]);
}
/**
* {@inheritdoc}
*/
public function getParent()
{
return ChoiceType::class;
}
}

View File

@@ -0,0 +1,44 @@
<?php
/*
* This file is part of the Kimai package.
*
* (c) Kevin Papst <kevin@kevinpapst.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\OptionsResolver\OptionsResolver;
/**
* Custom form field type to select a page size.
*
* @author Kevin Papst <kevin@kevinpapst.de>
*/
class PageSizeType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'label' => 'label.pageSize',
'choices' => [10 => 10, 25 => 25, 50 => 50, 75 => 75, 100 => 100],
]);
}
/**
* {@inheritdoc}
*/
public function getParent()
{
return ChoiceType::class;
}
}

View File

@@ -0,0 +1,54 @@
<?php
/*
* This file is part of the Kimai package.
*
* (c) Kevin Papst <kevin@kevinpapst.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Form\Type;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use App\Entity\Project;
use App\Repository\ProjectRepository;
use App\Repository\Query\ProjectQuery;
/**
* Custom form field type to select a project.
*
* @author Kevin Papst <kevin@kevinpapst.de>
*/
class ProjectType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'label' => 'label.project',
'class' => 'Kimai:Project',
'choice_label' => 'name',
'group_by' => function (Project $project, $key, $index) {
return $project->getCustomer()->getName();
},
'query_builder' => function (ProjectRepository $repo) {
return $repo->builderForEntityType(null);
},
]);
}
/**
* {@inheritdoc}
*/
public function getParent()
{
return EntityType::class;
}
}

View File

@@ -0,0 +1,67 @@
<?php
/*
* This file is part of the Kimai package.
*
* (c) Kevin Papst <kevin@kevinpapst.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\OptionsResolver\OptionsResolver;
/**
* Custom form field type to select a user role.
*
* @author Kevin Papst <kevin@kevinpapst.de>
*/
class UserRoleType extends AbstractType
{
/**
* @var string[]
*/
protected $roles = [];
/**
* UserRolesType constructor.
* @param string[] $roles
*/
public function __construct(array $roles = [])
{
$this->roles = $roles;
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$roles = [];
foreach ($this->roles as $key => $value) {
$roles[$key] = $key;
foreach ($value as $value2) {
$roles[$value2] = $value2;
}
}
$resolver->setDefaults([
'label' => 'label.roles',
'choices' => $roles,
]);
}
/**
* {@inheritdoc}
*/
public function getParent()
{
return ChoiceType::class;
}
}

View File

@@ -0,0 +1,50 @@
<?php
/*
* This file is part of the Kimai package.
*
* (c) Kevin Papst <kevin@kevinpapst.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Form\Type;
use App\Entity\User;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsResolver\OptionsResolver;
/**
* Custom form field type to select a user.
*
* @author Kevin Papst <kevin@kevinpapst.de>
*/
class UserType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'class' => 'Kimai:User',
'choice_label' => function (User $user) {
if (!empty($user->getAlias())) {
return $user->getAlias() . ' (' . $user->getUsername() . ')';
}
return $user->getUsername();
},
]);
}
/**
* {@inheritdoc}
*/
public function getParent()
{
return EntityType::class;
}
}

View File

@@ -0,0 +1,48 @@
<?php
/*
* This file is part of the Kimai package.
*
* (c) Kevin Papst <kevin@kevinpapst.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Form\Type;
use App\Repository\Query\VisibilityQuery;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\OptionsResolver\OptionsResolver;
/**
* Custom form field type to select a visibility.
*
* @author Kevin Papst <kevin@kevinpapst.de>
*/
class VisibilityType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'label' => 'label.visible',
'choices' => [
'yes' => VisibilityQuery::SHOW_VISIBLE,
'no' => VisibilityQuery::SHOW_HIDDEN,
],
]);
}
/**
* {@inheritdoc}
*/
public function getParent()
{
return ChoiceType::class;
}
}

View File

@@ -0,0 +1,45 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\OptionsResolver\OptionsResolver;
/**
* Custom form field type to select between Yes and No.
*
* @author Kevin Papst <kevin@kevinpapst.de>
*/
class YesNoType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'choices' => ['yes' => true, 'no' => false],
'multiple' => false,
'expanded' => true,
]);
}
/**
* {@inheritdoc}
*/
public function getParent()
{
return ChoiceType::class;
}
}

View File

@@ -0,0 +1,56 @@
<?php
/*
* This file is part of the Kimai package.
*
* (c) Kevin Papst <kevin@kevinpapst.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Form;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
/**
* Defines the form used to create Users.
*
* @author Kevin Papst <kevin@kevinpapst.de>
*/
class UserCreateType extends UserEditType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('username', null, [
'label' => 'label.username',
'required' => true
])
->add('plainPassword', RepeatedType::class, [
'required' => true,
'type' => PasswordType::class,
'first_options' => array('label' => 'security.label.password'),
'second_options' => array('label' => 'security.label.password_repeat'),
]);
parent::buildForm($builder, $options);
}
/**
* {@inheritdoc}
*/
public function __configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'class' => 'Kimai:User',
]);
}
}

78
src/Form/UserEditType.php Normal file
View File

@@ -0,0 +1,78 @@
<?php
/*
* This file is part of the Kimai package.
*
* (c) Kevin Papst <kevin@kevinpapst.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Form;
use App\Entity\User;
use App\Form\Type\LanguageType;
use App\Form\Type\YesNoType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
/**
* Defines the form used to edit the profile of a User.
*
* @author Kevin Papst <kevin@kevinpapst.de>
*/
class UserEditType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
// string - length 160
->add('alias', TextType::class, [
'label' => 'label.alias',
'required' => false,
])
// string - length 50
->add('title', TextType::class, [
'label' => 'label.title',
'required' => false,
])
// string - length 255
->add('avatar', TextType::class, [
'label' => 'label.avatar',
'required' => false,
])
// string - length 160
->add('email', TextType::class, [
'label' => 'label.email',
])
// string - length 5
->add('language', LanguageType::class, [
'label' => 'label.language',
])
// boolean
->add('active', YesNoType::class, [
'label' => 'label.active',
])
;
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => User::class,
'csrf_protection' => true,
'csrf_field_name' => '_token',
'csrf_token_id' => 'edit_user_profile',
]);
}
}

View File

@@ -0,0 +1,55 @@
<?php
/*
* This file is part of the Kimai package.
*
* (c) Kevin Papst <kevin@kevinpapst.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Form;
use App\Entity\User;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
/**
* Defines the form used to create and manipulate Users.
*
* @author Kevin Papst <kevin@kevinpapst.de>
*/
class UserPasswordType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('plainPassword', RepeatedType::class, [
'type' => PasswordType::class,
'first_options' => array('label' => 'security.label.password'),
'second_options' => array('label' => 'security.label.password_repeat'),
])
;
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => User::class,
'csrf_protection' => true,
'csrf_field_name' => '_token',
'csrf_token_id' => 'edit_user_password',
]);
}
}

View File

@@ -0,0 +1,53 @@
<?php
/*
* This file is part of the Kimai package.
*
* (c) Kevin Papst <kevin@kevinpapst.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Form;
use App\Entity\User;
use App\Form\Type\UserRoleType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
/**
* Defines the form used to set roles for a User.
*
* @author Kevin Papst <kevin@kevinpapst.de>
*/
class UserRolesType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
// string[]
->add('roles', UserRoleType::class, [
'label' => 'label.roles',
'multiple' => true,
])
;
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => User::class,
'csrf_protection' => true,
'csrf_field_name' => '_token',
'csrf_token_id' => 'edit_user_roles',
]);
}
}