Ejemplo n.º 1
0
 /**
  * Processing media list
  */
 public function listAction()
 {
     $params = $where = array();
     $type = $this->params('type', 'image');
     $keyword = $this->params('keyword', '');
     $style = 'default';
     if ('image' == $type) {
         $style = $this->params('style', 'normal');
         $params['style'] = $style;
     }
     $where['type'] = $this->getExtension($type);
     $types = array();
     foreach ($where['type'] as $item) {
         $types[$item] = $item;
     }
     $miniType = $this->params('mini_type', '');
     if (!empty($miniType)) {
         $where['type'] = $miniType;
         $params['mini_type'] = $miniType;
     }
     if (!empty($keyword)) {
         $where['title like ?'] = '%' . $keyword . '%';
         $params['keyword'] = $keyword;
     }
     $model = $this->getModel('media');
     $page = $this->params('p', 1);
     $page = $page > 0 ? $page : 1;
     $module = $this->getModule();
     $config = Pi::config('', $module);
     $limit = (int) $config['page_limit_all'] ?: 40;
     $resultSet = Media::getList($where, $page, $limit, null, null, $module);
     // Total count
     $count = $model->count($where);
     // Pagination
     $paginator = Paginator::factory($count, array('limit' => $limit, 'page' => $page, 'url_options' => array('page_param' => 'p', 'params' => array_merge(array('module' => $this->getModule(), 'controller' => 'media', 'action' => 'list', 'type' => $type, 'style' => $style), $params))));
     // Getting search form
     $form = new SimpleSearchForm();
     $this->view()->assign(array('title' => _a('All Media'), 'medias' => $resultSet, 'paginator' => $paginator, 'type' => $type, 'keyword' => $keyword, 'types' => $types, 'form' => $form, 'count' => $count, 'miniType' => $miniType, 'style' => $style));
 }
Ejemplo n.º 2
0
 /**
  * Searching image details by AJAX according to posted parameters. 
  */
 public function searchAction()
 {
     Pi::service('log')->mute();
     $type = $this->params('type', '');
     $where = array();
     // Resolving type
     if ($type == 'image') {
         $extensionDesc = $this->config('image_extension');
     } else {
         $extensionDesc = $type;
     }
     $extensions = explode(',', $extensionDesc);
     foreach ($extensions as &$ext) {
         $ext = trim($ext);
     }
     $types = array_filter($extensions);
     if (!empty($types)) {
         $where['type'] = $types;
     }
     // Resolving ID
     $id = $this->params('id', 0);
     $ids = array_filter(explode(',', $id));
     if (!empty($ids)) {
         $where['id'] = $ids;
     }
     // Getting title condition
     $title = $this->params('title', '');
     if (!empty($title)) {
         $where['title like ?'] = '%' . $title . '%';
     }
     $page = (int) $this->params('page', 1);
     $limit = (int) $this->params('limit', 5);
     $rowset = Media::getList($where, $page, $limit);
     // Get count
     $count = $this->getModel('media')->count($where);
     // Get previous and next button URL
     $prevUrl = '';
     $nextUrl = '';
     $params = array('action' => 'search', 'type' => $type ?: 0, 'id' => $id ?: 0, 'title' => $title ?: 0, 'limit' => $limit ?: 0);
     $params = array_filter($params);
     if ($count > $page * $limit) {
         $params['page'] = $page + 1;
         $nextUrl = $this->url('', $params);
     }
     if ($page > 1) {
         $params['page'] = $page - 1;
         $prevUrl = $this->url('', $params);
     }
     echo json_encode(array('data' => $rowset, 'prev_url' => $prevUrl, 'next_url' => $nextUrl));
     exit;
 }