@@ -14,7 +14,6 @@ namespace TimesheetBundle\Controller\Admin;
|
|||||||
use AppBundle\Controller\AbstractController;
|
use AppBundle\Controller\AbstractController;
|
||||||
use Pagerfanta\Pagerfanta;
|
use Pagerfanta\Pagerfanta;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use TimesheetBundle\Entity\Activity;
|
|
||||||
use TimesheetBundle\Entity\Customer;
|
use TimesheetBundle\Entity\Customer;
|
||||||
use TimesheetBundle\Entity\Project;
|
use TimesheetBundle\Entity\Project;
|
||||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
|
||||||
@@ -22,7 +21,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\ProjectEditForm;
|
use TimesheetBundle\Form\ProjectEditForm;
|
||||||
use TimesheetBundle\Form\ProjectToolbarForm;
|
use TimesheetBundle\Form\Toolbar\ProjectToolbarForm;
|
||||||
use TimesheetBundle\Repository\Query\ProjectQuery;
|
use TimesheetBundle\Repository\Query\ProjectQuery;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -41,7 +40,7 @@ class ProjectController extends AbstractController
|
|||||||
*/
|
*/
|
||||||
protected function getQueryForRequest(Request $request)
|
protected function getQueryForRequest(Request $request)
|
||||||
{
|
{
|
||||||
$visibility = $request->get('visibility');
|
$visibility = $request->get('visibility', ProjectQuery::SHOW_VISIBLE);
|
||||||
if (strlen($visibility) == 0 || (int)$visibility != $visibility) {
|
if (strlen($visibility) == 0 || (int)$visibility != $visibility) {
|
||||||
$visibility = ProjectQuery::SHOW_BOTH;
|
$visibility = ProjectQuery::SHOW_BOTH;
|
||||||
}
|
}
|
||||||
@@ -59,6 +58,7 @@ class ProjectController extends AbstractController
|
|||||||
->setPageSize($pageSize)
|
->setPageSize($pageSize)
|
||||||
->setVisibility($visibility)
|
->setVisibility($visibility)
|
||||||
->setCustomer($customer)
|
->setCustomer($customer)
|
||||||
|
->setExclusiveVisibility(true)
|
||||||
;
|
;
|
||||||
|
|
||||||
return $query ;
|
return $query ;
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ use Symfony\Component\Form\FormBuilderInterface;
|
|||||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
use TimesheetBundle\Entity\Activity;
|
use TimesheetBundle\Entity\Activity;
|
||||||
use TimesheetBundle\Form\Type\ProjectType;
|
use TimesheetBundle\Form\Type\ProjectType;
|
||||||
|
use TimesheetBundle\Repository\ProjectRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines the form used to manipulate Activities.
|
* Defines the form used to manipulate Activities.
|
||||||
@@ -33,6 +34,14 @@ class ActivityEditForm extends AbstractType
|
|||||||
*/
|
*/
|
||||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||||
{
|
{
|
||||||
|
/** @var Activity $entry */
|
||||||
|
$entry = $options['data'];
|
||||||
|
|
||||||
|
$project = null;
|
||||||
|
if ($entry->getId() !== null) {
|
||||||
|
$project = $entry->getProject();
|
||||||
|
}
|
||||||
|
|
||||||
$builder
|
$builder
|
||||||
// string - length 255
|
// string - length 255
|
||||||
->add('name', TextType::class, [
|
->add('name', TextType::class, [
|
||||||
@@ -46,6 +55,9 @@ class ActivityEditForm extends AbstractType
|
|||||||
// entity type: project
|
// entity type: project
|
||||||
->add('project', ProjectType::class, [
|
->add('project', ProjectType::class, [
|
||||||
'label' => 'label.project',
|
'label' => 'label.project',
|
||||||
|
'query_builder' => function (ProjectRepository $repo) use ($project) {
|
||||||
|
return $repo->builderForEntityType($project);
|
||||||
|
},
|
||||||
])
|
])
|
||||||
// boolean
|
// boolean
|
||||||
->add('visible', VisibilityType::class, [
|
->add('visible', VisibilityType::class, [
|
||||||
|
|||||||
@@ -36,13 +36,10 @@ class ProjectType extends AbstractType
|
|||||||
'class' => 'TimesheetBundle:Project',
|
'class' => 'TimesheetBundle:Project',
|
||||||
'choice_label' => 'name',
|
'choice_label' => 'name',
|
||||||
'group_by' => function (Project $project, $key, $index) {
|
'group_by' => function (Project $project, $key, $index) {
|
||||||
return '[' . $project->getCustomer()->getId() . '] ' . $project->getCustomer()->getName();
|
return $project->getCustomer()->getName();
|
||||||
},
|
},
|
||||||
'query_builder' => function (ProjectRepository $repo) {
|
'query_builder' => function (ProjectRepository $repo) {
|
||||||
$query = new ProjectQuery();
|
return $repo->builderForEntityType(null);
|
||||||
$query->setVisibility(ProjectQuery::SHOW_BOTH);
|
|
||||||
$query->setResultType(ProjectQuery::RESULT_TYPE_QUERYBUILDER);
|
|
||||||
return $repo->findByQuery($query);
|
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,6 +50,20 @@ class ProjectRepository extends AbstractRepository
|
|||||||
return $stats;
|
return $stats;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a query builder that is used for ProjectType and your own 'query_builder' option.
|
||||||
|
*
|
||||||
|
* @param Project|null $entity
|
||||||
|
* @return \Doctrine\ORM\QueryBuilder
|
||||||
|
*/
|
||||||
|
public function builderForEntityType(Project $entity = null)
|
||||||
|
{
|
||||||
|
$query = new ProjectQuery();
|
||||||
|
$query->setHiddenEntity($entity);
|
||||||
|
$query->setResultType(ProjectQuery::RESULT_TYPE_QUERYBUILDER);
|
||||||
|
return $this->findByQuery($query);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ProjectQuery $query
|
* @param ProjectQuery $query
|
||||||
* @return \Doctrine\ORM\QueryBuilder|\Pagerfanta\Pagerfanta
|
* @return \Doctrine\ORM\QueryBuilder|\Pagerfanta\Pagerfanta
|
||||||
@@ -66,7 +80,17 @@ class ProjectRepository extends AbstractRepository
|
|||||||
->orderBy('p.' . $query->getOrderBy(), $query->getOrder());
|
->orderBy('p.' . $query->getOrderBy(), $query->getOrder());
|
||||||
|
|
||||||
if ($query->getVisibility() == ProjectQuery::SHOW_VISIBLE) {
|
if ($query->getVisibility() == ProjectQuery::SHOW_VISIBLE) {
|
||||||
|
if (!$query->isExclusiveVisibility()) {
|
||||||
|
$qb->andWhere('c.visible = 1');
|
||||||
|
}
|
||||||
$qb->andWhere('p.visible = 1');
|
$qb->andWhere('p.visible = 1');
|
||||||
|
|
||||||
|
/** @var Project $entity */
|
||||||
|
$entity = $query->getHiddenEntity();
|
||||||
|
if ($entity !== null) {
|
||||||
|
$qb->orWhere('p.id = :project')->setParameter('project', $entity);
|
||||||
|
}
|
||||||
|
|
||||||
// TODO check for visibility of customer
|
// TODO check for visibility of customer
|
||||||
} elseif ($query->getVisibility() == ProjectQuery::SHOW_HIDDEN) {
|
} elseif ($query->getVisibility() == ProjectQuery::SHOW_HIDDEN) {
|
||||||
$qb->andWhere('p.visible = 0');
|
$qb->andWhere('p.visible = 0');
|
||||||
|
|||||||
Reference in New Issue
Block a user