Skip to content

Commit

Permalink
trip
Browse files Browse the repository at this point in the history
  • Loading branch information
alex210 committed Oct 4, 2018
1 parent f27a8cc commit f84e2e9
Show file tree
Hide file tree
Showing 15 changed files with 798 additions and 52 deletions.
6 changes: 6 additions & 0 deletions common/config/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@
'@bower' => '@vendor/bower-asset',
'@npm' => '@vendor/npm-asset',
],
'language' => 'ru-RU',
'vendorPath' => dirname(dirname(__DIR__)) . '/vendor',
'components' => [
'cache' => [
'class' => 'yii\caching\FileCache',
],
],
'modules' => [
'gridview' => [
'class' => '\kartik\grid\Module'
]
]
];
73 changes: 73 additions & 0 deletions common/models/Trip.php
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']);
}
}
72 changes: 72 additions & 0 deletions common/models/TripSearch.php
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;
}
}
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
"php": ">=5.4.0",
"yiisoft/yii2": "~2.0.6",
"yiisoft/yii2-bootstrap": "~2.0.0",
"yiisoft/yii2-swiftmailer": "~2.0.0 || ~2.1.0"
"yiisoft/yii2-swiftmailer": "~2.0.0 || ~2.1.0",
"kartik-v/yii2-widget-datepicker": "dev-master",
"kartik-v/yii2-widget-datetimepicker": "^1.4",
"kartik-v/yii2-grid": "dev-master"
},
"require-dev": {
"yiisoft/yii2-debug": "~2.0.0",
Expand Down
Loading

0 comments on commit f84e2e9

Please sign in to comment.