1
|
|
|
<?php
|
2
|
|
|
namespace Core\Modules\UserList;
|
3
|
|
|
|
4
|
|
|
use Frameworkless\Controllers;
|
5
|
|
|
use Donquixote\Cellbrush\Table\Table;
|
6
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
7
|
|
|
|
8
|
|
|
/**
|
9
|
|
|
* Description of UserListController
|
10
|
|
|
*
|
11
|
|
|
* @author d.lanec
|
12
|
|
|
*/
|
13
|
|
|
class UserList extends Controllers\ModuleController{
|
14
|
|
|
|
15
|
|
|
/**
|
16
|
|
|
* UserRepository
|
17
|
|
|
* @var \Core\Models\User\UserRepository
|
18
|
|
|
*/
|
19
|
|
|
protected $userRepository;
|
20
|
|
|
|
21
|
|
|
/**
|
22
|
|
|
* Request
|
23
|
|
|
* @var Symfony\Component\HttpFoundation\Request
|
24
|
|
|
*/
|
25
|
|
|
protected $request;
|
26
|
|
|
|
27
|
|
|
protected $limit = 5;
|
28
|
|
|
|
29
|
|
|
function __construct(\Core\Models\User\UserRepository $userRepository, Request $request){
|
|
|
|
|
30
|
|
|
$this->userRepository = $userRepository;
|
31
|
|
|
$this->request = $request;
|
|
|
|
|
32
|
|
|
}
|
33
|
|
|
|
34
|
|
|
public function process(){
|
35
|
|
|
|
36
|
|
|
if($this->request->query->get('fn') == 'add'){
|
37
|
|
|
$this->add();
|
38
|
|
|
}
|
39
|
|
|
|
40
|
|
|
$Users = $this->userRepository->findMany([], $this->limit);
|
|
|
|
|
41
|
|
|
|
42
|
|
|
$table = Table::create();
|
43
|
|
|
$table->addColNames([0, 1, 2, 3]);
|
44
|
|
|
$table->addClass('table table-striped');
|
45
|
|
|
$table->thead()
|
46
|
|
|
->addRowName('head row')
|
47
|
|
|
->th('head row', 0, 'Id')
|
48
|
|
|
->th('head row', 1, 'Регистрация')
|
49
|
|
|
->th('head row', 2, 'Имя')
|
50
|
|
|
->th('head row', 3, 'Email');
|
51
|
|
|
$i = 0;
|
52
|
|
|
foreach($Users as $User){
|
53
|
|
|
$table->addRow($i)->tdMultiple([
|
54
|
|
|
$User->getId(),
|
55
|
|
|
$User->getCreatedAt("d.m.Y"),
|
56
|
|
|
$User->getName(),
|
57
|
|
|
$User->getEmail()]);
|
58
|
|
|
$i++;
|
59
|
|
|
}
|
60
|
|
|
|
61
|
|
|
return $this->render('default', [
|
62
|
|
|
'table' => $table->render()
|
63
|
|
|
]);
|
64
|
|
|
}
|
65
|
|
|
|
66
|
|
|
protected function add(){
|
67
|
|
|
|
68
|
|
|
try{
|
69
|
|
|
|
70
|
|
|
$User = $this->userRepository->build();
|
71
|
|
|
$User->setEmail('[email protected]');
|
72
|
|
|
|
73
|
|
|
if(!$this->userRepository->save($User)){
|
74
|
|
|
throw new Exception('User not save');
|
75
|
|
|
} else{
|
76
|
|
|
$this->logger->info("Пользователь успешно сохранен!");
|
77
|
|
|
}
|
78
|
|
|
} catch(\Frameworkless\Exceptions\ValidationException $ex){
|
79
|
|
|
|
80
|
|
|
foreach($ex->getFailures() as $failure){
|
81
|
|
|
$this->logger->error("Property " . $failure->getPropertyPath() . ": " . $failure->getMessage() . "\n");
|
82
|
|
|
}
|
83
|
|
|
|
84
|
|
|
$this->logger->info("Произошла ошибка при сохранении пользователя");
|
85
|
|
|
} catch(\Exception $ex){
|
86
|
|
|
|
87
|
|
|
$this->logger->error("system error:" . $ex->getMessage());
|
88
|
|
|
|
89
|
|
|
$this->logger->info("Произошла ошибка при сохранении пользователя");
|
90
|
|
|
}
|
91
|
|
|
}
|
92
|
|
|
}
|
93
|
|
|
|