@@ -13,84 +13,84 @@ |
||
13 | 13 | class UserList extends Controllers\ModuleController |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * UserRepository |
|
18 | - * @var \Core\Models\User\UserRepository |
|
19 | - */ |
|
20 | - protected $userRepository; |
|
21 | - |
|
22 | - /** |
|
23 | - * Request |
|
24 | - * @var Symfony\Component\HttpFoundation\Request |
|
25 | - */ |
|
26 | - protected $request; |
|
27 | - |
|
28 | - protected $limit = 5; |
|
29 | - |
|
30 | - function __construct(\Core\Models\User\UserRepository $userRepository, Request $request) |
|
31 | - { |
|
32 | - $this->userRepository = $userRepository; |
|
33 | - $this->request = $request; |
|
34 | - } |
|
35 | - |
|
36 | - public function process() |
|
37 | - { |
|
38 | - |
|
39 | - if ($this->request->query->get('fn') == 'add') { |
|
40 | - $this->add(); |
|
41 | - } |
|
42 | - |
|
43 | - $Users = $this->userRepository->findMany([],$this->limit); |
|
44 | - |
|
45 | - $table = Table::create(); |
|
46 | - $table->addColNames([0, 1, 2,3]); |
|
47 | - $table->addClass('table table-striped'); |
|
48 | - $table->thead() |
|
49 | - ->addRowName('head row') |
|
50 | - ->th('head row', 0, 'Id') |
|
51 | - ->th('head row', 1, 'Регистрация') |
|
52 | - ->th('head row', 2, 'Имя') |
|
53 | - ->th('head row', 3, 'Email'); |
|
54 | - $i = 0; |
|
55 | - foreach ($Users as $User) { |
|
56 | - $table->addRow($i)->tdMultiple([ |
|
57 | - $User->getId(), |
|
58 | - $User->getCreatedAt("d.m.Y"), |
|
59 | - $User->getName(), |
|
60 | - $User->getEmail()]); |
|
61 | - $i++; |
|
62 | - } |
|
63 | - |
|
64 | - return $this->render('default', [ |
|
65 | - 'table' => $table->render() |
|
66 | - ]); |
|
67 | - } |
|
68 | - |
|
69 | - protected function add() |
|
70 | - { |
|
71 | - |
|
72 | - try { |
|
73 | - |
|
74 | - $User = $this->userRepository->build(); |
|
75 | - $User->setEmail('[email protected]'); |
|
76 | - |
|
77 | - if (!$this->userRepository->save($User)) { |
|
78 | - throw new Exception('User not save'); |
|
79 | - } else { |
|
80 | - $this->logger->info("Пользователь успешно сохранен!"); |
|
81 | - } |
|
82 | - } catch(\Frameworkless\Exceptions\ValidationException $ex) { |
|
83 | - |
|
84 | - foreach ($ex->getFailures() as $failure) { |
|
85 | - $this->logger->error("Property " . $failure->getPropertyPath() . ": " . $failure->getMessage() . "\n"); |
|
86 | - } |
|
87 | - |
|
88 | - $this->logger->info("Произошла ошибка при сохранении пользователя"); |
|
89 | - } catch(\Exception $ex) { |
|
90 | - |
|
91 | - $this->logger->error("system error:" . $ex->getMessage()); |
|
92 | - |
|
93 | - $this->logger->info("Произошла ошибка при сохранении пользователя"); |
|
94 | - } |
|
95 | - } |
|
16 | + /** |
|
17 | + * UserRepository |
|
18 | + * @var \Core\Models\User\UserRepository |
|
19 | + */ |
|
20 | + protected $userRepository; |
|
21 | + |
|
22 | + /** |
|
23 | + * Request |
|
24 | + * @var Symfony\Component\HttpFoundation\Request |
|
25 | + */ |
|
26 | + protected $request; |
|
27 | + |
|
28 | + protected $limit = 5; |
|
29 | + |
|
30 | + function __construct(\Core\Models\User\UserRepository $userRepository, Request $request) |
|
31 | + { |
|
32 | + $this->userRepository = $userRepository; |
|
33 | + $this->request = $request; |
|
34 | + } |
|
35 | + |
|
36 | + public function process() |
|
37 | + { |
|
38 | + |
|
39 | + if ($this->request->query->get('fn') == 'add') { |
|
40 | + $this->add(); |
|
41 | + } |
|
42 | + |
|
43 | + $Users = $this->userRepository->findMany([],$this->limit); |
|
44 | + |
|
45 | + $table = Table::create(); |
|
46 | + $table->addColNames([0, 1, 2,3]); |
|
47 | + $table->addClass('table table-striped'); |
|
48 | + $table->thead() |
|
49 | + ->addRowName('head row') |
|
50 | + ->th('head row', 0, 'Id') |
|
51 | + ->th('head row', 1, 'Регистрация') |
|
52 | + ->th('head row', 2, 'Имя') |
|
53 | + ->th('head row', 3, 'Email'); |
|
54 | + $i = 0; |
|
55 | + foreach ($Users as $User) { |
|
56 | + $table->addRow($i)->tdMultiple([ |
|
57 | + $User->getId(), |
|
58 | + $User->getCreatedAt("d.m.Y"), |
|
59 | + $User->getName(), |
|
60 | + $User->getEmail()]); |
|
61 | + $i++; |
|
62 | + } |
|
63 | + |
|
64 | + return $this->render('default', [ |
|
65 | + 'table' => $table->render() |
|
66 | + ]); |
|
67 | + } |
|
68 | + |
|
69 | + protected function add() |
|
70 | + { |
|
71 | + |
|
72 | + try { |
|
73 | + |
|
74 | + $User = $this->userRepository->build(); |
|
75 | + $User->setEmail('[email protected]'); |
|
76 | + |
|
77 | + if (!$this->userRepository->save($User)) { |
|
78 | + throw new Exception('User not save'); |
|
79 | + } else { |
|
80 | + $this->logger->info("Пользователь успешно сохранен!"); |
|
81 | + } |
|
82 | + } catch(\Frameworkless\Exceptions\ValidationException $ex) { |
|
83 | + |
|
84 | + foreach ($ex->getFailures() as $failure) { |
|
85 | + $this->logger->error("Property " . $failure->getPropertyPath() . ": " . $failure->getMessage() . "\n"); |
|
86 | + } |
|
87 | + |
|
88 | + $this->logger->info("Произошла ошибка при сохранении пользователя"); |
|
89 | + } catch(\Exception $ex) { |
|
90 | + |
|
91 | + $this->logger->error("system error:" . $ex->getMessage()); |
|
92 | + |
|
93 | + $this->logger->info("Произошла ошибка при сохранении пользователя"); |
|
94 | + } |
|
95 | + } |
|
96 | 96 | } |
@@ -8,21 +8,21 @@ |
||
8 | 8 | class IndexController extends BaseController { |
9 | 9 | |
10 | 10 | |
11 | - /** |
|
12 | - * Return index page (/) |
|
13 | - * |
|
14 | - * @param array $args |
|
15 | - * @return Response |
|
16 | - */ |
|
17 | - public function get($args) { |
|
11 | + /** |
|
12 | + * Return index page (/) |
|
13 | + * |
|
14 | + * @param array $args |
|
15 | + * @return Response |
|
16 | + */ |
|
17 | + public function get($args) { |
|
18 | 18 | |
19 | - $result = \App::getModule(UserList::class,[ |
|
20 | - "limit" => 50 |
|
21 | - ]); |
|
19 | + $result = \App::getModule(UserList::class,[ |
|
20 | + "limit" => 50 |
|
21 | + ]); |
|
22 | 22 | |
23 | - return $this->render('pages/index.html.twig', [ |
|
24 | - "content" => $result, |
|
25 | - ]); |
|
26 | - } |
|
23 | + return $this->render('pages/index.html.twig', [ |
|
24 | + "content" => $result, |
|
25 | + ]); |
|
26 | + } |
|
27 | 27 | |
28 | 28 | } |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | class Application extends CoreApp |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
15 | + /** |
|
16 | 16 | * Gets the default commands that should always be available. |
17 | 17 | * |
18 | 18 | * @return array An array of default Command instances |
@@ -23,13 +23,13 @@ discard block |
||
23 | 23 | // which is used when using the --help option |
24 | 24 | $defaultCommands = parent::getDefaultCommands(); |
25 | 25 | |
26 | - $defaultCommands []= new Commands\InfoCommand(); |
|
27 | - $defaultCommands []= new Commands\InstallPackagesCommand; |
|
28 | - $defaultCommands []= new Commands\SeedBuildCommand; |
|
29 | - $defaultCommands []= new Commands\SeedResetCommand; |
|
30 | - $defaultCommands []= new Commands\InstallCommand; |
|
31 | - $defaultCommands []= new \Propel\Generator\Command\ConfigConvertCommand(); |
|
32 | - $defaultCommands []= new \Propel\Generator\Command\MigrationMigrateCommand(); |
|
26 | + $defaultCommands []= new Commands\InfoCommand(); |
|
27 | + $defaultCommands []= new Commands\InstallPackagesCommand; |
|
28 | + $defaultCommands []= new Commands\SeedBuildCommand; |
|
29 | + $defaultCommands []= new Commands\SeedResetCommand; |
|
30 | + $defaultCommands []= new Commands\InstallCommand; |
|
31 | + $defaultCommands []= new \Propel\Generator\Command\ConfigConvertCommand(); |
|
32 | + $defaultCommands []= new \Propel\Generator\Command\MigrationMigrateCommand(); |
|
33 | 33 | |
34 | 34 | return $defaultCommands; |
35 | 35 | } |