added superexpert mode
This commit is contained in:
@@ -144,6 +144,62 @@ class User extends mfBaseModel {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function superexpertStart($duration = 1800) {
|
||||
if(!$this->can("Superexpert")) return false;
|
||||
|
||||
$ts = $this->getFlag("superexpert_lock_date");
|
||||
$ts->value(date("U") + $duration);
|
||||
$ts->save();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function superexpertStop($duration = 1800) {
|
||||
if(!$this->can("Superexpert")) return false;
|
||||
|
||||
$ts = $this->getFlag("superexpert_lock_date");
|
||||
$ts->value(0);
|
||||
$ts->save();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function superexpertExtend($duration = 1800) {
|
||||
if(!$this->can("Superexpert")) return false;
|
||||
|
||||
$ts = $this->getFlag("superexpert_lock_date");
|
||||
$ts->value(date("U") + $duration);
|
||||
$ts->save();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function superexpertEnabled() {
|
||||
if(!$this->can("Superexpert")) return false;
|
||||
|
||||
$tsFlag = $this->getFlag("superexpert_lock_date");
|
||||
$ts = $tsFlag->value();
|
||||
|
||||
if(!is_numeric($ts) || !$ts) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$now = date("U");
|
||||
|
||||
// if superexpert is longer than 60 minutes -> disable
|
||||
if($ts > $now + 3601) {
|
||||
$tsFlag->value(null);
|
||||
$tsFlag->save();
|
||||
return false;
|
||||
}
|
||||
|
||||
if($ts > $now) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getFlag($name) {
|
||||
return new WorkerFlag($this->id, $name);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user