/**
  * @param PaginateFinderConfiguration $configuration
  * @param array|null                  $order
  * @param int|null                    $limit
  * @param int|null                    $skip
  * @param array|null                  $search
  */
 protected function finderPaginateConfigurationTest(PaginateFinderConfiguration $configuration, $order, $limit, $skip, $search)
 {
     $this->isTypeOrNull("is_array", $configuration->getSearch(), $search);
     $this->isTypeOrNull("is_array", $configuration->getOrder(), $order);
     $this->isTypeOrNull("is_int", $configuration->getLimit(), $limit);
     $this->isTypeOrNull("is_int", $configuration->getSkip(), $skip);
 }
 /**
  * test count all user
  */
 public function testCount()
 {
     $this->markTestSkipped('To unskip when group list is refacto');
     $configuration = PaginateFinderConfiguration::generateFromVariable($this->getDescriptionColumnEntity(), array());
     $groups = $this->repository->count($configuration);
     $this->assertEquals(3, $groups);
 }
 /**
  * @param string $name
  * @param string $value
  * @param string $documentName
  *
  * @return array
  */
 public function generateFilter($name, $value, $documentName)
 {
     $columnsTree = explode('.', $name);
     if (2 == count($columnsTree)) {
         list($property, $referenceProperty) = $columnsTree;
         $metadata = $this->documentManager->getClassMetadata($documentName);
         $targetDocument = $metadata->getFieldMapping($property)['targetDocument'];
         $mapping = $this->searchMappingReader->extractMapping($targetDocument);
         $repository = $this->documentManager->getRepository($targetDocument);
         if ($repository instanceof AbstractAggregateRepository) {
             $repository->setAggregationQueryBuilder($this->aggregationQueryBuilder);
         }
         if ($repository instanceof PaginationRepositoryInterface) {
             $repository->setFilterTypeManager($this->filterTypeManager);
             $configuration = PaginateFinderConfiguration::generateFromVariable($mapping, array('columns' => array($referenceProperty => $value)));
             $filter = array(array($property . '.$id' => new \MongoId()));
             $referenceds = $repository->findForPaginate($configuration);
             foreach ($referenceds as $referenced) {
                 $filter[] = array($property . '.$id' => new \MongoId($referenced->getId()));
             }
             return array('$or' => $filter);
         }
     }
     return null;
 }
 /**
  * @param array   $descriptionEntity
  * @param array   $search
  * @param int     $skip
  * @param int     $limit
  * @param integer $count
  *
  * @dataProvider providePaginateSearch
  */
 public function testFindForPaginate($descriptionEntity, $search, $skip, $limit, $count)
 {
     $this->markTestSkipped('To unskip when group list is refacto');
     $configuration = PaginateFinderConfiguration::generateFromVariable($descriptionEntity, $search);
     $configuration->setPaginateConfiguration(null, $skip, $limit);
     $sites = $this->repository->findForPaginate($configuration);
     $this->assertCount($count, $sites);
 }
 /**
  * @param Request $request
  *
  * @Config\Route("", name="open_orchestra_api_workflow_functions_list")
  * @Config\Method({"GET"})
  *
  * @return FacadeInterface
  */
 public function listAction(Request $request)
 {
     $repository = $this->get('open_orchestra_model.repository.workflow_function');
     $configuration = PaginateFinderConfiguration::generateFromRequest($request);
     $mapping = $this->get('open_orchestra.annotation_search_reader')->extractMapping($this->container->getParameter('open_orchestra_model.document.workflow_function.class'));
     $configuration->setDescriptionEntity($mapping);
     $workflowFunctionCollection = $repository->findForPaginate($configuration);
     $recordsTotal = $repository->count();
     $recordsFiltered = $repository->countWithFilter($configuration);
     $facade = $this->get('open_orchestra_api.transformer_manager')->get('workflow_function_collection')->transform($workflowFunctionCollection);
     $facade->recordsTotal = $recordsTotal;
     $facade->recordsFiltered = $recordsFiltered;
     return $facade;
 }
 /**
  * @param Request                       $request
  * @param PaginationRepositoryInterface $entityRepository
  * @param array                         $mappingEntity
  * @param TransformerInterface          $transformerManager
  * @param array                         $filter
  *
  * @return \OpenOrchestra\BaseApi\Facade\FacadeInterface
  */
 protected function handleRequestDataTable(Request $request, PaginationRepositoryInterface $entityRepository, $mappingEntity, TransformerInterface $transformerManager, array $prefilter = array())
 {
     if ($entityId = $request->get('entityId')) {
         $element = $entityRepository->find($entityId);
         return $transformerManager->transform(array($element));
     }
     $configuration = PaginateFinderConfiguration::generateFromRequest($request);
     foreach ($prefilter as $key => $value) {
         $configuration->addPrefilterSearch($key, $value);
     }
     $configuration->setDescriptionEntity($mappingEntity);
     $collection = $entityRepository->findForPaginate($configuration);
     $recordsTotal = $entityRepository->count($configuration);
     $recordsFiltered = $entityRepository->countWithFilter($configuration);
     return $this->generateFacadeDataTable($transformerManager, $collection, $recordsTotal, $recordsFiltered);
 }
 /**
  * @param Request $request
  *
  * @Config\Route("", name="open_orchestra_api_content_type_list")
  * @Config\Method({"GET"})
  *
  * @return FacadeInterface
  */
 public function listAction(Request $request)
 {
     $repository = $this->get('open_orchestra_model.repository.content_type');
     $transformer = $this->get('open_orchestra_api.transformer_manager')->get('content_type_collection');
     if ($request->get('entityId')) {
         $element = $repository->find($request->get('entityId'));
         return $transformer->transform(array($element));
     }
     $configuration = PaginateFinderConfiguration::generateFromRequest($request);
     $mapping = $this->get('open_orchestra.annotation_search_reader')->extractMapping($this->container->getParameter('open_orchestra_model.document.content_type.class'));
     $configuration->setDescriptionEntity($mapping);
     $contentTypeCollection = $repository->findAllNotDeletedInLastVersionForPaginate($configuration);
     $recordsTotal = $repository->countByContentTypeInLastVersion();
     $recordsFiltered = $repository->countNotDeletedInLastVersionWithSearchFilter($configuration);
     return $this->generateFacadeDataTable($transformer, $contentTypeCollection, $recordsTotal, $recordsFiltered);
 }
 /**
  * @param Request $request
  *
  * @Config\Route("", name="open_orchestra_api_site_list")
  * @Config\Method({"GET"})
  *
  * @return FacadeInterface
  */
 public function listAction(Request $request)
 {
     $repository = $this->get('open_orchestra_model.repository.site');
     $transformer = $this->get('open_orchestra_api.transformer_manager')->get('site_collection');
     if ($entityId = $request->get('entityId')) {
         $element = $repository->find($entityId);
         return $transformer->transform(array($element));
     }
     $configuration = PaginateFinderConfiguration::generateFromRequest($request);
     $configuration->addColumnSearch('deleted', false);
     $mapping = $this->get('open_orchestra.annotation_search_reader')->extractMapping($this->container->getParameter('open_orchestra_model.document.site.class'));
     $configuration->setDescriptionEntity($mapping);
     $siteCollection = $repository->findByDeletedForPaginate(false, $configuration);
     $recordsTotal = $repository->countByDeleted(false);
     $recordsFiltered = $repository->countWithSearchFilterByDeleted(false, $configuration);
     return $this->generateFacadeDataTable($transformer, $siteCollection, $recordsTotal, $recordsFiltered);
 }
 /**
  * @param PaginateFinderConfiguration $configuration
  *
  * @return array
  */
 protected function generateGroupForFilterSort(PaginateFinderConfiguration $configuration)
 {
     $group = array();
     $sorts = $this->generateArrayForFilterSort($configuration->getOrder(), $configuration->getDescriptionEntity(), false, true);
     foreach ($sorts as $key => $name) {
         $group = array_merge($group, array($key => array('$last' => '$' . $name)));
     }
     return $group;
 }
 /**
  * @param string   $contentType
  * @param array    $descriptionEntity
  * @param array    $search
  * @param string   $siteId
  * @param int      $skip
  * @param int      $limit
  * @param integer  $count
  *
  * @dataProvider provideContentTypeAndPaginateAndSearchAndsiteId
  */
 public function testFindPaginatedLastVersionByContentTypeAndsite($contentType, $descriptionEntity, $search, $order, $siteId, $skip, $limit, $count, $name = null)
 {
     $this->markTestSkipped('To unskip when group list is refacto');
     $configuration = PaginateFinderConfiguration::generateFromVariable($descriptionEntity, $search);
     $configuration->setPaginateConfiguration($order, $skip, $limit);
     $contents = $this->repository->findPaginatedLastVersionByContentTypeAndsite($contentType, $configuration, $siteId);
     if (!is_null($name)) {
         $this->assertEquals($name, $contents[0]->getName());
     }
     $this->assertCount($count, $contents);
 }
 /**
  * @return array
  */
 public function provideFindWithFilterPaginateConfiguration()
 {
     $configurationAllPaginate = PaginateFinderConfiguration::generateFromVariable(array(), 0, 100, array());
     $configurationLimit = PaginateFinderConfiguration::generateFromVariable(array(), 0, 2, array());
     $configurationSkip = PaginateFinderConfiguration::generateFromVariable(array(), 2, 100, array());
     $configurationOrder = PaginateFinderConfiguration::generateFromVariable(array('updated_at' => 'desc'), 0, 100, array('updated_at' => 'updatedAt'));
     $configurationFilter = PaginateFinderConfiguration::generateFromVariable(array(), 0, 100, array(), array('name' => 'orchestra'));
     return array('all' => array($configurationAllPaginate, '2', 'fr', 8), 'limit' => array($configurationLimit, '2', 'fr', 2), 'skip' => array($configurationSkip, '2', 'fr', 6), 'order' => array($configurationOrder, '2', 'fr', 8), 'filter' => array($configurationFilter, '2', 'fr', 1));
 }
 /**
  * @param Request $request
  *
  * @Config\Route("", name="open_orchestra_api_content_list")
  * @Config\Method({"GET"})
  *
  * @Api\Groups({GroupContext::G_HIDE_ROLES})
  *
  * @return FacadeInterface
  */
 public function listAction(Request $request)
 {
     $contentType = $request->get('content_type');
     $siteId = $this->get('open_orchestra_backoffice.context_manager')->getCurrentSiteId();
     $repository = $this->get('open_orchestra_model.repository.content');
     $transformer = $this->get('open_orchestra_api.transformer_manager')->get('content_collection');
     if ($request->get('entityId') && $request->get('language')) {
         $content = $this->showOrCreate($request, $request->get('entityId'));
         return $transformer->transform(array($content), $contentType);
     }
     $configuration = PaginateFinderConfiguration::generateFromRequest($request);
     $mapping = $this->get('open_orchestra.annotation_search_reader')->extractMapping($this->container->getParameter('open_orchestra_model.document.content.class'));
     $mappingAttributes = $this->get('open_orchestra_api.mapping.content_attribute')->getMapping($contentType);
     $mapping = array_merge($mapping, $mappingAttributes);
     $configuration->setDescriptionEntity($mapping);
     $contentCollection = $repository->findPaginatedLastVersionByContentTypeAndSite($contentType, $configuration, $siteId);
     $recordsTotal = $repository->countByContentTypeAndSiteInLastVersion($contentType, $siteId);
     $recordsFiltered = $repository->countByContentTypeInLastVersionWithFilter($contentType, $configuration, $siteId);
     $facade = $transformer->transform($contentCollection, $contentType);
     $facade->recordsTotal = $recordsTotal;
     $facade->recordsFiltered = $recordsFiltered;
     return $facade;
 }
 /**
  * @param Request $request
  * @param String  $siteId
  * @param String  $language
  *
  * @Config\Route("/list/{siteId}/{language}", name="open_orchestra_api_node_list")
  * @Config\Method({"GET"})
  *
  *  @Api\Groups({
  *     OpenOrchestra\ApiBundle\Context\CMSGroupContext::STATUS
  * })
  *
  * @return FacadeInterface
  */
 public function listAction(Request $request, $siteId, $language)
 {
     $mapping = array('updated_at' => 'updatedAt', 'name' => 'name', 'created_by' => 'createdBy', 'status.label' => 'status.labels');
     $configuration = PaginateFinderConfiguration::generateFromRequest($request, $mapping);
     $repository = $this->get('open_orchestra_model.repository.node');
     $collection = $repository->findForPaginate($configuration, $siteId, $language);
     $recordsTotal = $repository->count($siteId, $language);
     $recordsFiltered = $repository->countWithFilter($configuration, $siteId, $language);
     $collectionTransformer = $this->get('open_orchestra_api.transformer_manager')->get('node_collection');
     $facade = $collectionTransformer->transform($collection);
     $facade->recordsTotal = $recordsTotal;
     $facade->recordsFiltered = $recordsFiltered;
     return $facade;
 }
 /**
  * @param PaginateFinderConfiguration $configuration
  *
  * @return array
  */
 protected function getFilterSearch(PaginateFinderConfiguration $configuration)
 {
     $filter = array();
     $name = $configuration->getSearchIndex('name');
     if (null !== $name && $name !== '') {
         $filter['name'] = new MongoRegex('/.*' . $name . '.*/i');
     }
     $inMenu = $configuration->getSearchIndex('inMenu');
     if (null !== $inMenu && $inMenu !== '') {
         $filter['inMenu'] = (bool) $inMenu;
     }
     $status = $configuration->getSearchIndex('status');
     if (null !== $status && $status !== '') {
         $filter['status.name'] = $status;
     }
     return $filter;
 }