Files
thetool/application/User/User.php
Frank Schubert 4ea4927931 Initial commit
2021-03-29 23:04:42 +02:00

91 lines
2.0 KiB
PHP

<?php
/**
* Description of User
*
* @author fronk
*/
class User extends mfBaseModel {
public $permissions;
public $flags;
public function init() {
$this->table = "Worker";
if(defined("MFUSERTABLE")) {
$this->table = MFUSERTABLE;
}
}
/**
* Loads currently logged in user
*/
public function loadMe() {
if(defined("INTERNAL_USER_ID") && is_numeric(INTERNAL_USER_ID)) {
$this->fetch(INTERNAL_USER_ID);
return true;
}
$username = $_SESSION[MFAPPNAME.'_username'];
$res = $this->db->select($this->table,"*","username='$username' LIMIT 1");
if($this->db->num_rows($res)) {
$data = $this->db->fetch_object($res);
$this->load($data);
return true;
}
return false;
}
protected function afterLoad() {
$wp = new WorkerPermission();
$wp->loadByUserId($this->id);
$this->permissions = $wp;
$this->loadFlags();
return true;
}
public function getFlag($name) {
return new WorkerFlag($this->id, $name);
}
private function loadFlags() {
$res = $this->db->select("WorkerFlag", "*", "worker_id=".$this->id);
if(!$this->db->num_rows($res)) {
return false;
}
while($data = $this->db->fetch_object($res)) {
$this->flags[$data->name] = $data->value;
}
}
protected function afterSave() {
$this->afterLoad();
}
protected function afterDelete() {
if(is_object($this->permissions)) {
$this->permissions->delete();
}
}
public function is($what) {
if(is_object($this->permissions) && property_exists($this->permissions, "is$what")) {
return $this->permissions->{"is$what"};
}
}
public function isAdmin() {
if(is_object($this->permissions) && property_exists($this->permissions, "isAdmin")) {
return $this->permissions->isAdmin;
}
$this->log->warning("No permissions object in user");
return false;
}
public function __toString() {
return $this->username;
}
}