+ */
+class VisibilityToolbarForm extends PagedToolbarForm
+{
+
+ /**
+ * {@inheritdoc}
+ */
+ public function buildForm(FormBuilderInterface $builder, array $options)
+ {
+ parent::buildForm($builder, $options);
+
+ $builder
+ ->add('visibility', VisibilityType::class, [
+ 'required' => false,
+ ])
+ ;
+ }
+}
diff --git a/src/TimesheetBundle/Form/Type/ActivityGroupedWithCustomerNameType.php b/src/TimesheetBundle/Form/Type/ActivityGroupedWithCustomerNameType.php
index 5d3ea4d6..e66948a2 100644
--- a/src/TimesheetBundle/Form/Type/ActivityGroupedWithCustomerNameType.php
+++ b/src/TimesheetBundle/Form/Type/ActivityGroupedWithCustomerNameType.php
@@ -29,6 +29,15 @@ class ActivityGroupedWithCustomerNameType extends ActivityType
*/
public function groupBy(Activity $activity, $key, $index)
{
- return $activity->getProject()->getCustomer()->getName() . ': ' . $activity->getProject()->getName();
+ return $activity->getProject()->getCustomer()->getName();
+ }
+
+ /**
+ * @param Activity $activity
+ * @return string
+ */
+ public function choiceLabel(Activity $activity)
+ {
+ return $activity->getProject()->getName() . ': ' . $activity->getName();
}
}
diff --git a/src/TimesheetBundle/Form/Type/ActivityType.php b/src/TimesheetBundle/Form/Type/ActivityType.php
index 4576448f..46e69e05 100644
--- a/src/TimesheetBundle/Form/Type/ActivityType.php
+++ b/src/TimesheetBundle/Form/Type/ActivityType.php
@@ -16,7 +16,6 @@ use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use TimesheetBundle\Entity\Activity;
use TimesheetBundle\Repository\ActivityRepository;
-use TimesheetBundle\Repository\Query\ActivityQuery;
/**
* Custom form field type to select an activity.
@@ -26,6 +25,22 @@ use TimesheetBundle\Repository\Query\ActivityQuery;
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}
*/
@@ -34,15 +49,10 @@ class ActivityType extends AbstractType
$resolver->setDefaults([
'label' => 'label.activity',
'class' => 'TimesheetBundle:Activity',
- 'choice_label' => 'name',
- 'group_by' => function (Activity $activity, $key, $index) {
- return '[' . $activity->getProject()->getId() . '] ' . $activity->getProject()->getName();
- },
+ 'choice_label' => [$this, 'choiceLabel'],
+ 'group_by' => [$this, 'groupBy'],
'query_builder' => function (ActivityRepository $repo) {
- $query = new ActivityQuery();
- $query->setVisibility(ActivityQuery::SHOW_BOTH);
- $query->setResultType(ActivityQuery::RESULT_TYPE_QUERYBUILDER);
- return $repo->findByQuery($query);
+ return $repo->builderForEntityType(null);
},
]);
}
diff --git a/src/TimesheetBundle/Repository/ActivityRepository.php b/src/TimesheetBundle/Repository/ActivityRepository.php
index 24d87fe8..13863049 100644
--- a/src/TimesheetBundle/Repository/ActivityRepository.php
+++ b/src/TimesheetBundle/Repository/ActivityRepository.php
@@ -50,6 +50,9 @@ class ActivityRepository extends AbstractRepository
->join('a.project', 'p')
->join('p.customer', 'c')
->where($qb->expr()->isNotNull('t.end'))
+ ->andWhere('a.visible = 1')
+ ->andWhere('p.visible = 1')
+ ->andWhere('c.visible = 1')
->groupBy('a.id')
->orderBy('t.end', 'DESC')
->setMaxResults(10)
@@ -93,6 +96,20 @@ class ActivityRepository extends AbstractRepository
return $stats;
}
+ /**
+ * Returns a query builder that is used for ActivityType and your own 'query_builder' option.
+ *
+ * @param Activity|null $entity
+ * @return \Doctrine\ORM\QueryBuilder
+ */
+ public function builderForEntityType(Activity $entity = null)
+ {
+ $query = new ActivityQuery();
+ $query->setHiddenEntity($entity);
+ $query->setResultType(ActivityQuery::RESULT_TYPE_QUERYBUILDER);
+ return $this->findByQuery($query);
+ }
+
/**
* @param ActivityQuery $query
* @return \Doctrine\ORM\QueryBuilder|\Pagerfanta\Pagerfanta
@@ -108,11 +125,19 @@ class ActivityRepository extends AbstractRepository
->orderBy('a.' . $query->getOrderBy(), $query->getOrder());
if ($query->getVisibility() == ActivityQuery::SHOW_VISIBLE) {
+ if (!$query->isExclusiveVisibility()) {
+ $qb->andWhere('c.visible = 1');
+ $qb->andWhere('p.visible = 1');
+ }
$qb->andWhere('a.visible = 1');
- // TODO check for visibility of customer and project
+
+ /** @var Activity $entity */
+ $entity = $query->getHiddenEntity();
+ if ($entity !== null) {
+ $qb->orWhere('a.id = :activity')->setParameter('activity', $entity);
+ }
} elseif ($query->getVisibility() == ActivityQuery::SHOW_HIDDEN) {
$qb->andWhere('a.visible = 0');
- // TODO check for visibility of customer and project
}
if ($query->getProject() !== null) {
diff --git a/src/TimesheetBundle/Resources/views/admin/timesheet.html.twig b/src/TimesheetBundle/Resources/views/admin/timesheet.html.twig
index c64cad5c..872a5235 100644
--- a/src/TimesheetBundle/Resources/views/admin/timesheet.html.twig
+++ b/src/TimesheetBundle/Resources/views/admin/timesheet.html.twig
@@ -36,8 +36,10 @@
| ‐ |
‐ |
{% endif %}
- {{ widgets.label_activity(entry.activity.name) }} |
- {{ entry.user.username }} |
+
+ {{ widgets.label_activity(entry.activity) }}
+ |
+ {{ widgets.label_user(entry.user) }} |
{{ entry.description }} |
{% if entry.end %}
diff --git a/src/TimesheetBundle/Resources/views/timesheet/index.html.twig b/src/TimesheetBundle/Resources/views/timesheet/index.html.twig
index 3c2701cf..14e55abe 100644
--- a/src/TimesheetBundle/Resources/views/timesheet/index.html.twig
+++ b/src/TimesheetBundle/Resources/views/timesheet/index.html.twig
@@ -35,7 +35,7 @@
| {{ entry.duration|duration }} |
‐ |
{% endif %}
- {{ widgets.label_activity(entry.activity.name) }} |
+ {{ widgets.label_activity(entry.activity) }} |
{{ entry.description }} |
{% if entry.end %}
|