Newer
Older
<?php
namespace QUI\Memberships;
use QUI\CRUD\Factory;
use QUI\Utils\Grid;
use QUI;
class Handler extends Factory
{
/**
* @inheritdoc
*/
public function createChild($data = array())
{
$data['createDate'] = time();
$data['createUser'] = QUI::getUserBySession()->getId();
$title = $data['title'];
$data['title'] = array();
foreach (QUI::availableLanguages() as $lang) {
$data['title'][$lang] = $title;
}
$data['title'] = json_encode($data['title']);
return parent::createChild($data);
}
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
/**
* @inheritdoc
* @return string
*/
public function getDataBaseTableName()
{
return 'quiqqer_memberships';
}
/**
* @inheritdoc
* @return string
*/
public function getChildClass()
{
return Membership::class;
}
/**
* @inheritdoc
* @return array
*/
public function getChildAttributes()
{
return array(
'title',
'description',
'content',
'duration',
'groupIds',
'autoRenew',
'editDate',
'editUser',
'createDate',
'createUser',
// these fields require quiqqer/order
'paymentInterval',
'netPrice',
'netPriceOffer',
// 'grossPrice',
'paymentMethodIds'
// @todo additional fields for quiqqer/contracts
);
}
/**
* Search memberships
*
* @param array $searchParams
* @param bool $countOnly (optional) - get count for search result only [default: false]
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
*/
public function search($searchParams, $countOnly = false)
{
$memberships = array();
$Grid = new Grid($searchParams);
$gridParams = $Grid->parseDBParams($searchParams);
$whereOr = array();
if (!empty($searchParams['search'])) {
$search = $searchParams['search'];
$whereOr['title'] = array(
'type' => '%LIKE%',
'value' => $search
);
$whereOr['description'] = array(
'type' => '%LIKE%',
'value' => $search
);
$whereOr['content'] = array(
'type' => '%LIKE%',
'value' => $search
);
}
if ($countOnly) {
$result = QUI::getDataBase()->fetch(array(
'count' => 1,
'from' => $this->getDataBaseTableName(),
'where_or' => $whereOr
));
return current(current($result));
}
$result = QUI::getDataBase()->fetch(array(
'select' => array(
'id'
),
'from' => $this->getDataBaseTableName(),
'where_or' => $whereOr,
'limit' => $gridParams['limit']
));
foreach ($result as $row) {
/**
* Get list of all packages that are relevant for quiqqer/memberships
* and that are currently installed
*
* @return array
*/
public function getInstalledMembershipPackages()
{
$packages = array();
try {
QUI::getPackage('quiqqer/products');
$packages[] = 'quiqqer/products';
} catch (\Exception $Exception) {
}
try {
QUI::getPackage('quiqqer/contracts');
$packages[] = 'quiqqer/contracts';
} catch (\Exception $Exception) {
}
return $packages;
}