1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace core\models; |
4
|
|
|
|
5
|
|
|
use core\models\Base\Route as BaseRoute; |
6
|
|
|
use core\src\CoreConfiguration; |
7
|
|
|
use core\src\CoreFactory; |
8
|
|
|
use Propel\Runtime\ActiveQuery\Criteria; |
9
|
|
|
use Propel\Runtime\Collection\ObjectCollection; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Skeleton subclass for representing a row from the 'route' table. |
13
|
|
|
* |
14
|
|
|
* |
15
|
|
|
* |
16
|
|
|
* You should add additional methods to this class to meet the |
|
|
|
|
17
|
|
|
* application requirements. This class will only be generated as |
18
|
|
|
* long as it does not already exist in the output directory. |
19
|
|
|
* |
20
|
|
|
*/ |
|
|
|
|
21
|
|
|
class Route extends BaseRoute |
22
|
|
|
{ |
|
|
|
|
23
|
|
|
const TYPE_SHOP_CATEGORY = 'shop_category'; |
24
|
|
|
const TYPE_PRODUCT = 'product'; |
25
|
|
|
const TYPE_CATEGORY = 'category'; |
26
|
|
|
const TYPE_PAGE = 'page'; |
27
|
|
|
const TYPE_MAIN = 'main'; |
28
|
|
|
const TYPE_MODULE = 'module'; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param string $newParentUrl |
32
|
|
|
* @param string $newUrl |
33
|
|
|
*/ |
34
|
|
|
public function updateUrlRecursive($newParentUrl, $newUrl) { |
35
|
|
|
|
36
|
|
|
$oldUrl = $this->getFullUrl(); |
37
|
|
|
|
38
|
|
|
if ($oldUrl !== $newParentUrl . '/' . $newUrl) { |
39
|
|
|
$this->setParentUrl($newParentUrl); |
40
|
|
|
$this->setUrl($newUrl); |
41
|
|
|
$this->save(); |
42
|
|
|
RouteQuery::create()->updateParentUrl($oldUrl, $this->getFullUrl()); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @return string |
49
|
|
|
*/ |
50
|
|
|
public function getRouteUrl() { |
51
|
|
|
return self::createRouteUrl($this->getUrl(), $this->getParentUrl(), $this->getType()); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return string |
56
|
|
|
*/ |
57
|
|
|
public function getFullUrl() { |
58
|
|
|
$url = $this->getParentUrl() ? $this->getParentUrl() . '/' . $this->getUrl() : $this->getUrl(); |
59
|
|
|
return $url; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @return Route[]|ObjectCollection |
64
|
|
|
*/ |
65
|
|
|
public function getPathRoutes() { |
66
|
|
|
$parent = $this->getParentUrl(); |
67
|
|
|
|
68
|
|
|
$collection = new ObjectCollection(); |
69
|
|
|
$collection->setModel(get_class($this)); |
70
|
|
|
|
71
|
|
|
if ($parent) { |
72
|
|
|
$segments = explode('/', $parent); |
73
|
|
|
$collection = RouteQuery::create()->orderByParentUrl(Criteria::ASC)->filterByUrl($segments, Criteria::IN)->find(); |
|
|
|
|
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
$collection->append($this); |
77
|
|
|
|
78
|
|
|
return $collection; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param string $url |
83
|
|
|
* @param string $parentUrl |
84
|
|
|
* @param int $type |
85
|
|
|
* @return string |
86
|
|
|
*/ |
87
|
|
|
public static function createRouteUrl($url, $parentUrl, $type) { |
88
|
|
|
$urlConfiguration = CoreFactory::getConfiguration()->getUrlRules(); |
89
|
|
|
|
90
|
|
|
if (array_key_exists($type, $urlConfiguration)) { |
91
|
|
|
$rules = $urlConfiguration[$type]; |
92
|
|
|
} else { |
93
|
|
|
$rules = [ |
94
|
|
|
'prefix' => '', |
95
|
|
|
'parent' => true, |
96
|
|
|
]; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
if ($rules['parent'] && $parentUrl) { |
100
|
|
|
$url = $parentUrl . '/' . $url; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
if ($rules['prefix']) { |
104
|
|
|
$url = $rules['prefix'] . '/' . $url; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
return $url; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
} |