Notification.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace app\models;
  3. use Yii;
  4. /**
  5. * This is the model class for table "messages".
  6. *
  7. * @property integer $id
  8. * @property integer $user_id
  9. * @property string $notes
  10. * @property string $date
  11. * @property integer $status
  12. */
  13. class Notification extends \yii\db\ActiveRecord
  14. {
  15. /**
  16. * @inheritdoc
  17. */
  18. public static function tableName()
  19. {
  20. return 'messages';
  21. }
  22. /**
  23. * @inheritdoc
  24. */
  25. public function rules()
  26. {
  27. return [
  28. [['user_id', 'notes', 'date'], 'required'],
  29. [['user_id', 'status'], 'integer'],
  30. [['date'], 'safe'],
  31. [['notes'], 'string', 'max' => 255]
  32. ];
  33. }
  34. /**
  35. * @inheritdoc
  36. */
  37. public function attributeLabels()
  38. {
  39. return [
  40. 'id' => Yii::t('app', 'ID'),
  41. 'user_id' => Yii::t('app', 'User ID'),
  42. 'notes' => Yii::t('app', 'Notes'),
  43. 'date' => Yii::t('app', 'Date'),
  44. 'status' => Yii::t('app', 'Status'),
  45. ];
  46. }
  47. public function fields()
  48. {
  49. return [
  50. 'count_messages' => function () {
  51. $sql = Yii::$app->db->createCommand("SELECT count(*) as msg from messages WHERE status=0 AND user_id=:user_id");
  52. $sql->bindValue(':user_id', Yii::$app->user->identity->id);
  53. $result = $sql->queryOne();
  54. return $result['msg'];
  55. },
  56. 'count_bids' => function () {
  57. if(Yii::$app->user->can('member'))
  58. {
  59. $sql = Yii::$app->db->createCommand("SELECT count(*) as bid from bidding WHERE readed=0 AND user_id=:user_id");
  60. }
  61. else
  62. {
  63. $sql = Yii::$app->db->createCommand("SELECT count(*) as bid from bidding WHERE readed=0 AND org_id=:user_id");
  64. }
  65. $sql->bindValue(':user_id', Yii::$app->user->identity->id);
  66. $result = $sql->queryOne();
  67. return $result['bid'];
  68. },
  69. ];
  70. }
  71. }