From 293eabfa7bdceeb8d4f0890e0a73c166a50425a0 Mon Sep 17 00:00:00 2001 From: shi-yang Date: Sun, 3 Mar 2019 07:49:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=A2=98=E7=9B=AE=E6=A3=80?= =?UTF-8?q?=E7=B4=A2=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + models/ProblemSearch.php | 4 +- models/SolutionSearch.php | 2 +- .../admin/controllers/ProblemController.php | 10 +- modules/admin/views/problem/_search.php | 41 +++++++ modules/admin/views/problem/index.php | 2 + .../polygon/controllers/DefaultController.php | 15 +-- .../polygon/controllers/ProblemController.php | 11 +- modules/polygon/models/ProblemQuery.php | 34 ++++++ modules/polygon/models/ProblemSearch.php | 105 ++++++++++++++++++ modules/polygon/views/default/index.php | 3 + modules/polygon/views/problem/_search.php | 42 +++++++ modules/polygon/views/problem/index.php | 3 + views/problem/_search.php | 40 ------- 14 files changed, 247 insertions(+), 66 deletions(-) create mode 100644 modules/admin/views/problem/_search.php create mode 100644 modules/polygon/models/ProblemQuery.php create mode 100644 modules/polygon/models/ProblemSearch.php create mode 100644 modules/polygon/views/problem/_search.php delete mode 100644 views/problem/_search.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 09e711edc..097a119d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ JNOJ Change Log SPJ 的参数输入顺序修改为输入文件、选手输出、标准答案。**为保证SPJ题目的准确性,更新后需要你改写题目的SPJ**。具体参考OJ 的 Wiki。示例区别在于: 旧版本SPJ写法示例为`FILE * f_in = fopen(args[1],"r"); FILE * f_outr = fopen(args[2],"r");FILE * f_use = fopen(args[3],"r");`, 新版本SPJ写法示例为`FILE * f_in = fopen(args[1],"r"); FILE * f_user = fopen(args[2],"r");FILE * f_out = fopen(args[3],"r");` +- Enh: [web] 添加题目检索功能 0.7.0 2019.2.1 ------------------------ diff --git a/models/ProblemSearch.php b/models/ProblemSearch.php index 966be9c4b..3fc2a1cf9 100644 --- a/models/ProblemSearch.php +++ b/models/ProblemSearch.php @@ -2,10 +2,8 @@ namespace app\models; -use Yii; use yii\base\Model; use yii\data\ActiveDataProvider; -use app\models\Problem; /** * ProblemSearch represents the model behind the search form of `app\models\Problem`. @@ -41,7 +39,7 @@ public function scenarios() */ public function search($params) { - $query = Problem::find()->where(['status' => Problem::STATUS_VISIBLE]); + $query = Problem::find()->orderBy(['id' => SORT_DESC])->with('user'); // add conditions that should always apply here diff --git a/models/SolutionSearch.php b/models/SolutionSearch.php index ec773c230..bfd4da5fc 100644 --- a/models/SolutionSearch.php +++ b/models/SolutionSearch.php @@ -90,7 +90,7 @@ public function search($params, $contest_id = NULL) ->from('{{%user}}') ->andWhere('nickname=:name', [':name' => $this->username]) ->orWhere('username=:name', [':name' => $this->username]) - ->column(); + ->scalar(); } // grid filtering conditions $query->andFilterWhere([ diff --git a/modules/admin/controllers/ProblemController.php b/modules/admin/controllers/ProblemController.php index 995dd7c56..5a563263d 100644 --- a/modules/admin/controllers/ProblemController.php +++ b/modules/admin/controllers/ProblemController.php @@ -3,6 +3,7 @@ namespace app\modules\admin\controllers; use app\models\ContestProblem; +use app\models\ProblemSearch; use Yii; use yii\data\ActiveDataProvider; use yii\db\Query; @@ -61,12 +62,8 @@ public function behaviors() */ public function actionIndex() { - $dataProvider = new ActiveDataProvider([ - 'query' => Problem::find()->orderBy(['id' => SORT_DESC])->with('user'), - 'pagination' => [ - 'pageSize' => 50 - ] - ]); + $searchModel = new ProblemSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); if (Yii::$app->request->isPost) { $keys = Yii::$app->request->post('keylist'); @@ -81,6 +78,7 @@ public function actionIndex() return $this->render('index', [ 'dataProvider' => $dataProvider, + 'searchModel' => $searchModel ]); } diff --git a/modules/admin/views/problem/_search.php b/modules/admin/views/problem/_search.php new file mode 100644 index 000000000..1caff11e1 --- /dev/null +++ b/modules/admin/views/problem/_search.php @@ -0,0 +1,41 @@ + + + diff --git a/modules/admin/views/problem/index.php b/modules/admin/views/problem/index.php index f995c61ce..39c09e14f 100644 --- a/modules/admin/views/problem/index.php +++ b/modules/admin/views/problem/index.php @@ -5,6 +5,7 @@ use yii\bootstrap\Modal; /* @var $this yii\web\View */ +/* @var $searchModel app\models\ProblemSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = Yii::t('app', 'Problems'); @@ -31,6 +32,7 @@ 设为私有

+ render('_search', ['model' => $searchModel]); ?> $dataProvider, 'options' => ['id' => 'grid'], diff --git a/modules/polygon/controllers/DefaultController.php b/modules/polygon/controllers/DefaultController.php index 483c60456..0f2de6ca1 100644 --- a/modules/polygon/controllers/DefaultController.php +++ b/modules/polygon/controllers/DefaultController.php @@ -2,11 +2,12 @@ namespace app\modules\polygon\controllers; -use app\models\User; use Yii; use yii\web\Controller; -use app\modules\polygon\models\Problem; use yii\data\ActiveDataProvider; +use app\modules\polygon\models\Problem; +use app\models\User; +use app\modules\polygon\models\ProblemSearch; /** * Default controller for the `polygon` module @@ -19,16 +20,12 @@ class DefaultController extends Controller */ public function actionIndex() { - $query = Problem::find()->with('user')->orderBy(['id' => SORT_DESC]); - if (Yii::$app->user->isGuest || Yii::$app->user->identity->role != User::ROLE_ADMIN) { - $query->andWhere(['created_by' => Yii::$app->user->id]); - } - $dataProvider = new ActiveDataProvider([ - 'query' => $query - ]); + $searchModel = new ProblemSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return $this->render('index', [ 'dataProvider' => $dataProvider, + 'searchModel' => $searchModel ]); } } diff --git a/modules/polygon/controllers/ProblemController.php b/modules/polygon/controllers/ProblemController.php index c03d0af8f..e7bb39d60 100644 --- a/modules/polygon/controllers/ProblemController.php +++ b/modules/polygon/controllers/ProblemController.php @@ -4,6 +4,7 @@ use app\models\Solution; use app\modules\polygon\models\PolygonStatus; +use app\modules\polygon\models\ProblemSearch; use Yii; use app\models\User; use app\modules\polygon\models\Problem; @@ -53,16 +54,12 @@ public function behaviors() public function actionIndex() { $this->layout = '/main'; - $query = Problem::find()->with('user')->orderBy(['id' => SORT_DESC]); - if (Yii::$app->user->identity->role != User::ROLE_ADMIN) { - $query->andWhere(['created_by' => Yii::$app->user->id]); - } - $dataProvider = new ActiveDataProvider([ - 'query' => $query - ]); + $searchModel = new ProblemSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return $this->render('index', [ 'dataProvider' => $dataProvider, + 'searchModel' => $searchModel ]); } diff --git a/modules/polygon/models/ProblemQuery.php b/modules/polygon/models/ProblemQuery.php new file mode 100644 index 000000000..993eadd3d --- /dev/null +++ b/modules/polygon/models/ProblemQuery.php @@ -0,0 +1,34 @@ +andWhere('[[status]]=1'); + }*/ + + /** + * {@inheritdoc} + * @return Problem[]|array + */ + public function all($db = null) + { + return parent::all($db); + } + + /** + * {@inheritdoc} + * @return Problem|array|null + */ + public function one($db = null) + { + return parent::one($db); + } +} diff --git a/modules/polygon/models/ProblemSearch.php b/modules/polygon/models/ProblemSearch.php new file mode 100644 index 000000000..9f28d5743 --- /dev/null +++ b/modules/polygon/models/ProblemSearch.php @@ -0,0 +1,105 @@ +with('user')->orderBy(['id' => SORT_DESC]); + + if (Yii::$app->user->isGuest || Yii::$app->user->identity->role != User::ROLE_ADMIN) { + $query->andWhere(['created_by' => Yii::$app->user->id]); + } + + $dataProvider = new ActiveDataProvider([ + 'query' => $query, + ]); + + $this->load($params); + + if (!$this->validate()) { + // uncomment the following line if you do not want to return any records when validation fails + // $query->where('0=1'); + return $dataProvider; + } + + if (!empty($this->username)) { + $this->created_by = (new Query())->select('id') + ->from('{{%user}}') + ->andWhere('nickname=:name', [':name' => $this->username]) + ->orWhere('username=:name', [':name' => $this->username]) + ->scalar(); + } + + // grid filtering conditions + $query->andFilterWhere([ + 'id' => $this->id, + 'spj' => $this->spj, + 'spj_lang' => $this->spj_lang, + 'time_limit' => $this->time_limit, + 'memory_limit' => $this->memory_limit, + 'status' => $this->status, + 'accepted' => $this->accepted, + 'submit' => $this->submit, + 'solved' => $this->solved, + 'solution_lang' => $this->solution_lang, + 'created_at' => $this->created_at, + 'updated_at' => $this->updated_at, + 'created_by' => $this->created_by, + ]); + + $query->andFilterWhere(['like', 'title', $this->title]) + ->andFilterWhere(['like', 'description', $this->description]) + ->andFilterWhere(['like', 'input', $this->input]) + ->andFilterWhere(['like', 'output', $this->output]) + ->andFilterWhere(['like', 'sample_input', $this->sample_input]) + ->andFilterWhere(['like', 'sample_output', $this->sample_output]) + ->andFilterWhere(['like', 'spj_source', $this->spj_source]) + ->andFilterWhere(['like', 'hint', $this->hint]) + ->andFilterWhere(['like', 'source', $this->source]) + ->andFilterWhere(['like', 'tags', $this->tags]) + ->andFilterWhere(['like', 'solution_source', $this->solution_source]); + + return $dataProvider; + } +} diff --git a/modules/polygon/views/default/index.php b/modules/polygon/views/default/index.php index f80531e50..b8989ebe2 100644 --- a/modules/polygon/views/default/index.php +++ b/modules/polygon/views/default/index.php @@ -4,6 +4,7 @@ use yii\helpers\Html; /* @var $this yii\web\View */ +/* @var $searchModel app\modules\polygon\models\ProblemSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = Yii::t('app', 'Polygon System'); @@ -29,6 +30,8 @@ 'btn btn-success']) ?>

+ render('/problem/_search', ['model' => $searchModel]); ?> + $dataProvider, 'columns' => [ diff --git a/modules/polygon/views/problem/_search.php b/modules/polygon/views/problem/_search.php new file mode 100644 index 000000000..f078afd4d --- /dev/null +++ b/modules/polygon/views/problem/_search.php @@ -0,0 +1,42 @@ + + + diff --git a/modules/polygon/views/problem/index.php b/modules/polygon/views/problem/index.php index c3f1b80e9..00fffaa5c 100644 --- a/modules/polygon/views/problem/index.php +++ b/modules/polygon/views/problem/index.php @@ -4,6 +4,7 @@ use yii\grid\GridView; /* @var $this yii\web\View */ +/* @var $searchModel app\modules\polygon\models\ProblemSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = Yii::t('app', 'Problems'); @@ -18,6 +19,8 @@ 'btn btn-success']) ?>

+ render('_search', ['model' => $searchModel]); ?> + $dataProvider, 'columns' => [ diff --git a/views/problem/_search.php b/views/problem/_search.php deleted file mode 100644 index e3070bdf3..000000000 --- a/views/problem/_search.php +++ /dev/null @@ -1,40 +0,0 @@ - - -