game/_incl_data/class/Learming.php

46 lines
1.1 KiB
PHP
Raw Normal View History

2022-12-19 20:22:19 +00:00
<?php
2022-12-30 19:03:37 +00:00
use Core\Db;
2022-12-19 20:22:19 +00:00
class Learming
{
private $uid;
private $shouldStartLearning;
public function __construct()
{
/** @var User $user */
$user = User::start();
$this->uid = $user->info['id'];
$this->shouldStartLearning = $user->info['shouldStartLearning'];
}
public function getLearningStatus()
{
if (!isset($this->shouldStartLearning)) {
Db::sql('insert into users_learming (uid) value (?)' ,
[$this->uid]);
return 1;
}
return (bool)$this->shouldStartLearning;
}
public function hasLearned()
{
if (!isset($this->shouldStartLearning)) {
return false;
}
$this->shouldStartLearning = 0;
$this->save();
return true;
}
private function save()
{
if (empty($this->uid) || empty($this->shouldStartLearning)) {
return;
}
Db::sql('replace into users_learming (uid, shouldStartLearming) values (?,?)',
[$this->uid, $this->shouldStartLearning]);
}
}