Этот коммит содержится в:
2019-11-12 01:45:36 +03:00
родитель e2ac280221
Коммит 50e81a1298
19 изменённых файлов: 569 добавлений и 97 удалений

Просмотреть файл

@@ -3,8 +3,9 @@
namespace MyApp\Controller;
use MyApp\Core\Controller;
use MyApp\Model\GroupsModel as Model;
use MyApp\View\GroupsView as View;
use MyApp\Service\GroupsService;
use MyApp\Service\GroupsService as Service;
class GroupsController extends Controller
{
@@ -13,29 +14,62 @@ class GroupsController extends Controller
*/
public function index()
{
$this->htmlResponse((new View())->index((new GroupsService())->getTableData()));
$this->htmlResponse((new View())->index((new Service())->getTableData()));
}
/**
* @RouteRegExp = "|^/groups/add$|"
* @HttpMethod = "GET,POST"
*/
public function add()
{
$service = new Service();
if (!empty($_POST)) {
/** @var Model $model */
$model = $service->addGroup((string) $_POST['name'],
(int) $_POST['parent']);
if ($model) {
$this->redirect('/groups/edit/'.$model->getId());
}
}
$select = $service->sortForSelect($service->getTableData());
$this->htmlResponse((new View())->add($select));
}
/**
* @RouteRegExp = "|^/groups/delete$|"
* @HttpMethod = "POST"
*/
public function delete()
{
if (!empty($_POST)) {
(new Service())->deleteGroup((int) $_POST['id']);
}
}
/**
* @RouteRegExp = "|^/groups/edit/(?<id>\d+)$|"
* @HttpMethod = "GET,POST"
*
* @param $id
*
* @throws \Exception
*/
public function edit($id)
{
$group_service = new GroupsService();
$service = new Service();
$model = $group_service->getGroup($id);
$model = !empty($_POST) ? $service->updateGroup((int) $id,
(string) $_POST['name'],
(int) $_POST['parent']) : $service->getGroup((int) $id);
if ($model) {
$this->htmlResponse((new View())->edit($group_service->getGroup($id),
$group_service->getTableData()));
$select = $service->sortForSelect($service->getTableData());
$this->htmlResponse((new View())->edit($model, $select));
} else {
$this->redirect('/groups');
}

Просмотреть файл

@@ -3,6 +3,9 @@
namespace MyApp\Controller;
use MyApp\Core\Controller;
use MyApp\View\ServersView as View;
use MyApp\Service\ServersService as Service;
use MyApp\Service\GroupsService;
class ServersController extends Controller
{
@@ -11,20 +14,62 @@ class ServersController extends Controller
*/
public function index()
{
$this->htmlResponse((new View())->index((new Service())->getTableData()));
}
/**
* @RouteRegExp = "|^/servers/add$|"
* @HttpMethod = "GET,POST"
*/
public function add()
{
$service = new Service();
if (!empty($_POST)) {
/** @var \MyApp\Model\ServersModel $model */
$model = $service->addServer((string) $_POST['name'],
(string) $_POST['ip'], (int) $_POST['group']);
if ($model) {
$this->redirect('/servers/edit/'.$model->getId());
}
}
$group_service = new GroupsService();
$select = $group_service->sortForSelect($group_service->getTableData());
$this->htmlResponse((new View())->add($select));
}
/**
* @RouteRegExp = "|^/servers/edit/(?<id>\d+)$|"
* @HttpMethod = "GET,POST"
*/
public function edit($id)
{
$service = new Service();
$model = !empty($_POST) ? $service->updateServer((int) $id,
(string) $_POST['name'], (string) $_POST['ip'],
(int) $_POST['group']) : $service->getServer((int) $id);
if ($model) {
$group_service = new GroupsService();
$select = $group_service->sortForSelect($group_service->getTableData());
$this->htmlResponse((new View())->edit($model, $select));
} else {
$this->redirect('/servers');
}
}
/**
* @RouteRegExp = "|^/servers/delete$|"
* @HttpMethod = "POST"
*/
public function delete()
{
if (!empty($_POST)) {
(new Service())->deleteServer((int) $_POST['id']);
}
}
}