/** * Returns a List of all notifications for the session user */ public function actionIndex() { $pageSize = 10; $notifications = []; $filterForm = new FilterForm(); $filterForm->initFilter(); $filterForm->load(Yii::$app->request->get()); $query = Notification::findGrouped(); $query->andWhere(['user_id' => Yii::$app->user->id]); if ($filterForm->isExcludeFilter()) { $query->andFilterWhere(['not in', 'class', $filterForm->getExcludeClassFilter()]); } else { if ($filterForm->isActive()) { $query->andFilterWhere(['in', 'class', $filterForm->getIncludeClassFilter()]); } else { return $this->render('index', ['notificationEntries' => [], 'filterForm' => $filterForm, 'pagination' => null, 'notifications' => $notifications]); } } $countQuery = clone $query; $pagination = new \yii\data\Pagination(['totalCount' => $countQuery->count(), 'pageSize' => $pageSize]); //Reset pagegination after new filter set if (Yii::$app->request->post()) { $pagination->setPage(0); } $query->offset($pagination->offset)->limit($pagination->limit); foreach ($query->all() as $notificationRecord) { $notifications[] = $notificationRecord->getClass(); } return $this->render('index', array('notifications' => $notifications, 'filterForm' => $filterForm, 'pagination' => $pagination)); }
public function actionUploadDict() { $sougouDir = Yii::$app->params['sougouDictDir']; $dictFiles = array(); if (file_exists($sougouDir)) { if (is_writable($sougouDir)) { $oDir = dir($sougouDir); while (($file = $oDir->read()) !== false) { if (strcasecmp($file, '.') != 0 && strcasecmp($file, '..') != 0) { $filename = $sougouDir . '/' . $file; if (is_dir($filename)) { $subDir = dir($filename); while (($subFile = $subDir->read()) !== false) { if (strcasecmp($subFile, '.') != 0 && strcasecmp($subFile, '..') != 0) { $dictFiles[$file][] = $subFile; } } } } } } else { exit('目录不可写'); } } $count = count($dictFiles); $page = isset($_REQUEST['page']) ? $_REQUEST['page'] ? $_REQUEST['page'] : 1 : 1; $pageSize = 10; $start = ($page - 1) * $pageSize; $pager = new \yii\data\Pagination(array('defaultPageSize' => $pageSize, 'totalCount' => $count)); if ($page > $pager->getPageCount() && $page != 1) { exit('超过最大页数'); } $data = array(); if ($count) { $sArr = array_slice($dictFiles, $start, $pageSize, true); foreach ($sArr as $time => $value) { if (!empty($value)) { foreach ($value as $key => $val) { if (preg_match('/\\.scel/', $val)) { $file = $sougouDir . '/' . $time . '/' . $val; $data[$time][$key] = array('filename' => mb_convert_encoding($val, 'UTF-8', 'GBK,GB2312'), 'filesize' => \app\common\XUtils::file_size_format(filesize($file)), 'filetype' => filetype($file), 'filetime' => date('Y-m-d H:i:s', filemtime($file))); } } } } } if (Yii::$app->request->isPost) { exit(json_encode(array('data' => $data, 'pager' => \yii\widgets\LinkPager::widget(['pagination' => $pager, 'prevPageLabel' => '上一页', 'nextPageLabel' => '下一页'])))); } return $this->render('uploaddict', array('data' => $data, 'pager' => $pager)); }
static function mkPage($ret, $start, $limit) { if ($start == 0 && $limit == 0) { $ret['cnt'] = count($ret['lst']); } else { $pages = new \yii\data\Pagination(['totalCount' => $ret['cnt']]); $pages->setPageSize($limit); $ret['pager'] = \yii\widgets\LinkPager::widget(['pagination' => $pages]); } }