@@ -20,7 +20,7 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
|||||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
|
||||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
|
||||||
use TimesheetBundle\Form\CustomerEditForm;
|
use TimesheetBundle\Form\CustomerEditForm;
|
||||||
use TimesheetBundle\Form\CustomerToolbarForm;
|
use TimesheetBundle\Form\Toolbar\CustomerToolbarForm;
|
||||||
use TimesheetBundle\Repository\Query\CustomerQuery;
|
use TimesheetBundle\Repository\Query\CustomerQuery;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -40,7 +40,7 @@ class CustomerController extends AbstractController
|
|||||||
*/
|
*/
|
||||||
protected function getQueryForRequest(Request $request)
|
protected function getQueryForRequest(Request $request)
|
||||||
{
|
{
|
||||||
$visibility = $request->get('visibility');
|
$visibility = $request->get('visibility', CustomerQuery::SHOW_VISIBLE);
|
||||||
if (strlen($visibility) == 0 || (int)$visibility != $visibility) {
|
if (strlen($visibility) == 0 || (int)$visibility != $visibility) {
|
||||||
$visibility = CustomerQuery::SHOW_BOTH;
|
$visibility = CustomerQuery::SHOW_BOTH;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
|
|||||||
use TimesheetBundle\Entity\Customer;
|
use TimesheetBundle\Entity\Customer;
|
||||||
use TimesheetBundle\Entity\Project;
|
use TimesheetBundle\Entity\Project;
|
||||||
use TimesheetBundle\Form\Type\CustomerType;
|
use TimesheetBundle\Form\Type\CustomerType;
|
||||||
|
use TimesheetBundle\Repository\CustomerRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines the form used to edit Projects.
|
* Defines the form used to edit Projects.
|
||||||
@@ -35,6 +36,14 @@ class ProjectEditForm extends AbstractType
|
|||||||
*/
|
*/
|
||||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||||
{
|
{
|
||||||
|
/** @var Project $entry */
|
||||||
|
$entry = $options['data'];
|
||||||
|
|
||||||
|
$customer = null;
|
||||||
|
if ($entry->getId() !== null) {
|
||||||
|
$customer = $entry->getCustomer();
|
||||||
|
}
|
||||||
|
|
||||||
$builder
|
$builder
|
||||||
// string - length 255
|
// string - length 255
|
||||||
->add('name', TextType::class, [
|
->add('name', TextType::class, [
|
||||||
@@ -47,6 +56,9 @@ class ProjectEditForm extends AbstractType
|
|||||||
// customer
|
// customer
|
||||||
->add('customer', CustomerType::class, [
|
->add('customer', CustomerType::class, [
|
||||||
'label' => 'label.customer',
|
'label' => 'label.customer',
|
||||||
|
'query_builder' => function (CustomerRepository $repo) use ($customer) {
|
||||||
|
return $repo->builderForEntityType($customer);
|
||||||
|
},
|
||||||
])
|
])
|
||||||
// boolean
|
// boolean
|
||||||
->add('visible', VisibilityType::class, [
|
->add('visible', VisibilityType::class, [
|
||||||
@@ -57,17 +69,6 @@ class ProjectEditForm extends AbstractType
|
|||||||
'label' => 'label.budget',
|
'label' => 'label.budget',
|
||||||
'currency' => $builder->getOption('currency'),
|
'currency' => $builder->getOption('currency'),
|
||||||
])
|
])
|
||||||
// do not allow activity selection as this causes headaches:
|
|
||||||
// 1. it is a bad UX
|
|
||||||
// 2. what should happen if they are detached?
|
|
||||||
/*
|
|
||||||
->add('activities', EntityType::class, [
|
|
||||||
'label' => 'label.activity',
|
|
||||||
'class' => 'TimesheetBundle:Activity',
|
|
||||||
'multiple' => true,
|
|
||||||
'expanded' => true
|
|
||||||
])
|
|
||||||
*/
|
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,10 +35,7 @@ class CustomerType extends AbstractType
|
|||||||
'class' => 'TimesheetBundle:Customer',
|
'class' => 'TimesheetBundle:Customer',
|
||||||
'choice_label' => 'name',
|
'choice_label' => 'name',
|
||||||
'query_builder' => function (CustomerRepository $repo) {
|
'query_builder' => function (CustomerRepository $repo) {
|
||||||
$query = new CustomerQuery();
|
return $repo->builderForEntityType(null);
|
||||||
$query->setVisibility(CustomerQuery::SHOW_BOTH);
|
|
||||||
$query->setResultType(CustomerQuery::RESULT_TYPE_QUERYBUILDER);
|
|
||||||
return $repo->findByQuery($query);
|
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,6 +50,20 @@ class CustomerRepository extends AbstractRepository
|
|||||||
return $stats;
|
return $stats;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a query builder that is used for CustomerType and your own 'query_builder' option.
|
||||||
|
*
|
||||||
|
* @param Customer|null $entity
|
||||||
|
* @return \Doctrine\ORM\QueryBuilder
|
||||||
|
*/
|
||||||
|
public function builderForEntityType(Customer $entity = null)
|
||||||
|
{
|
||||||
|
$query = new CustomerQuery();
|
||||||
|
$query->setHiddenEntity($entity);
|
||||||
|
$query->setResultType(CustomerQuery::RESULT_TYPE_QUERYBUILDER);
|
||||||
|
return $this->findByQuery($query);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param CustomerQuery $query
|
* @param CustomerQuery $query
|
||||||
* @return \Doctrine\ORM\QueryBuilder|\Pagerfanta\Pagerfanta
|
* @return \Doctrine\ORM\QueryBuilder|\Pagerfanta\Pagerfanta
|
||||||
@@ -64,6 +78,12 @@ class CustomerRepository extends AbstractRepository
|
|||||||
|
|
||||||
if ($query->getVisibility() == CustomerQuery::SHOW_VISIBLE) {
|
if ($query->getVisibility() == CustomerQuery::SHOW_VISIBLE) {
|
||||||
$qb->andWhere('c.visible = 1');
|
$qb->andWhere('c.visible = 1');
|
||||||
|
|
||||||
|
/** @var Customer $entity */
|
||||||
|
$entity = $query->getHiddenEntity();
|
||||||
|
if ($entity!== null) {
|
||||||
|
$qb->orWhere('c.id = :customer')->setParameter('customer', $entity);
|
||||||
|
}
|
||||||
} elseif ($query->getVisibility() == CustomerQuery::SHOW_HIDDEN) {
|
} elseif ($query->getVisibility() == CustomerQuery::SHOW_HIDDEN) {
|
||||||
$qb->andWhere('c.visible = 0');
|
$qb->andWhere('c.visible = 0');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user