You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

101 regels
3.1 KiB

  1. <?php
  2. namespace backend\modules\motorcade\models;
  3. use Yii;
  4. use yii\base\Model;
  5. use yii\data\ActiveDataProvider;
  6. use yii\db\BaseActiveRecord;
  7. /**
  8. * DriverSearch represents the model behind the search form about `backend\modules\motorcade\models\BaseDriver`.
  9. */
  10. class DriverSearch extends BaseDriver
  11. {
  12. /**
  13. * @inheritdoc
  14. */
  15. public function rules()
  16. {
  17. return [
  18. [['DRIVER_ID', 'CREATE_USER_ID', 'UPDATE_USER_ID', 'CANCEL_FLAG', 'SEX', 'AGE', 'MAIN_CORP_ID', 'ORG_ID', 'DRIVER_STATUS', 'AREA_ID', 'VALID_YEARS'], 'integer'],
  19. [['CREATE_TIME', 'UPDATE_TIME', 'DRIVER_NAME', 'DRIVER_NUMBER', 'PHONE_NO', 'ID_NUMBER', 'LICENSE_NO', 'DRIVER_BIRTHDAY', 'FIRST_LICENSE_DATE', 'ADDRESS', 'LICENSE_START_DATE'], 'safe'],
  20. ];
  21. }
  22. public function init(){
  23. BaseActiveRecord::init();
  24. }
  25. /**
  26. * @inheritdoc
  27. */
  28. public function scenarios()
  29. {
  30. // bypass scenarios() implementation in the parent class
  31. return Model::scenarios();
  32. }
  33. /**
  34. * Creates data provider instance with search query applied
  35. *
  36. * @param array $params
  37. *
  38. * @return ActiveDataProvider
  39. */
  40. public function search($params)
  41. {
  42. $query = BaseDriver::find()->with('organization');
  43. // add conditions that should always apply here
  44. $dataProvider = new ActiveDataProvider([
  45. 'query' => $query,
  46. ]);
  47. $this->load($params);
  48. // grid filtering conditions
  49. $query->andFilterWhere([
  50. // 'DRIVER_ID' => $this->DRIVER_ID,
  51. 'CREATE_USER_ID' => $this->CREATE_USER_ID,
  52. 'UPDATE_USER_ID' => $this->UPDATE_USER_ID,
  53. 'UPDATE_TIME' => $this->UPDATE_TIME,
  54. 'CANCEL_FLAG' => 0,
  55. 'SEX' => $this->SEX,
  56. 'AGE' => $this->AGE,
  57. 'MAIN_CORP_ID' => Yii::$app->user->identity->MAIN_CORP_ID2,
  58. 'ORG_ID' => $this->ORG_ID,
  59. 'DRIVER_STATUS' => $this->DRIVER_STATUS,
  60. 'AREA_ID' => $this->AREA_ID,
  61. 'VALID_YEARS' => $this->VALID_YEARS,
  62. 'DRIVER_ID' => $this->DRIVER_NAME,
  63. ]);
  64. $query->andFilterWhere(['like', 'CREATE_TIME', $this->CREATE_TIME])
  65. ->andFilterWhere(['like', 'DRIVER_NUMBER', $this->DRIVER_NUMBER])
  66. ->andFilterWhere(['like', 'PHONE_NO', $this->PHONE_NO])
  67. ->andFilterWhere(['like', 'ID_NUMBER', $this->ID_NUMBER])
  68. ->andFilterWhere(['like', 'LICENSE_NO', $this->LICENSE_NO])
  69. ->andFilterWhere(['like', 'DRIVER_BIRTHDAY', $this->DRIVER_BIRTHDAY])
  70. ->andFilterWhere(['like', 'FIRST_LICENSE_DATE', $this->FIRST_LICENSE_DATE])
  71. ->andFilterWhere(['like', 'ADDRESS', $this->ADDRESS])
  72. ->andFilterWhere(['like', 'LICENSE_START_DATE', $this->LICENSE_START_DATE]);
  73. $dataProvider->setSort([
  74. 'attributes' => [
  75. 'DRIVER_ID',
  76. 'DRIVER_NAME',
  77. 'DRIVER_NUMBER',
  78. 'ORG_ID',
  79. // 'PHONE_NO',
  80. 'LICENSE_NO',
  81. // 'ID_NUMBER',
  82. // 'SEX',
  83. ]
  84. ]);
  85. return $dataProvider;
  86. }
  87. }