1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Controllers\Admin\User\Traits; |
4
|
|
|
|
5
|
|
|
trait HelpersTrait |
6
|
|
|
{ |
7
|
|
|
private function formatUsers($users) |
8
|
|
|
{ |
9
|
|
|
$users_for_list = []; |
10
|
|
|
|
11
|
|
|
foreach ($users as $user) { |
12
|
|
|
$user->new = $this->isUserNew($user->registration); |
13
|
|
|
$user->country_icon = $this->countries($user->country); |
|
|
|
|
14
|
|
|
$user->registration = $this->changeFormatDate($user->registration); |
|
|
|
|
15
|
|
|
$user->last_login = $this->changeFormatDate($user->last_login); |
16
|
|
|
$users_for_list[] = $user; |
17
|
|
|
} |
18
|
|
|
return $users_for_list; |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
private function isUserNew($date) |
22
|
|
|
{ |
23
|
|
|
if (!$date) { |
24
|
|
|
return; |
25
|
|
|
} |
26
|
|
|
$register_year = $this->changeFormatDate($date, ['Y-m-d H:i:s', 'Y']); |
27
|
|
|
$register_month = $this->changeFormatDate($date, ['Y-m-d H:i:s', 'm']); |
28
|
|
|
$register_day = $this->changeFormatDate($date, ['Y-m-d H:i:s', 'd']); |
29
|
|
|
|
30
|
|
|
$year = date('Y'); |
31
|
|
|
$month = date('m'); |
32
|
|
|
$day = date('d'); |
33
|
|
|
|
34
|
|
|
$years = $year - $register_year; |
35
|
|
|
|
36
|
|
|
if ($years === 0) { |
37
|
|
|
$months = $month - $register_month; |
38
|
|
|
|
39
|
|
|
if ($months === 0) { |
40
|
|
|
$days = $day - $register_day; |
41
|
|
|
|
42
|
|
|
if ($days < 1) { |
43
|
|
|
return 1; |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
return 0; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
private function validatorPasses($filters, $name) |
51
|
|
|
{ |
52
|
|
|
foreach ($filters as $func => $arg) { |
53
|
|
|
if (method_exists($this->validator, $func) == 1) { |
54
|
|
|
if (gettype($arg) === 'boolean') { |
55
|
|
|
if ($arg) { |
56
|
|
|
$this->validator->input($name)->$func(); |
57
|
|
|
} |
58
|
|
|
} else { |
59
|
|
|
$this->validator->input($name)->$func($arg); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
return $this->validator->passes(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
private function getUserConfigColumns() |
67
|
|
|
{ |
68
|
|
|
$columns = $this->file->fileContent('config/admin/users/columns.json'); |
69
|
|
|
return json_decode($columns); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|