-
Notifications
You must be signed in to change notification settings - Fork 0
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
15 changed files
with
798 additions
and
52 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
namespace common\models; | ||
|
||
use Yii; | ||
use yii\behaviors\TimestampBehavior; | ||
use yii\db\ActiveRecord; | ||
|
||
/** | ||
* This is the model class for table "trip". | ||
* | ||
* @property int $id | ||
* @property int $created_at | ||
* @property int $date | ||
* @property int $driver | ||
* @property int $user_id | ||
*/ | ||
class Trip extends \yii\db\ActiveRecord | ||
{ | ||
public function behaviors() | ||
{ | ||
return [ | ||
[ | ||
'class' => TimestampBehavior::className(), | ||
'attributes' => [ | ||
ActiveRecord::EVENT_BEFORE_INSERT => ['created_at'] | ||
], | ||
'value' => date("Y-m-d H:i:s") | ||
] | ||
]; | ||
} | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function tableName() | ||
{ | ||
return 'trip'; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function rules() | ||
{ | ||
return [ | ||
[['created_at', 'date'], 'safe'], | ||
[['driver', 'user_id'], 'integer'], | ||
]; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function attributeLabels() | ||
{ | ||
return [ | ||
'created_at' => 'Дата добавления', | ||
'date' => 'Дата поездки', | ||
'driver' => 'Водитель', | ||
'user_id' => 'Кто добавил', | ||
]; | ||
} | ||
|
||
public function getDriverName() | ||
{ | ||
return $this->hasOne(User::className(), ['id' => 'driver']); | ||
} | ||
|
||
public function getUser() | ||
{ | ||
return $this->hasOne(User::className(), ['id' => 'user_id']); | ||
} | ||
} |
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,72 @@ | ||
<?php | ||
|
||
namespace common\models; | ||
|
||
use Yii; | ||
use yii\base\Model; | ||
use yii\data\ActiveDataProvider; | ||
use common\models\Trip; | ||
|
||
/** | ||
* Trip1Search represents the model behind the search form of `common\models\Trip1`. | ||
*/ | ||
class TripSearch extends Trip | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function rules() | ||
{ | ||
return [ | ||
[['id', 'driver', 'user_id'], 'integer'], | ||
[['created_at', 'date'], '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 = Trip::find(); | ||
|
||
// add conditions that should always apply here | ||
|
||
$dataProvider = new ActiveDataProvider([ | ||
'query' => $query, | ||
'sort'=> ['defaultOrder' => ['date' => SORT_DESC]] | ||
]); | ||
|
||
$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; | ||
} | ||
|
||
// grid filtering conditions | ||
$query->andFilterWhere([ | ||
'id' => $this->id, | ||
'created_at' => $this->created_at, | ||
'date' => $this->date, | ||
'driver' => $this->driver, | ||
'user_id' => $this->user_id, | ||
]); | ||
|
||
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
Oops, something went wrong.