Example #1
0
 public function actionRecent()
 {
     $this->pageTitle = 'New Torrents | ' . Yii::app()->name . ' Torrent Search Engine';
     $pagination = new Pagination(9975);
     $pagination->setPageSize(35);
     $torrents = new CActiveDataProvider(LTorrent::model(), array('criteria' => array('scopes' => array('allowed')), 'sort' => array('sortVar' => 'Torrent_sort', 'defaultOrder' => array('id' => CSort::SORT_DESC), 'attributes' => LTorrent::$defaultSortAttributes), 'pagination' => $pagination));
     if (empty($torrents)) {
         Yii::log('Empty latest torrents set', CLogger::LEVEL_ERROR);
     }
     $this->render('latest', array('torrents' => $torrents));
 }
 /**
  * List action: list of elements
  * 
  * @param array $aParams array of input params
  * @return ActionResponse 
  */
 public function actionList($aParams = array())
 {
     $aConfig = $this->config('List');
     $limit = 10;
     $aFindParams = array();
     if (count($aParams) && $this->sMapperAlias) {
         foreach ($aParams as $key => $param) {
             if ($this->mapper()->isRealFieldExists($key)) {
                 $aFindParams['Criteria'][$key] = $param;
             }
         }
     }
     $page = isset($_GET['page']) ? intval($_GET['page']) - 1 : 0;
     $aFindParams['Limit'] = $limit;
     $aFindParams['Offset'] = $page * $limit;
     $sort_field = isset($_GET['sort_field']) ? $_GET['sort_field'] : 'Id';
     $sort_direction = isset($_GET['sort_direction']) ? $_GET['sort_direction'] : 'ASC';
     $aFindParams['Order'] = array();
     //echo '<pre>', print_r($aFindParams, true), '</pre>'; die();
     if (isset($aConfig['Component']['FindParams'])) {
         $aFindParams = ArrayHelper::merge($aFindParams, $aConfig['Component']['FindParams']);
     }
     if (!count($aFindParams['Order'])) {
         $aFindParams['Order'] = array($sort_field => $sort_direction);
     }
     $mResult = false;
     if ($aConfig) {
         if (!isset($aConfig['View']) || isset($aConfig['View']) && $aConfig['View'] != false) {
             $mResult = $this->view(array(), $aConfig['View']);
         } else {
             if (isset($aConfig['Component'])) {
                 $sComponentModule = $aConfig['Component']['Component'][0];
                 $sComponentAlias = $aConfig['Component']['Component'][1];
                 $aComponentParams = isset($aConfig['Component']['Params']) ? $aConfig['Component']['Params'] : array();
                 // Проверка доступа
                 $this->checkActionAccess('List');
                 $aComponentParams['Data'] = $this->getListData($aFindParams);
                 $count = $this->getListDataCount($aFindParams);
                 $oPagination = new Pagination($count);
                 $oPagination->setPageSize($aFindParams['Limit']);
                 $oPagination->applyLimit(@$aFindParams['Criteria']);
                 $aComponentParams['Pagination'] = $oPagination;
                 $mResult = $this->component($sComponentModule, $sComponentAlias, $aComponentParams);
             } else {
                 $mResult = false;
             }
         }
     } else {
         $mResult = $this->view('List');
     }
     return $mResult;
 }
Example #3
0
 /**
  * Список записей
  *
  * @param array $params
  * @return \ActionResponse|mixed
  */
 public function actionIndex($params = array())
 {
     $limit = 1;
     $offset = !empty($_GET['page']) ? ($_GET['page'] - 1) * $limit : 0;
     if (\Toolkit::i()->auth->isAdmin()) {
         $items = $this->mapper()->find(['Limit' => $limit, 'Offset' => $offset]);
         $count = $this->mapper()->count();
     } else {
         $items = $this->mapper()->active()->find(['Limit' => $limit, 'Offset' => $offset]);
         $count = $this->mapper()->active()->count();
     }
     $oPagination = new \Pagination($count);
     $oPagination->setPageSize($limit);
     return $this->view('Index', array('Items' => $items, 'Pagination' => $oPagination));
 }