Setting.php
Go to the documentation of this file.
1 <?php
2 namespace App\Models;
3 
6 
7 class Setting extends Model
8 {
9  protected $injectUniqueIdentifier = true;
10  use ValidatingTrait;
11 
12  protected $rules = [
13  "brand" => 'required|min:1|numeric',
14  "qr_text" => 'min:1|max:31',
15  "custom_css" => 'string',
16  "slack_endpoint" => 'url',
17  "default_currency" => 'required',
18  "slack_channel" => 'regex:/(?<!\w)#\w+/',
19  "slack_botname" => 'string',
20  "ldap_server" => 'sometimes|required_if:ldap_enabled,1|url',
21  "ldap_uname" => 'sometimes|required_if:ldap_enabled,1',
22  "ldap_pword" => 'sometimes|required_if:ldap_enabled,1',
23  "ldap_basedn" => 'sometimes|required_if:ldap_enabled,1',
24  "ldap_filter" => 'sometimes|required_if:ldap_enabled,1',
25  "ldap_username_field" => 'sometimes|required_if:ldap_enabled,1',
26  "ldap_lname_field" => 'sometimes|required_if:ldap_enabled,1',
27  "ldap_auth_filter_query" => 'sometimes|required_if:ldap_enabled,1',
28  "ldap_version" => 'sometimes|required_if:ldap_enabled,1',
29  ];
30 
31  protected $fillable = ['site_name'];
32 
33  public static function getSettings()
34  {
35  static $static_cache = null;
36 
37  if (!$static_cache) {
38  $static_cache = Setting::first();
39  }
40  return $static_cache;
41  }
42 
43  public function lar_ver()
44  {
45  $app = \App::getFacadeApplication();
46  return $app::VERSION;
47  }
48 
49  public static function getDefaultEula()
50  {
51 
52  $Parsedown = new \Parsedown();
53  if (Setting::getSettings()->default_eula_text) {
54  return $Parsedown->text(e(Setting::getSettings()->default_eula_text));
55  } else {
56  return null;
57  }
58 
59  }
60 
61  public function show_custom_css()
62  {
63  $custom_css = Setting::getSettings()->custom_css;
64  $custom_css = e($custom_css);
65  // Needed for modifying the bootstrap nav :(
66  $custom_css = str_ireplace('script', 'SCRIPTS-NOT-ALLOWED-HERE', $custom_css);
67  $custom_css = str_replace('&gt;', '>', $custom_css);
68  return $custom_css;
69  }
70 
78  public static function fileSizeConvert($bytes)
79  {
80  $bytes = floatval($bytes);
81  $arBytes = array(
82  0 => array(
83  "UNIT" => "TB",
84  "VALUE" => pow(1024, 4)
85  ),
86  1 => array(
87  "UNIT" => "GB",
88  "VALUE" => pow(1024, 3)
89  ),
90  2 => array(
91  "UNIT" => "MB",
92  "VALUE" => pow(1024, 2)
93  ),
94  3 => array(
95  "UNIT" => "KB",
96  "VALUE" => 1024
97  ),
98  4 => array(
99  "UNIT" => "B",
100  "VALUE" => 1
101  ),
102  );
103 
104  foreach ($arBytes as $arItem) {
105  if ($bytes >= $arItem["VALUE"]) {
106  $result = $bytes / $arItem["VALUE"];
107  $result = round($result, 2) .$arItem["UNIT"];
108  break;
109  }
110  }
111  return $result;
112  }
113 }
static getSettings()
Definition: Setting.php:33
static getDefaultEula()
Definition: Setting.php:49
static fileSizeConvert($bytes)
Converts bytes into human readable file size.
Definition: Setting.php:78