12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- <?php
- namespace app\models;
- use Yii;
- /**
- * This is the model class for table "inquirer_log".
- *
- * @property int $id
- * @property int $idq
- * @property string $hash
- * @property string $dt
- */
- class InquirerLog extends \yii\db\ActiveRecord
- {
- public $resetTime = 60*60;
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return 'inquirer_log';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['idq', 'hash','ida'], 'required'],
- [['idq'], 'integer'],
- [['ida'], 'integer'],
- [['id'], 'integer'],
- [['hash'], 'string', 'max' => 64],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'idq' => 'id вопроса',
- 'ida' => 'id щтвета',
- 'hash' => 'Hash',
- 'dt' => 'дата голоса',
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function test($idq, $ida, $hash)
- {
- $r = $this->findOne(['idq'=>$idq, 'ida'=>$ida, 'hash'=>$hash]);
- if( $r && strtotime( $r->dt ) > time() - $this->resetTime ){
- return true;
- }
- return false;
- }
- public function testq($idq, $hash)
- {
- $r = $this->find()->where(['idq'=>$idq, 'hash'=>$hash])->orderBy('dt DESC')->limit(1)->one();
- if( $r && strtotime( $r->dt ) > time() - $this->resetTime ){
- return true;
- }
- return false;
- }
- public function add($idq, $ida, $hash)
- {
- $this->ida = $ida;
- $this->idq = $idq;
- $this->hash = $hash;
- return $this->save();
- }
- }
|