getSnippetsAmount() public method

If $type is given then only return the snippets of that type.
public getSnippetsAmount ( string $locale, string $type = null, string $search = null, string $sortBy = null, string $sortOrder = null ) : SnippetBridge[]
$locale string
$type string Optional snippet type
$search string
$sortBy string
$sortOrder string
return Sulu\Component\Content\Compat\Structure\SnippetBridge[]
示例#1
0
 /**
  * Returns list of snippets.
  *
  * @param Request $request
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function cgetAction(Request $request)
 {
     $locale = $this->getLocale($request);
     // if the type parameter is falsy, assign NULL to $type
     $type = $request->query->get('type', null) ?: null;
     $uuidsString = $request->get('ids');
     if ($uuidsString) {
         $uuids = explode(',', $uuidsString);
         $snippets = $this->snippetRepository->getSnippetsByUuids($uuids, $locale);
         $total = count($snippets);
     } else {
         $snippets = $this->snippetRepository->getSnippets($locale, $type, $this->listRestHelper->getOffset(), $this->listRestHelper->getLimit(), $this->listRestHelper->getSearchPattern(), $this->listRestHelper->getSortColumn(), $this->listRestHelper->getSortOrder());
         $total = $this->snippetRepository->getSnippetsAmount($locale, $type, $this->listRestHelper->getSearchPattern(), $this->listRestHelper->getSortColumn(), $this->listRestHelper->getSortOrder());
     }
     $data = new ListRepresentation($snippets, 'snippets', 'get_snippets', $request->query->all(), $this->listRestHelper->getPage(), $this->listRestHelper->getLimit(), $total);
     return $this->viewHandler->handle(View::create($data));
 }
示例#2
0
 /**
  * Returns list of snippets.
  *
  * @param Request $request
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function getSnippetsAction(Request $request)
 {
     $this->initEnv($request);
     $listRestHelper = new ListRestHelper($request);
     // if the type parameter is falsy, assign NULL to $type
     $type = $request->query->get('type', null) ?: null;
     $uuidsString = $request->get('ids');
     if ($uuidsString) {
         $uuids = explode(',', $uuidsString);
         $snippets = $this->snippetRepository->getSnippetsByUuids($uuids, $this->languageCode);
         $total = count($snippets);
     } else {
         $snippets = $this->snippetRepository->getSnippets($this->languageCode, $type, $listRestHelper->getOffset(), $listRestHelper->getLimit(), $listRestHelper->getSearchPattern(), $listRestHelper->getSortColumn(), $listRestHelper->getSortOrder());
         $total = $this->snippetRepository->getSnippetsAmount($this->languageCode, $type, $listRestHelper->getSearchPattern(), $listRestHelper->getSortColumn(), $listRestHelper->getSortOrder());
     }
     $data = array();
     foreach ($snippets as $snippet) {
         $data[] = $snippet->toArray();
     }
     $data = new ListRepresentation($this->decorateSnippets($data, $this->languageCode), 'snippets', 'get_snippets', $request->query->all(), $listRestHelper->getPage(), $listRestHelper->getLimit(), $total);
     return $this->viewHandler->handle(View::create($data));
 }