Ejemplo n.º 1
0
 /**
  * @param User $currentUser
  * @param GridView $gridView
  *
  * @return string
  */
 protected function createGridViewLabel(User $currentUser, GridView $gridView)
 {
     if ($gridView->getOwner()->getId() === $currentUser->getId()) {
         return $gridView->getName();
     }
     return $this->translator->trans('oro.datagrid.gridview.shared_by', ['%name%' => $gridView->getName(), '%owner%' => $gridView->getOwner()->getUsername()]);
 }
Ejemplo n.º 2
0
 /**
  * @todo Remove once https://github.com/symfony/symfony/issues/5906 is fixed
  *
  * @param GridView $gridView
  */
 protected function fixFilters(GridView $gridView)
 {
     $filters = $gridView->getFiltersData();
     foreach ($filters as $name => $filter) {
         if (array_key_exists('type', $filter) && $filter['type'] == null) {
             $filters[$name]['type'] = '';
         }
     }
     $gridView->setFiltersData($filters);
 }
Ejemplo n.º 3
0
 public function testCreateView()
 {
     $gridView = new GridView();
     $gridView->setName('name');
     $gridView->setFiltersData(['f' => 'fv']);
     $gridView->setSortersData(['s' => 'sv']);
     $expectedView = new View(null, ['f' => 'fv'], ['s' => 'sv'], GridView::TYPE_PRIVATE);
     $expectedView->setLabel('name');
     $this->assertEquals($expectedView, $gridView->createView());
 }
Ejemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     $privateView = new GridView();
     $privateView->setName('gridView')->setGridName('testing-grid')->setOwner($this->getReference('simple_user'));
     $manager->persist($privateView);
     $publicView = new GridView();
     $publicView->setName('gridView')->setType(GridView::TYPE_PUBLIC)->setGridName('testing-grid')->setOwner($this->getReference('simple_user'));
     $manager->persist($publicView);
     $manager->flush();
 }
Ejemplo n.º 5
0
 /**
  * @param User     $user
  * @param GridView $gridView
  * @param bool     $default
  */
 public function setDefaultGridView(User $user, GridView $gridView, $default)
 {
     $isGridViewDefault = $gridView->getUsers()->contains($user);
     // Checks if default grid view changed
     if ($isGridViewDefault !== $default) {
         $om = $this->registry->getManagerForClass('OroDataGridBundle:GridView');
         /** @var GridViewRepository $repository */
         $repository = $om->getRepository('OroDataGridBundle:GridView');
         $gridViews = $repository->findDefaultGridViews($this->aclHelper, $user, $gridView, false);
         foreach ($gridViews as $view) {
             $view->removeUser($user);
         }
         if ($default) {
             $gridView->addUser($user);
         }
     }
 }
 /**
  * @param ObjectManager $manager
  */
 public function load(ObjectManager $manager)
 {
     $user = $manager->getRepository('Oro\\Bundle\\UserBundle\\Entity\\User')->find(1);
     $organization = $manager->getRepository('Oro\\Bundle\\OrganizationBundle\\Entity\\Organization')->find(1);
     $newTicketsFilter = new GridView();
     $newTicketsFilter->setOwner($user)->setOrganization($organization)->setName('New tickets')->setType(GridView::TYPE_PUBLIC)->setFiltersData(array('status' => array('value' => array('new'))))->setSortersData(array('assigneeFullName' => '-1'))->setGridName('diamante-ticket-grid');
     $manager->persist($newTicketsFilter);
     $myTicketsFilter = new GridView();
     $myTicketsFilter->setOwner($user)->setOrganization($organization)->setName('My tickets')->setType(GridView::TYPE_PUBLIC)->setFiltersData(array('assigneeFullName' => 'fixtureUser', 'type' => '1'))->setSortersData(array('assigneeFullName' => '-1'))->setGridName('diamante-ticket-grid');
     $manager->persist($myTicketsFilter);
     $myNewTicketsFilter = new GridView();
     $myNewTicketsFilter->setOwner($user)->setOrganization($organization)->setName('My new tickets')->setType(GridView::TYPE_PUBLIC)->setFiltersData(array('assigneeFullName' => 'fixtureUser', 'type' => '1', 'status' => array('value' => array('new'))))->setSortersData(array('assigneeFullName' => '-1'))->setGridName('diamante-ticket-grid');
     $manager->persist($myNewTicketsFilter);
     $myOpenTicketsFilter = new GridView();
     $myOpenTicketsFilter->setOwner($user)->setOrganization($organization)->setName('My open tickets')->setType(GridView::TYPE_PUBLIC)->setFiltersData(array('assigneeFullName' => 'fixtureUser', 'type' => '1', 'status' => array('value' => array('open'))))->setSortersData(array('assigneeFullName' => '-1'))->setGridName('diamante-ticket-grid');
     $manager->persist($myOpenTicketsFilter);
     $manager->flush();
 }
 public function testListenerShouldAddViewsIntoEvent()
 {
     $originalViews = ['choices' => [['label' => 'first', 'value' => 'first']], 'views' => [['name' => 'first', 'filters' => [], 'sorters' => [], 'type' => 'system']]];
     $event = new GridViewsLoadEvent('grid', $originalViews);
     $currentUser = new User();
     $this->securityFacade->expects($this->once())->method('getLoggedUser')->will($this->returnValue($currentUser));
     $view1 = new GridView();
     $view1->setId(1);
     $view1->setOwner($currentUser);
     $view1->setName('view1');
     $view2 = new GridView();
     $view2->setId(2);
     $view2->setName('view2');
     $view2->setOwner($currentUser);
     $gridViews = [$view1, $view2];
     $this->gridViewRepository->expects($this->once())->method('findGridViews')->will($this->returnValue($gridViews));
     $expectedViews = ['choices' => [['label' => 'first', 'value' => 'first'], ['label' => 'view1', 'value' => 1], ['label' => 'view2', 'value' => 2]], 'views' => [['name' => 'first', 'filters' => [], 'sorters' => [], 'type' => 'system'], ['label' => 'view1', 'name' => 1, 'filters' => [], 'sorters' => [], 'type' => GridView::TYPE_PRIVATE, 'deletable' => true, 'editable' => true, 'columns' => [], 'is_default' => false], ['label' => 'view2', 'name' => 2, 'filters' => [], 'sorters' => [], 'type' => GridView::TYPE_PRIVATE, 'deletable' => true, 'editable' => true, 'columns' => [], 'is_default' => false]]];
     $this->gridViewsLoadListener->onViewsLoad($event);
     $this->assertEquals($expectedViews, $event->getGridViews());
 }
