public function indexAction($view = null, $sortBy = null, $sortDirection = null, $filter = null, $tagMode = self::TAG_GIVEN, Tag $tag = null, $searchTerm = null, $collectionMode = self::COLLECTION_GIVEN, AssetCollection $assetCollection = null)
{
if ($view !== null) {
$this->browserState->set('view', $view);
$this->view->assign('view', $view);
}
if ($sortBy !== null) {
$this->browserState->set('sortBy', $sortBy);
$this->view->assign('sortBy', $sortBy);
}
if ($sortDirection !== null) {
$this->browserState->set('sortDirection', $sortDirection);
$this->view->assign('sortDirection', $sortDirection);
}
if ($filter !== null) {
$this->browserState->set('filter', $filter);
$this->view->assign('filter', $filter);
}
if ($tagMode === self::TAG_GIVEN && $tag !== null) {
$this->browserState->set('activeTag', $tag);
$this->view->assign('activeTag', $tag);
} elseif ($tagMode === self::TAG_NONE || $tagMode === self::TAG_ALL) {
$this->browserState->set('activeTag', null);
$this->view->assign('activeTag', null);
}
$this->browserState->set('tagMode', $tagMode);
if ($collectionMode === self::COLLECTION_GIVEN && $assetCollection !== null) {
$this->browserState->set('activeAssetCollection', $assetCollection);
$this->view->assign('activeAssetCollection', $assetCollection);
} elseif ($collectionMode === self::COLLECTION_ALL) {
$this->browserState->set('activeAssetCollection', null);
$this->view->assign('activeAssetCollection', null);
}
$this->browserState->set('collectionMode', $collectionMode);
try {
/** @var AssetCollection $activeAssetCollection */
$activeAssetCollection = $this->browserState->get('activeAssetCollection');
if ($activeAssetCollection instanceof DoctrineProxy) {
// To trigger a possible EntityNotFound have to load the entity
$activeAssetCollection->__load();
}
} catch (EntityNotFoundException $exception) {
// If a removed tasset collection is still in the browser state it can not be fetched
$this->browserState->set('activeAssetCollection', null);
$activeAssetCollection = null;
}
// Unset active tag if it isn't available in the active asset collection
if ($this->browserState->get('activeTag') && $activeAssetCollection !== null && !$activeAssetCollection->getTags()->contains($this->browserState->get('activeTag'))) {
$this->browserState->set('activeTag', null);
$this->view->assign('activeTag', null);
}
if ($this->browserState->get('filter') !== 'All') {
switch ($this->browserState->get('filter')) {
case 'Image':
$this->assetRepository = new ImageRepository();
break;
case 'Document':
$this->assetRepository = new DocumentRepository();
break;
case 'Video':
$this->assetRepository = new VideoRepository();
break;
case 'Audio':
$this->assetRepository = new AudioRepository();
break;
}
}
switch ($this->browserState->get('sortBy')) {
case 'Name':
$this->assetRepository->setDefaultOrderings(array('resource.filename' => $this->browserState->get('sortDirection')));
break;
case 'Modified':
default:
$this->assetRepository->setDefaultOrderings(array('lastModified' => $this->browserState->get('sortDirection')));
break;
}
if (!$this->browserState->get('activeTag') && $this->browserState->get('tagMode') === self::TAG_GIVEN) {
$this->browserState->set('tagMode', self::TAG_ALL);
}
$assetCollections = array();
foreach ($this->assetCollectionRepository->findAll() as $assetCollection) {
$assetCollections[] = array('object' => $assetCollection, 'count' => $this->assetRepository->countByAssetCollection($assetCollection));
}
$tags = array();
foreach ($activeAssetCollection !== null ? $activeAssetCollection->getTags() : $this->tagRepository->findAll() as $tag) {
$tags[] = array('object' => $tag, 'count' => $this->assetRepository->countByTag($tag, $activeAssetCollection));
}
if ($searchTerm !== null) {
$assets = $this->assetRepository->findBySearchTermOrTags($searchTerm, array(), $activeAssetCollection);
$this->view->assign('searchTerm', $searchTerm);
} elseif ($this->browserState->get('tagMode') === self::TAG_NONE) {
$assets = $this->assetRepository->findUntagged($activeAssetCollection);
} elseif ($this->browserState->get('activeTag') !== null) {
$assets = $this->assetRepository->findByTag($this->browserState->get('activeTag'), $activeAssetCollection);
} else {
$assets = $activeAssetCollection === null ? $this->assetRepository->findAll() : $this->assetRepository->findByAssetCollection($activeAssetCollection);
}
$allCollectionsCount = $this->assetRepository->countAll();
$maximumFileUploadSize = $this->maximumFileUploadSize();
$this->view->assignMultiple(array('assets' => $assets, 'tags' => $tags, 'allCollectionsCount' => $allCollectionsCount, 'allCount' => $activeAssetCollection ? $this->assetRepository->countByAssetCollection($activeAssetCollection) : $allCollectionsCount, 'untaggedCount' => $this->assetRepository->countUntagged($activeAssetCollection), 'tagMode' => $this->browserState->get('tagMode'), 'assetCollections' => $assetCollections, 'argumentNamespace' => $this->request->getArgumentNamespace(), 'maximumFileUploadSize' => $maximumFileUploadSize, 'humanReadableMaximumFileUploadSize' => Files::bytesToSizeString($maximumFileUploadSize)));
}