Initial commit
This commit is contained in:
90
application/User/User.php
Normal file
90
application/User/User.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user