I18nMessage.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace common\modules\i18n\models;
  3. use Yii;
  4. /**
  5. * This is the model class for table "{{%i18n_message}}".
  6. *
  7. * @property integer $id
  8. * @property string $language
  9. * @property string $translation
  10. * @property string $sourceMessage
  11. * @property string $category
  12. *
  13. * @property I18nSourceMessage $sourceMessageModel
  14. */
  15. class I18nMessage extends \yii\db\ActiveRecord
  16. {
  17. public $category;
  18. public $sourceMessage;
  19. /**
  20. * @inheritdoc
  21. */
  22. public static function tableName()
  23. {
  24. return '{{%i18n_message}}';
  25. }
  26. /**
  27. * @inheritdoc
  28. */
  29. public function rules()
  30. {
  31. return [
  32. [['id', 'language'], 'required'],
  33. [['id'], 'exist', 'targetClass'=>I18nSourceMessage::className(), 'targetAttribute'=>'id'],
  34. [['translation'], 'string'],
  35. [['language'], 'string', 'max' => 16],
  36. [['language'], 'unique', 'targetAttribute' => ['id', 'language']]
  37. ];
  38. }
  39. /**
  40. * @inheritdoc
  41. */
  42. public function attributeLabels()
  43. {
  44. return [
  45. 'id' => Yii::t('backend', 'ID'),
  46. 'language' => Yii::t('backend', 'Language'),
  47. 'translation' => Yii::t('backend', 'Translation'),
  48. 'sourceMessage' => Yii::t('backend', 'Source Message'),
  49. 'category' => Yii::t('backend', 'Category'),
  50. ];
  51. }
  52. public function afterFind()
  53. {
  54. $this->sourceMessage = $this->sourceMessageModel ? $this->sourceMessageModel->message : null;
  55. $this->category = $this->sourceMessageModel ? $this->sourceMessageModel->category : null;
  56. return parent::afterFind();
  57. }
  58. /**
  59. * @return \yii\db\ActiveQuery
  60. */
  61. public function getSourceMessageModel()
  62. {
  63. return $this->hasOne(I18nSourceMessage::className(), ['id' => 'id']);
  64. }
  65. }