-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
247 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
use yii\helpers\Html; | ||
use yii\widgets\ActiveForm; | ||
|
||
/* @var $this yii\web\View */ | ||
/* @var $model app\models\ProblemSearch */ | ||
/* @var $form yii\widgets\ActiveForm */ | ||
?> | ||
|
||
<div class="problem-search"> | ||
|
||
<?php $form = ActiveForm::begin([ | ||
'action' => ['index'], | ||
'method' => 'get', | ||
'options' => [ | ||
'class' => 'form-inline', | ||
'data-pjax' => 1 | ||
], | ||
]); ?> | ||
|
||
<?= $form->field($model, 'id', [ | ||
'template' => "{label}\n<div class=\"input-group\"><span class=\"input-group-addon\"><span class='glyphicon glyphicon-sunglasses'></span> pid</span>{input}</div>", | ||
])->textInput(['maxlength' => 128, 'autocomplete'=>'off', 'placeholder' => 'Problem ID'])->label(false) ?> | ||
|
||
<?= $form->field($model, 'title', [ | ||
'template' => "{label}\n<div class=\"input-group\"><span class=\"input-group-addon\">标题</span>{input}</div>", | ||
])->textInput(['maxlength' => 128, 'autocomplete'=>'off', 'placeholder' => Yii::t('app', 'Title')])->label(false) ?> | ||
|
||
<?= $form->field($model, 'source', [ | ||
'template' => "{label}\n<div class=\"input-group\"><span class=\"input-group-addon\">来源</span>{input}</div>", | ||
])->textInput(['maxlength' => 128, 'autocomplete'=>'off', 'placeholder' => Yii::t('app', 'Source')])->label(false) ?> | ||
|
||
<div class="form-group"> | ||
<?= Html::submitButton(Yii::t('app', 'Search'), ['class' => 'btn btn-primary']) ?> | ||
<?= Html::resetButton(Yii::t('app', 'Reset'), ['class' => 'btn btn-default']) ?> | ||
</div> | ||
|
||
<?php ActiveForm::end(); ?> | ||
|
||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace app\modules\polygon\models; | ||
|
||
/** | ||
* This is the ActiveQuery class for [[Problem]]. | ||
* | ||
* @see PolygonProblem | ||
*/ | ||
class ProblemQuery extends \yii\db\ActiveQuery | ||
{ | ||
/*public function active() | ||
{ | ||
return $this->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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<?php | ||
|
||
namespace app\modules\polygon\models; | ||
|
||
use Yii; | ||
use yii\base\Model; | ||
use yii\data\ActiveDataProvider; | ||
use yii\db\Query; | ||
use app\modules\polygon\models\Problem; | ||
use app\models\User; | ||
|
||
/** | ||
* ProblemSearch represents the model behind the search form of `app\modules\polygon\models\Problem`. | ||
*/ | ||
class ProblemSearch extends Problem | ||
{ | ||
public $username; | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function rules() | ||
{ | ||
return [ | ||
[['id', 'spj', 'spj_lang', 'time_limit', 'memory_limit', 'status', 'accepted', 'submit', 'solved', 'solution_lang'], 'integer'], | ||
[['title', 'description', 'input', 'output', 'sample_input', 'sample_output', 'spj_source', 'hint', | ||
'source', 'tags', 'solution_source', 'created_at', 'updated_at', 'created_by', 'username'], 'safe'], | ||
]; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function scenarios() | ||
{ | ||
// bypass scenarios() implementation in the parent class | ||
return Model::scenarios(); | ||
} | ||
|
||
/** | ||
* Creates data provider instance with search query applied | ||
* | ||
* @param array $params | ||
* | ||
* @return ActiveDataProvider | ||
*/ | ||
public function search($params) | ||
{ | ||
$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, | ||
]); | ||
|
||
$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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
use yii\helpers\Html; | ||
use yii\widgets\ActiveForm; | ||
|
||
/* @var $this yii\web\View */ | ||
/* @var $model app\modules\polygon\models\ProblemSearch */ | ||
/* @var $form yii\widgets\ActiveForm */ | ||
?> | ||
|
||
<div class="problem-search"> | ||
|
||
<?php $form = ActiveForm::begin([ | ||
'action' => ['index'], | ||
'method' => 'get', | ||
'options' => [ | ||
'class' => 'form-inline', | ||
'data-pjax' => 1 | ||
], | ||
]); ?> | ||
|
||
<?= $form->field($model, 'id', [ | ||
'template' => "{label}\n<div class=\"input-group\"><span class=\"input-group-addon\"><span class='glyphicon glyphicon-sunglasses'></span></span>{input}</div>", | ||
])->textInput(['maxlength' => 128, 'autocomplete'=>'off', 'placeholder' => 'ID'])->label(false) ?> | ||
|
||
<?= $form->field($model, 'title', [ | ||
'template' => "{label}\n<div class=\"input-group\"><span class=\"input-group-addon\"><span class='glyphicon glyphicon-text-size'></span></span>{input}</div>", | ||
])->textInput(['maxlength' => 128, 'autocomplete'=>'off', 'placeholder' => Yii::t('app', 'Title')])->label(false) ?> | ||
|
||
<?= $form->field($model, 'username', [ | ||
'template' => "{label}\n<div class=\"input-group\"><span class=\"input-group-addon\"><span class='glyphicon glyphicon-user'></span></span>{input}</div>", | ||
])->textInput(['maxlength' => 128, 'autocomplete'=>'off', 'placeholder' => Yii::t('app', 'Who')])->label(false) ?> | ||
|
||
|
||
<div class="form-group"> | ||
<?= Html::submitButton(Yii::t('app', 'Search'), ['class' => 'btn btn-primary']) ?> | ||
<?= Html::resetButton(Yii::t('app', 'Reset'), ['class' => 'btn btn-default']) ?> | ||
</div> | ||
|
||
<?php ActiveForm::end(); ?> | ||
|
||
</div> |
Oops, something went wrong.