Ejemplo n.º 8
0
 public function testCreateView()
 {
     $gridView = new GridView();
     $gridView->setName('name');
     $gridView->setFiltersData(['f' => 'fv']);
     $gridView->setSortersData(['s' => 'sv']);
     $gridView->setColumnsData(['name' => ['order' => 4]]);
     $expectedView = new View(null, ['f' => 'fv'], ['s' => 'sv'], GridView::TYPE_PRIVATE, ['name' => ['order' => 4]]);
     $expectedView->setLabel('name');
     static::assertEquals($expectedView, $gridView->createView());
 }
Ejemplo n.º 9
0
 /**
  * Example of usage:
  *     Sorters options choices:
  *     '-1': 'ASC',
  *     '1': 'DESC'
  *
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->add('label', 'text', ['property_path' => 'name'])->add('type', 'choice', ['choices' => GridView::getTypes()])->add('grid_name', 'text', ['property_path' => 'gridName'])->add('filters', null, ['property_path' => 'filtersData', 'empty_data' => []])->add('sorters', 'collection', ['property_path' => 'sorters_data', 'error_bubbling' => false, 'allow_add' => true, 'allow_delete' => true, 'type' => 'choice', 'options' => ['choices' => [1 => 1, -1 => -1]]])->add('columns', null, ['property_path' => 'columns_data', 'empty_data' => []]);
 }
Ejemplo n.º 10
0
 /**
  * @param GridView $gridView
  *
  * @throws AccessDeniedException
  */
 protected function checkEditPublicAccess(GridView $gridView)
 {
     if ($gridView->getType() !== GridView::TYPE_PUBLIC) {
         return;
     }
     if ($this->getSecurityFacade()->isGranted('oro_datagrid_gridview_update_public')) {
         return;
     }
     throw new AccessDeniedException();
 }
Ejemplo n.º 11
0
 /**
  * @param AclHelper     $aclHelper
  * @param UserInterface $user
  * @param GridView      $gridView
  * @param bool          $checkOwner
  *
  * @return GridView[]
  */
 public function findDefaultGridViews(AclHelper $aclHelper, UserInterface $user, GridView $gridView, $checkOwner = true)
 {
     /** @var GridView[] $defaultGridViews */
     $qb = $this->getFindDefaultGridViewQb($user, $gridView->getGridName(), $checkOwner);
     return $aclHelper->apply($qb)->getResult();
 }