UserDevice.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php /** Created by Anton on 29.01.2020. */
  2. namespace app\models\entity;
  3. /**
  4. * This is the model class for table "user_device".
  5. *
  6. * @property int $id
  7. * @property int $employee
  8. * @property int $phone
  9. * @property int $camera
  10. * @property int $oil_meter
  11. */
  12. class UserDevice extends \yii\db\ActiveRecord
  13. {
  14. const PHONE_FIELD = 'phone';
  15. const CAMERA_FIELD = 'camera';
  16. const OIL_METER_FIELD = 'oil_meter';
  17. private $fields = [
  18. 1 => self::CAMERA_FIELD,
  19. 2 => self::OIL_METER_FIELD,
  20. 3 => self::PHONE_FIELD
  21. ];
  22. /**
  23. * {@inheritdoc}
  24. */
  25. public static function tableName()
  26. {
  27. return 'user_device';
  28. }
  29. /**
  30. * {@inheritdoc}
  31. */
  32. public function rules()
  33. {
  34. return [
  35. [['employee', 'phone', 'camera', 'oil_meter'], 'integer'],
  36. ];
  37. }
  38. /**
  39. * @return \yii\db\ActiveQuery
  40. */
  41. public function getEmployee()
  42. {
  43. return $this->hasOne(Accounts::class, ['id' => 'employee']);
  44. }
  45. /**
  46. * @return \yii\db\ActiveQuery
  47. */
  48. public function getPhone()
  49. {
  50. return $this->hasOne(Log::class, ['id' => 'phone']);
  51. }
  52. /**
  53. * @return \yii\db\ActiveQuery
  54. */
  55. public function getCamera()
  56. {
  57. return $this->hasOne(Log::class, ['id' => 'camera']);
  58. }
  59. /**
  60. * @return \yii\db\ActiveQuery
  61. */
  62. public function getOilMeter()
  63. {
  64. return $this->hasOne(Log::class, ['id' => 'oil_meter']);
  65. }
  66. public function getFieldNameById(int $id)
  67. {
  68. return $this->fields[$id];
  69. }
  70. }