amdp3-metaforums/Application/Models/User.php

48 lines
1.9 KiB
PHP
Raw Normal View History

2019-11-18 13:33:45 +00:00
<?php
namespace Application\Models;
use Application\Foundations\Model as DBModel;
2019-11-19 03:36:39 +00:00
use Application\Foundations\QueryBuilder;
use Application\Services\ServiceContainer;
2019-11-18 13:33:45 +00:00
class User extends DBModel {
2019-11-19 03:36:39 +00:00
public function is_moderator_attribute() {
return ($this->role >= 2500);
}
public function is_admin_attribute() {
return ($this->role >= 100000);
}
public function role_string_attribute() {
if($this->is_admin) {
return "Site Admin";
} else if($this->is_moderator) {
return "Moderator";
}
return "User";
}
public function post_count_attribute() {
$query = new QueryBuilder();
$query = $query->select("COUNT(id) AS count")->from("post")->where("user_id",$this->id)->build();
$result = ServiceContainer::Database()->select($query);
return $result[0]["count"];
}
public function isBanned($cat_id) {
$where = new QueryBuilder();
$where = $where->where('user_id',$this->id)->where('category_id',$cat_id)->where('action_type','ban')->where('expired_at','>',date('Y-m-d H:i:s'))->orderBy('expired_at','desc');
$actions = UserAction::select($where);
return (count($actions) > 0);
}
public function isSilenced($cat_id) {
$where = new QueryBuilder();
$where = $where->where('user_id',$this->id)->where('category_id',$cat_id)->where('action_type','silence')->where('expired_at','>',date('Y-m-d H:i:s'))->orderBy('expired_at','desc');
$actions = UserAction::select($where);
return (count($actions) > 0);
}
public function isPardoned($thread_id) {
$where = new QueryBuilder();
$where = $where->where('user_id',$this->id)->where('thread_id',$thread_id)->where('action_type','silence')->where('expired_at','>',date('Y-m-d H:i:s'))->orderBy('expired_at','desc');
$actions = UserAction::select($where);
return (count($actions) > 0);
}
2019-11-18 13:33:45 +00:00
}