forked from thelia/thelia
/
ModuleQuery.php
97 lines (85 loc) · 2.82 KB
/
ModuleQuery.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
namespace Thelia\Model;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Thelia\Log\Tlog;
use Thelia\Model\Base\ModuleQuery as BaseModuleQuery;
use Thelia\Module\BaseModule;
/**
* Skeleton subclass for performing query and update operations on the 'module' table.
*
*
*
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
*
*/
class ModuleQuery extends BaseModuleQuery
{
protected static $activated = null;
/**
* @return array|mixed|\PropelObjectCollection
*/
public static function getActivated()
{
if (null === self::$activated) {
self::$activated = self::create()
->filterByActivate(BaseModule::IS_ACTIVATED)
->orderByPosition()
->find();
}
return self::$activated;
}
public static function resetActivated()
{
self::$activated = null;
}
/**
* @param int $moduleType the module type : classic, payment or delivery. Use BaseModule constant here.
* @param int $id the module id
* @return ModuleQuery
*/
public function filterActivatedByTypeAndId($moduleType, $id)
{
return $this
->filterByType($moduleType)
->filterByActivate(BaseModule::IS_ACTIVATED)
->filterById($id);
}
/**
*
* if the container is provided, this method will found the module in the container. Reflection is used instead.
* If it's possible use it with the container.
*
* return false if no delivery modules are found, an array of BaseModule otherwise.
*
* @param ContainerInterface $container optional
* @return false|\Thelia\Module\BaseModule[]
*/
public function retrieveVirtualProductDelivery(ContainerInterface $container = null)
{
$modules = $this
->filterByType(BaseModule::DELIVERY_MODULE_TYPE)
->filterByActivate(BaseModule::IS_ACTIVATED)
->find()
;
$result = [];
/** @var \Thelia\Model\Module $module */
foreach ($modules as $module) {
try {
if (null !== $container) {
$instance = $module->getDeliveryModuleInstance($container);
} else {
$instance = $module->createInstance();
}
if (true === $instance->handleVirtualProductDelivery()) {
$result[] = $instance;
}
} catch (\Exception $ex) {
Tlog::getInstance()->addError("Failed to instantiate module ".$module->getCode(), $ex);
}
}
return empty($result) ? false : $result;
}
}
// ModuleQuery