src/Model/UserPref.php line 84

Open in your IDE?
  1. <?php
  2. namespace App\Model;
  3. class UserPref implements \JsonSerializable
  4. {
  5.     private $username;
  6.     private $preference// type - black, white, disabled, enabled
  7.     private $value;
  8.     private $prefid;
  9.     
  10.     const DEFAULT_SPAM_SCORE 4.0;
  11.     const DEFAULT_QUARANTINE_THRESHOLD 6.0;
  12.     const DEFAULT_DELETE_THRESHOLD 12.0;
  13.     const SA_MAX_SCORE 50// default
  14.     const SA_MAX_SCORE_LIMIT 999// maximum possible default
  15.     
  16.     public function __construct()
  17.     {
  18.         $this->prefid 0;
  19.     }
  20.     
  21.     public function getUsername(): ?string
  22.     {
  23.         return $this->username;
  24.     }
  25.     
  26.     public function setUsername(string $name): self
  27.     {
  28.         $this->username $name;
  29.         
  30.         return $this;
  31.     }
  32.     
  33.     public function getPreference(): ?string
  34.     {
  35.         if(substr($this->preference04) == "_NA_") {
  36.             return substr($this->preference4);
  37.         }
  38.         
  39.         return $this->preference;
  40.     }
  41.     
  42.     public function setPreference(string $preference): self
  43.     {
  44.         $this->preference $preference;
  45.         
  46.         return $this;
  47.     }
  48.     
  49.     public function getValue(): ?string
  50.     {
  51.         return $this->value;
  52.     }
  53.     
  54.     public function setValue(string $value): self
  55.     {
  56.         $this->value $value;
  57.         
  58.         return $this;
  59.     }
  60.     
  61.     public function getPrefid(): ?int
  62.     {
  63.         return $this->prefid;
  64.     }
  65.     
  66.     public function setPrefid(int $prefid): self
  67.     {
  68.         $this->prefid $prefid;
  69.         
  70.         return $this;
  71.     }
  72.     
  73.     public function isEnabled() : bool
  74.     {
  75.         if(substr($this->preference04) == "_NA_") {
  76.             return false;
  77.         }
  78.         
  79.         return true;
  80.     }
  81.     
  82.     public function jsonSerialize()
  83.     {
  84.         $vars get_object_vars($this);
  85.         return $vars;
  86.     }
  87.     
  88.     public static function cmpObjectsByVal($o1$o2)
  89.     {
  90.         return strcasecmp($o1->getValue(), $o2->getValue());
  91.     }
  92.     
  93.     public static function cmpObjectsByValDesc($o1$o2)
  94.     {
  95.         return UserPref::cmpObjectsByVal($o2$o1);
  96.     }
  97.     
  98.     public static function cmpObjectsByPreference($o1$o2)
  99.     {
  100.         return strcasecmp($o1->getPreference(), $o2->getPreference());
  101.     }
  102.     
  103.     public static function cmpObjectsByPreferenceDesc($o1$o2)
  104.     {
  105.         return UserPref::cmpObjectsByPreference($o2$o1) ;
  106.     }
  107.     
  108.     public static function cmpObjectsByEnableStatus($o1$o2)
  109.     {
  110.         if($o1->isEnabled() && !$o2->isEnabled()) {
  111.             return 1;
  112.         }
  113.         
  114.         if(!$o1->isEnabled() && $o2->isEnabled()) {
  115.             return -1;
  116.         }
  117.         
  118.         return 0;
  119.     }
  120.     
  121.     public static function cmpObjectsByEnableStatusDesc($o1$o2)
  122.     {
  123.         return UserPref::cmpObjectsByEnableStatus($o2$o1);
  124.     }
  125. }