46 lines
1.1 KiB
PHP
46 lines
1.1 KiB
PHP
|
<?php
|
||
|
|
||
|
use Insallah\Db;
|
||
|
|
||
|
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]);
|
||
|
}
|
||
|
}
|