InquirerLog.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace app\models;
  3. use Yii;
  4. /**
  5. * This is the model class for table "inquirer_log".
  6. *
  7. * @property int $id
  8. * @property int $idq
  9. * @property string $hash
  10. * @property string $dt
  11. */
  12. class InquirerLog extends \yii\db\ActiveRecord
  13. {
  14. public $resetTime = 60*60;
  15. /**
  16. * {@inheritdoc}
  17. */
  18. public static function tableName()
  19. {
  20. return 'inquirer_log';
  21. }
  22. /**
  23. * {@inheritdoc}
  24. */
  25. public function rules()
  26. {
  27. return [
  28. [['idq', 'hash','ida'], 'required'],
  29. [['idq'], 'integer'],
  30. [['ida'], 'integer'],
  31. [['id'], 'integer'],
  32. [['hash'], 'string', 'max' => 64],
  33. ];
  34. }
  35. /**
  36. * {@inheritdoc}
  37. */
  38. public function attributeLabels()
  39. {
  40. return [
  41. 'id' => 'ID',
  42. 'idq' => 'id вопроса',
  43. 'ida' => 'id щтвета',
  44. 'hash' => 'Hash',
  45. 'dt' => 'дата голоса',
  46. ];
  47. }
  48. /**
  49. * {@inheritdoc}
  50. */
  51. public function test($idq, $ida, $hash)
  52. {
  53. $r = $this->findOne(['idq'=>$idq, 'ida'=>$ida, 'hash'=>$hash]);
  54. if( $r && strtotime( $r->dt ) > time() - $this->resetTime ){
  55. return true;
  56. }
  57. return false;
  58. }
  59. public function testq($idq, $hash)
  60. {
  61. $r = $this->find()->where(['idq'=>$idq, 'hash'=>$hash])->orderBy('dt DESC')->limit(1)->one();
  62. if( $r && strtotime( $r->dt ) > time() - $this->resetTime ){
  63. return true;
  64. }
  65. return false;
  66. }
  67. public function add($idq, $ida, $hash)
  68. {
  69. $this->ida = $ida;
  70. $this->idq = $idq;
  71. $this->hash = $hash;
  72. return $this->save();
  73. }
  74. }