1
|
|
|
<?php |
2
|
|
|
/*************************************************************************************/ |
3
|
|
|
/* This file is part of the RewriteUrl module for Thelia. */ |
4
|
|
|
/* */ |
5
|
|
|
/* Copyright (c) OpenStudio */ |
6
|
|
|
/* email : [email protected] */ |
7
|
|
|
/* web : http://www.thelia.net */ |
8
|
|
|
/* */ |
9
|
|
|
/* For the full copyright and license information, please view the LICENSE.txt */ |
10
|
|
|
/* file that was distributed with this source code. */ |
11
|
|
|
/*************************************************************************************/ |
12
|
|
|
|
13
|
|
|
namespace RewriteUrl\Loop; |
14
|
|
|
|
15
|
|
|
use Propel\Runtime\ActiveQuery\Criteria; |
16
|
|
|
use Thelia\Core\Template\Element\BaseI18nLoop; |
17
|
|
|
use Thelia\Core\Template\Element\LoopResult; |
18
|
|
|
use Thelia\Core\Template\Element\LoopResultRow; |
19
|
|
|
use Thelia\Core\Template\Element\PropelSearchLoopInterface; |
20
|
|
|
use Thelia\Core\Template\Loop\Argument\Argument; |
21
|
|
|
use Thelia\Core\Template\Loop\Argument\ArgumentCollection; |
22
|
|
|
use Thelia\Model\Base\BrandQuery; |
23
|
|
|
use Thelia\Model\Brand; |
24
|
|
|
use Thelia\Model\Category; |
25
|
|
|
use Thelia\Model\CategoryQuery; |
26
|
|
|
use Thelia\Model\Content; |
27
|
|
|
use Thelia\Model\ContentQuery; |
28
|
|
|
use Thelia\Model\Folder; |
29
|
|
|
use Thelia\Model\FolderQuery; |
30
|
|
|
use Thelia\Model\LangQuery; |
31
|
|
|
use Thelia\Model\Map\RewritingUrlTableMap; |
32
|
|
|
use Thelia\Model\Product; |
33
|
|
|
use Thelia\Model\ProductQuery; |
34
|
|
|
use Thelia\Model\RewritingUrlQuery; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Class NotRewritenUrlCategoryLoop |
38
|
|
|
* @package RewriteUrl\Loop |
39
|
|
|
* @author Tom Pradat <[email protected]> |
40
|
|
|
* @author Gilles Bourgeat <[email protected]> |
41
|
|
|
* |
42
|
|
|
* @method string getView() |
43
|
|
|
*/ |
44
|
|
|
class NotRewritenUrlCategoryLoop extends BaseI18nLoop implements PropelSearchLoopInterface |
45
|
|
|
{ |
46
|
|
|
protected static $cacheRewritingUrl = []; |
47
|
|
|
|
48
|
|
|
protected function getArgDefinitions() |
49
|
|
|
{ |
50
|
|
|
return new ArgumentCollection( |
51
|
|
|
Argument::createEnumListTypeArgument( |
52
|
|
|
'view', |
53
|
|
|
['product', 'category', 'folder', 'content', 'brand'] |
54
|
|
|
) |
55
|
|
|
); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function buildModelCriteria() |
59
|
|
|
{ |
60
|
|
|
$view = $this->getView()[0]; |
61
|
|
|
|
62
|
|
|
$rewritingUrlQuery = RewritingUrlQuery::create(); |
63
|
|
|
|
64
|
|
|
$class = 'Thelia\Model\\' . ucfirst($view) . 'Query'; |
65
|
|
|
/** @var CategoryQuery|ProductQuery|FolderQuery|ContentQuery|BrandQuery $objectQuery */ |
66
|
|
|
$objectQuery = $class::create(); |
67
|
|
|
|
68
|
|
|
$localeSearch = LangQuery::create()->findByIdOrLocale($this->getLang()); |
69
|
|
|
|
70
|
|
|
$rewritingUrlQuery->filterByView($view)->filterByViewLocale( |
71
|
|
|
$localeSearch !== null ? $localeSearch->getLocale() : 'en_US' |
72
|
|
|
); |
73
|
|
|
|
74
|
|
|
if (!isset(static::$cacheRewritingUrl[$view])) { |
75
|
|
|
static::$cacheRewritingUrl[$view] = $rewritingUrlQuery |
76
|
|
|
->select([RewritingUrlTableMap::VIEW_ID]) |
77
|
|
|
->groupBy(RewritingUrlTableMap::VIEW_ID) |
78
|
|
|
->find(); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
$query = $objectQuery |
82
|
|
|
->filterById(static::$cacheRewritingUrl[$view]->getData(), Criteria::NOT_IN); |
83
|
|
|
|
84
|
|
|
/* manage translations */ |
85
|
|
|
$this->configureI18nProcessing($query, ['TITLE']); |
86
|
|
|
|
87
|
|
|
return $query; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function parseResults(LoopResult $loopResult) |
91
|
|
|
{ |
92
|
|
|
/** @var Category|Product|Folder|Content|Brand $category */ |
93
|
|
|
foreach ($loopResult->getResultDataCollection() as $category) { |
94
|
|
|
$loopResultRow = (new LoopResultRow($category)) |
95
|
|
|
->set('ID', $category->getId()) |
96
|
|
|
->set('NAME', $category->getVirtualColumn('i18n_TITLE')); |
97
|
|
|
|
98
|
|
|
if (property_exists($category, 'ref')) { |
99
|
|
|
$loopResultRow->set('REF', $category->getRef()); |
100
|
|
|
} |
101
|
|
|
$loopResult->addRow($loopResultRow); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
return $loopResult; |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|