|
1
|
|
|
<?php namespace core\src; |
|
2
|
|
|
|
|
3
|
|
|
use core\models\Route; |
|
4
|
|
|
use core\models\RouteQuery; |
|
5
|
|
|
|
|
6
|
|
|
class RouteSubscriber |
|
7
|
|
|
{ |
|
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
public function getHandlers() { |
|
10
|
|
|
return [ |
|
11
|
|
|
'Categories:create' => 'createCategoryRoute', |
|
12
|
|
|
'Categories:update' => 'updateCategoryRoute', |
|
13
|
|
|
'Categories:delete' => 'deleteCategoryRoute', |
|
14
|
|
|
|
|
15
|
|
|
'Page:create' => 'createPageRoute', |
|
16
|
|
|
'Page:update' => 'updatePageRoute', |
|
17
|
|
|
'Page:delete' => 'deletePageRoute', |
|
18
|
|
|
]; |
|
19
|
|
|
|
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function deletePageRoute($data) { |
|
23
|
|
|
RouteQuery::create()->filterByType(Route::TYPE_PAGE)->filterByEntityId($data['pageId'])->delete(); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function updatePageRoute($data) { |
|
27
|
|
|
$route = RouteQuery::create()->filterByType(Route::TYPE_PAGE)->findOneByEntityId($data['id']); |
|
28
|
|
|
|
|
29
|
|
|
if ($route) { |
|
30
|
|
|
$fullUrl = $data['cat_url'] . $data['url']; |
|
31
|
|
|
if ($route->getFullUrl() !== $fullUrl) { |
|
32
|
|
|
$route->setParentUrl(trim($data['cat_url'], '/')); |
|
33
|
|
|
$route->setUrl($data['url']); |
|
34
|
|
|
$route->save(); |
|
35
|
|
|
} |
|
36
|
|
|
} |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function createPageRoute($data) { |
|
40
|
|
|
$route = new Route(); |
|
41
|
|
|
$route->setEntityId($data['id']) |
|
42
|
|
|
->setType(Route::TYPE_PAGE) |
|
43
|
|
|
->setUrl($data['url']) |
|
44
|
|
|
->setParentUrl(trim($data['cat_url'], '/')) |
|
45
|
|
|
->save(); |
|
46
|
|
|
|
|
47
|
|
|
\CI::$APP->db->where('id', $data['id'])->update('content', ['route_id' => $route->getId()]); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function updateCategoryRoute($data) { |
|
51
|
|
|
|
|
52
|
|
|
$route = RouteQuery::create()->findOneById($data['route_id']); |
|
53
|
|
|
$parentRoute = RouteQuery::create()->filterByEntityId($data['parent_id'])->filterByType(Route::TYPE_CATEGORY)->findOne(); |
|
54
|
|
|
$parentUrl = $parentRoute ? $parentRoute->getFullUrl() : ''; |
|
55
|
|
|
$route->updateUrlRecursive($parentUrl, $data['url']); |
|
56
|
|
|
|
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function createCategoryRoute($data) { |
|
60
|
|
|
$parentCategoryId = $data['parent_id']; |
|
61
|
|
|
|
|
62
|
|
|
$route = new Route(); |
|
63
|
|
|
$route->setUrl($data['url']); |
|
64
|
|
|
$parentRoute = RouteQuery::create()->filterByEntityId($parentCategoryId)->filterByType(Route::TYPE_CATEGORY)->findOne(); |
|
65
|
|
|
|
|
66
|
|
|
if ($parentRoute) { |
|
67
|
|
|
$route->setParentUrl($parentRoute->getFullUrl()); |
|
68
|
|
|
} |
|
69
|
|
|
$route->setType(Route::TYPE_CATEGORY); |
|
70
|
|
|
$route->setEntityId($data['id']); |
|
71
|
|
|
$route->save(); |
|
72
|
|
|
|
|
73
|
|
|
\CI::$APP->db->where('id', $data['id'])->update('category', ['route_id' => $route->getId()]); |
|
74
|
|
|
|
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function deleteCategoryRoute($data) { |
|
78
|
|
|
RouteQuery::create()->filterByType(Route::TYPE_CATEGORY)->filterByEntityId($data['id'])->delete(); |
|
79
|
|
|
|
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
} |