/**
  * Index action method
  *
  * @return void
  */
 public function index()
 {
     $library = new Model\MediaLibrary();
     if ($library->hasPages($this->config->pagination)) {
         $limit = $this->config->pagination;
         $pages = new Paginator($library->getCount(), $limit);
         $pages->useInput(true);
     } else {
         $limit = null;
         $pages = null;
     }
     $this->prepareView('media/libraries/index.phtml');
     $this->view->title = 'Media Libraries';
     $this->view->pages = $pages;
     $this->view->libraries = $library->getAll($limit, $this->request->getQuery('page'), $this->request->getQuery('sort'));
     $this->send();
 }
 /**
  * Index action method
  *
  * @param  int $lid
  * @return void
  */
 public function index($lid = null)
 {
     if (null === $lid) {
         $this->prepareView('media/libraries.phtml');
         $library = new Model\MediaLibrary();
         if ($library->hasPages($this->config->pagination)) {
             $limit = $this->config->pagination;
             $pages = new Paginator($library->getCount(), $limit);
             $pages->useInput(true);
         } else {
             $limit = null;
             $pages = null;
         }
         $this->view->title = 'Media';
         $this->view->pages = $pages;
         $this->view->libraries = $library->getAll($limit, $this->request->getQuery('page'), $this->request->getQuery('sort'));
     } else {
         $this->prepareView('media/index.phtml');
         $media = new Model\Media(['lid' => $lid]);
         $library = new Model\MediaLibrary();
         $library->getById($lid);
         if (!isset($library->id)) {
             $this->redirect(BASE_PATH . APP_URI . '/media');
         }
         if ($this->services['acl']->isAllowed($this->sess->user->role, 'media-library-' . $library->id, 'index')) {
             if (null !== $this->request->getQuery('title')) {
                 $mediaFiles = $media->getAll(null, $this->request->getQuery('page'), $this->request->getQuery('sort'), $this->request->getQuery('title'));
                 if (count($mediaFiles) > $this->config->pagination) {
                     $page = $this->request->getQuery('page');
                     $limit = $this->config->pagination;
                     $pages = new Paginator(count($mediaFiles), $limit);
                     $pages->useInput(true);
                     $offset = null !== $page && (int) $page > 1 ? $page * $limit - $limit : 0;
                     $mediaFiles = array_slice($mediaFiles, $offset, $limit, true);
                 } else {
                     $pages = null;
                 }
             } else {
                 if ($media->hasPages($this->config->pagination, $lid)) {
                     $limit = $this->config->pagination;
                     $pages = new Paginator($media->getCount($lid), $limit);
                     $pages->useInput(true);
                 } else {
                     $limit = null;
                     $pages = null;
                 }
                 $mediaFiles = $media->getAll($limit, $this->request->getQuery('page'), $this->request->getQuery('sort'));
             }
             $this->view->title = 'Media : ' . $library->name;
             $this->view->pages = $pages;
             $this->view->lid = $lid;
             $this->view->queryString = $this->getQueryString('sort');
             $this->view->folder = $library->folder;
             $this->view->searchValue = htmlentities(strip_tags($this->request->getQuery('title')), ENT_QUOTES, 'UTF-8');
             $this->view->media = $mediaFiles;
         } else {
             $this->redirect(BASE_PATH . APP_URI . '/media');
         }
     }
     $this->send();
 }