1 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,223 +0,0 @@ |
1 |
-<?php |
|
2 |
- |
|
3 |
-declare(strict_types=1); |
|
4 |
- |
|
5 |
-/* |
|
6 |
- * This file is part of Oveleon ContaoMemberExtension Bundle. |
|
7 |
- * |
|
8 |
- * @package contao-member-extension-bundle |
|
9 |
- * @license MIT |
|
10 |
- * @author Daniele Sciannimanica <https://github.com/doishub> |
|
11 |
- * @author Fabian Ekert <https://github.com/eki89> |
|
12 |
- * @author Sebastian Zoglowek <https://github.com/zoglo> |
|
13 |
- * @copyright Oveleon <https://www.oveleon.de/> |
|
14 |
- */ |
|
15 |
- |
|
16 |
-namespace Oveleon\ContaoMemberExtensionBundle; |
|
17 |
- |
|
18 |
-use Contao\BackendTemplate; |
|
19 |
-use Contao\Config; |
|
20 |
-use Contao\CoreBundle\Exception\PageNotFoundException; |
|
21 |
-use Contao\Environment; |
|
22 |
-use Contao\FrontendTemplate; |
|
23 |
-use Contao\Input; |
|
24 |
-use Contao\MemberModel; |
|
25 |
-use Contao\Model\Collection; |
|
26 |
-use Contao\Pagination; |
|
27 |
-use Contao\StringUtil; |
|
28 |
-use Contao\System; |
|
29 |
- |
|
30 |
-/** |
|
31 |
- * Class ModuleMemberList |
|
32 |
- * |
|
33 |
- * @property string $ext_order order of list items |
|
34 |
- * @property string ext_orderField order field for list items |
|
35 |
- * @property string $ext_groups considered member groups |
|
36 |
- * @property string $memberFields Fields to be displayed |
|
37 |
- * @property string $memberListTpl Frontend list template |
|
38 |
- */ |
|
39 |
-class ModuleMemberList extends ModuleMemberExtension |
|
40 |
-{ |
|
41 |
- |
|
42 |
- /** |
|
43 |
- * Template |
|
44 |
- * @var string |
|
45 |
- */ |
|
46 |
- protected $strTemplate = 'mod_memberList'; |
|
47 |
- |
|
48 |
- /** |
|
49 |
- * Template |
|
50 |
- * @var string |
|
51 |
- */ |
|
52 |
- protected $strMemberTemplate = 'memberExtension_list_default'; |
|
53 |
- |
|
54 |
- /** |
|
55 |
- * Return a wildcard in the back end |
|
56 |
- * |
|
57 |
- * @return string |
|
58 |
- */ |
|
59 |
- public function generate() |
|
60 |
- { |
|
61 |
- $request = System::getContainer()->get('request_stack')->getCurrentRequest(); |
|
62 |
- |
|
63 |
- if ($request && System::getContainer()->get('contao.routing.scope_matcher')->isBackendRequest($request)) |
|
64 |
- { |
|
65 |
- $objTemplate = new BackendTemplate('be_wildcard'); |
|
66 |
- $objTemplate->wildcard = '### ' . mb_strtoupper($GLOBALS['TL_LANG']['FMD']['memberList'][0], 'UTF-8') . ' ###'; |
|
67 |
- $objTemplate->title = $this->headline; |
|
68 |
- $objTemplate->id = $this->id; |
|
69 |
- $objTemplate->link = $this->name; |
|
70 |
- $objTemplate->href = 'contao/main.php?do=themes&table=tl_module&act=edit&id=' . $this->id; |
|
71 |
- |
|
72 |
- return $objTemplate->parse(); |
|
73 |
- } |
|
74 |
- |
|
75 |
- return parent::generate(); |
|
76 |
- } |
|
77 |
- |
|
78 |
- /** |
|
79 |
- * Generate the module |
|
80 |
- */ |
|
81 |
- protected function compile() |
|
82 |
- { |
|
83 |
- $limit = null; |
|
84 |
- $offset = 0; |
|
85 |
- |
|
86 |
- $arrGroups = StringUtil::deserialize($this->ext_groups); |
|
87 |
- |
|
88 |
- if(empty($arrGroups) || !\is_array($arrGroups)) |
|
89 |
- { |
|
90 |
- $this->Template->empty = $GLOBALS['TL_LANG']['MSC']['emptyMemberList']; |
|
91 |
- return; |
|
92 |
- } |
|
93 |
- |
|
94 |
- $objTemplate = new FrontendTemplate($this->memberListTpl ?: $this->strMemberTemplate); |
|
95 |
- |
|
96 |
- $objMembers = $this->getMembers(); |
|
97 |
- |
|
98 |
- $intTotal = 0; |
|
99 |
- |
|
100 |
- $arrMembers = []; |
|
101 |
- |
|
102 |
- if(null !== $objMembers) |
|
103 |
- { |
|
104 |
- while($objMembers->next()) |
|
105 |
- { |
|
106 |
- $objMember = $objMembers->current(); |
|
107 |
- |
|
108 |
- if(!$this->checkMemberGroups($arrGroups, $objMember)) |
|
109 |
- { |
|
110 |
- continue; |
|
111 |
- } |
|
112 |
- |
|
113 |
- $intTotal += 1; |
|
114 |
- |
|
115 |
- $arrMemberFields = StringUtil::deserialize($this->memberFields, true); |
|
116 |
- $objTemplate->setData($objMember->row()); |
|
117 |
- |
|
118 |
- $arrMembers[] = $this->parseMemberTemplate($objMember, $objTemplate, $arrMemberFields, $this->imgSize); |
|
119 |
- } |
|
120 |
- } |
|
121 |
- |
|
122 |
- $total = $intTotal - $offset; |
|
123 |
- |
|
124 |
- if ($this->numberOfItems > 0) |
|
125 |
- { |
|
126 |
- $limit = $this->numberOfItems; |
|
127 |
- } |
|
128 |
- |
|
129 |
- if ($this->perPage > 0 && (!isset($limit) || $this->numberOfItems > $this->perPage)) |
|
130 |
- { |
|
131 |
- if (isset($limit)) |
|
132 |
- { |
|
133 |
- $total = min($limit, $total); |
|
134 |
- } |
|
135 |
- |
|
136 |
- $id = 'page_n' . $this->id; |
|
137 |
- $page = Input::get($id) ?? 1; |
|
138 |
- |
|
139 |
- if ($page < 1 || $page > max(ceil($total/$this->perPage), 1)) |
|
140 |
- { |
|
141 |
- throw new PageNotFoundException('Page not found: ' . Environment::get('uri')); |
|
142 |
- } |
|
143 |
- |
|
144 |
- $limit = $this->perPage; |
|
145 |
- $offset += (max($page, 1) - 1) * $this->perPage; |
|
146 |
- $skip = 0; |
|
147 |
- |
|
148 |
- if ($offset + $limit > $total + $skip) |
|
149 |
- { |
|
150 |
- $limit = $total + $skip - $offset; |
|
151 |
- } |
|
152 |
- |
|
153 |
- $arrMembers = \array_slice($arrMembers, $offset, ((int) $limit ?: $intTotal), true); |
|
154 |
- |
|
155 |
- $objPagination = new Pagination($total, $this->perPage, Config::get('maxPaginationLinks'), $id); |
|
156 |
- $this->Template->pagination = $objPagination->generate("\n "); |
|
157 |
- } |
|
158 |
- |
|
159 |
- if(empty($arrMembers)) |
|
160 |
- { |
|
161 |
- $this->Template->empty = $GLOBALS['TL_LANG']['MSC']['emptyMemberList']; |
|
162 |
- } |
|
163 |
- |
|
164 |
- $this->Template->members = $arrMembers; |
|
165 |
- } |
|
166 |
- |
|
167 |
- /** |
|
168 |
- * Checks whether a member is in any given group |
|
169 |
- * |
|
170 |
- * @param array $arrGroups |
|
171 |
- * @param MemberModel $objMember |
|
172 |
- * @return bool |
|
173 |
- */ |
|
174 |
- private function checkMemberGroups(array $arrGroups, MemberModel $objMember): bool |
|
175 |
- { |
|
176 |
- if(empty($arrGroups)) |
|
177 |
- { |
|
178 |
- return false; |
|
179 |
- } |
|
180 |
- |
|
181 |
- $arrMemberGroups = StringUtil::deserialize($objMember->groups); |
|
182 |
- |
|
183 |
- if(!\is_array($arrMemberGroups) || !\count(array_intersect($arrGroups, $arrMemberGroups))) |
|
184 |
- { |
|
185 |
- return false; |
|
186 |
- } |
|
187 |
- |
|
188 |
- return true; |
|
189 |
- } |
|
190 |
- |
|
191 |
- /** |
|
192 |
- * Get members |
|
193 |
- * |
|
194 |
- * @return Collection|MemberModel|null |
|
195 |
- */ |
|
196 |
- private function getMembers() |
|
197 |
- { |
|
198 |
- $t = MemberModel::getTable(); |
|
199 |
- $arrOptions = ['order' => '']; |
|
200 |
- |
|
201 |
- if (!!$this->ext_orderField) |
|
202 |
- { |
|
203 |
- $arrOptions['order'] .= "$t.$this->ext_orderField "; |
|
204 |
- } |
|
205 |
- |
|
206 |
- switch ($this->ext_order) |
|
207 |
- { |
|
208 |
- case 'order_random': |
|
209 |
- $arrOptions['order'] .= "RAND()"; |
|
210 |
- break; |
|
211 |
- |
|
212 |
- case 'order_desc': |
|
213 |
- $arrOptions['order'] .= "DESC"; |
|
214 |
- break; |
|
215 |
- |
|
216 |
- case 'order_asc': |
|
217 |
- default: |
|
218 |
- break; |
|
219 |
- } |
|
220 |
- |
|
221 |
- return MemberModel::findBy(["$t.disable=''"], null, $arrOptions); |
|
222 |
- } |
|
223 |
-} |
... | ... |
@@ -39,47 +39,47 @@ use Contao\System; |
39 | 39 |
class ModuleMemberList extends ModuleMemberExtension |
40 | 40 |
{ |
41 | 41 |
|
42 |
- /** |
|
43 |
- * Template |
|
44 |
- * @var string |
|
45 |
- */ |
|
46 |
- protected $strTemplate = 'mod_memberList'; |
|
47 |
- |
|
48 |
- /** |
|
49 |
- * Template |
|
50 |
- * @var string |
|
51 |
- */ |
|
52 |
- protected $strMemberTemplate = 'memberExtension_list_default'; |
|
53 |
- |
|
54 |
- /** |
|
55 |
- * Return a wildcard in the back end |
|
56 |
- * |
|
57 |
- * @return string |
|
58 |
- */ |
|
59 |
- public function generate() |
|
60 |
- { |
|
42 |
+ /** |
|
43 |
+ * Template |
|
44 |
+ * @var string |
|
45 |
+ */ |
|
46 |
+ protected $strTemplate = 'mod_memberList'; |
|
47 |
+ |
|
48 |
+ /** |
|
49 |
+ * Template |
|
50 |
+ * @var string |
|
51 |
+ */ |
|
52 |
+ protected $strMemberTemplate = 'memberExtension_list_default'; |
|
53 |
+ |
|
54 |
+ /** |
|
55 |
+ * Return a wildcard in the back end |
|
56 |
+ * |
|
57 |
+ * @return string |
|
58 |
+ */ |
|
59 |
+ public function generate() |
|
60 |
+ { |
|
61 | 61 |
$request = System::getContainer()->get('request_stack')->getCurrentRequest(); |
62 | 62 |
|
63 | 63 |
if ($request && System::getContainer()->get('contao.routing.scope_matcher')->isBackendRequest($request)) |
64 | 64 |
{ |
65 | 65 |
$objTemplate = new BackendTemplate('be_wildcard'); |
66 |
- $objTemplate->wildcard = '### ' . mb_strtoupper($GLOBALS['TL_LANG']['FMD']['memberList'][0], 'UTF-8') . ' ###'; |
|
67 |
- $objTemplate->title = $this->headline; |
|
68 |
- $objTemplate->id = $this->id; |
|
69 |
- $objTemplate->link = $this->name; |
|
70 |
- $objTemplate->href = 'contao/main.php?do=themes&table=tl_module&act=edit&id=' . $this->id; |
|
71 |
- |
|
72 |
- return $objTemplate->parse(); |
|
73 |
- } |
|
74 |
- |
|
75 |
- return parent::generate(); |
|
76 |
- } |
|
77 |
- |
|
78 |
- /** |
|
79 |
- * Generate the module |
|
80 |
- */ |
|
81 |
- protected function compile() |
|
82 |
- { |
|
66 |
+ $objTemplate->wildcard = '### ' . mb_strtoupper($GLOBALS['TL_LANG']['FMD']['memberList'][0], 'UTF-8') . ' ###'; |
|
67 |
+ $objTemplate->title = $this->headline; |
|
68 |
+ $objTemplate->id = $this->id; |
|
69 |
+ $objTemplate->link = $this->name; |
|
70 |
+ $objTemplate->href = 'contao/main.php?do=themes&table=tl_module&act=edit&id=' . $this->id; |
|
71 |
+ |
|
72 |
+ return $objTemplate->parse(); |
|
73 |
+ } |
|
74 |
+ |
|
75 |
+ return parent::generate(); |
|
76 |
+ } |
|
77 |
+ |
|
78 |
+ /** |
|
79 |
+ * Generate the module |
|
80 |
+ */ |
|
81 |
+ protected function compile() |
|
82 |
+ { |
|
83 | 83 |
$limit = null; |
84 | 84 |
$offset = 0; |
85 | 85 |
|
... | ... |
@@ -162,7 +162,7 @@ class ModuleMemberList extends ModuleMemberExtension |
162 | 162 |
} |
163 | 163 |
|
164 | 164 |
$this->Template->members = $arrMembers; |
165 |
- } |
|
165 |
+ } |
|
166 | 166 |
|
167 | 167 |
/** |
168 | 168 |
* Checks whether a member is in any given group |
... | ... |
@@ -195,8 +195,8 @@ class ModuleMemberList extends ModuleMemberExtension |
195 | 195 |
*/ |
196 | 196 |
private function getMembers() |
197 | 197 |
{ |
198 |
- $arrOptions = []; |
|
199 | 198 |
$t = MemberModel::getTable(); |
199 |
+ $arrOptions = ['order' => '']; |
|
200 | 200 |
|
201 | 201 |
if (!!$this->ext_orderField) |
202 | 202 |
{ |
... | ... |
@@ -206,7 +206,7 @@ class ModuleMemberList extends ModuleMemberExtension |
206 | 206 |
switch ($this->ext_order) |
207 | 207 |
{ |
208 | 208 |
case 'order_random': |
209 |
- $arrOptions['order'] = "RAND()"; |
|
209 |
+ $arrOptions['order'] .= "RAND()"; |
|
210 | 210 |
break; |
211 | 211 |
|
212 | 212 |
case 'order_desc': |
... | ... |
@@ -150,7 +150,7 @@ class ModuleMemberList extends ModuleMemberExtension |
150 | 150 |
$limit = $total + $skip - $offset; |
151 | 151 |
} |
152 | 152 |
|
153 |
- $arrMembers = \array_slice($arrMembers, $offset, ($limit ?: $intTotal), true); |
|
153 |
+ $arrMembers = \array_slice($arrMembers, $offset, ((int) $limit ?: $intTotal), true); |
|
154 | 154 |
|
155 | 155 |
$objPagination = new Pagination($total, $this->perPage, Config::get('maxPaginationLinks'), $id); |
156 | 156 |
$this->Template->pagination = $objPagination->generate("\n "); |
... | ... |
@@ -150,6 +150,8 @@ class ModuleMemberList extends ModuleMemberExtension |
150 | 150 |
$limit = $total + $skip - $offset; |
151 | 151 |
} |
152 | 152 |
|
153 |
+ $arrMembers = \array_slice($arrMembers, $offset, ($limit ?: $intTotal), true); |
|
154 |
+ |
|
153 | 155 |
$objPagination = new Pagination($total, $this->perPage, Config::get('maxPaginationLinks'), $id); |
154 | 156 |
$this->Template->pagination = $objPagination->generate("\n "); |
155 | 157 |
} |
... | ... |
@@ -159,8 +161,6 @@ class ModuleMemberList extends ModuleMemberExtension |
159 | 161 |
$this->Template->empty = $GLOBALS['TL_LANG']['MSC']['emptyMemberList']; |
160 | 162 |
} |
161 | 163 |
|
162 |
- $arrMembers = \array_slice($arrMembers, $offset, ($limit ?: 0), true); |
|
163 |
- |
|
164 | 164 |
$this->Template->members = $arrMembers; |
165 | 165 |
} |
166 | 166 |
|
... | ... |
@@ -16,9 +16,14 @@ declare(strict_types=1); |
16 | 16 |
namespace Oveleon\ContaoMemberExtensionBundle; |
17 | 17 |
|
18 | 18 |
use Contao\BackendTemplate; |
19 |
+use Contao\Config; |
|
20 |
+use Contao\CoreBundle\Exception\PageNotFoundException; |
|
21 |
+use Contao\Environment; |
|
19 | 22 |
use Contao\FrontendTemplate; |
23 |
+use Contao\Input; |
|
20 | 24 |
use Contao\MemberModel; |
21 | 25 |
use Contao\Model\Collection; |
26 |
+use Contao\Pagination; |
|
22 | 27 |
use Contao\StringUtil; |
23 | 28 |
use Contao\System; |
24 | 29 |
|
... | ... |
@@ -75,6 +80,9 @@ class ModuleMemberList extends ModuleMemberExtension |
75 | 80 |
*/ |
76 | 81 |
protected function compile() |
77 | 82 |
{ |
83 |
+ $limit = null; |
|
84 |
+ $offset = 0; |
|
85 |
+ |
|
78 | 86 |
$arrGroups = StringUtil::deserialize($this->ext_groups); |
79 | 87 |
|
80 | 88 |
if(empty($arrGroups) || !\is_array($arrGroups)) |
... | ... |
@@ -86,6 +94,9 @@ class ModuleMemberList extends ModuleMemberExtension |
86 | 94 |
$objTemplate = new FrontendTemplate($this->memberListTpl ?: $this->strMemberTemplate); |
87 | 95 |
|
88 | 96 |
$objMembers = $this->getMembers(); |
97 |
+ |
|
98 |
+ $intTotal = 0; |
|
99 |
+ |
|
89 | 100 |
$arrMembers = []; |
90 | 101 |
|
91 | 102 |
if(null !== $objMembers) |
... | ... |
@@ -99,6 +110,8 @@ class ModuleMemberList extends ModuleMemberExtension |
99 | 110 |
continue; |
100 | 111 |
} |
101 | 112 |
|
113 |
+ $intTotal += 1; |
|
114 |
+ |
|
102 | 115 |
$arrMemberFields = StringUtil::deserialize($this->memberFields, true); |
103 | 116 |
$objTemplate->setData($objMember->row()); |
104 | 117 |
|
... | ... |
@@ -106,11 +119,48 @@ class ModuleMemberList extends ModuleMemberExtension |
106 | 119 |
} |
107 | 120 |
} |
108 | 121 |
|
122 |
+ $total = $intTotal - $offset; |
|
123 |
+ |
|
124 |
+ if ($this->numberOfItems > 0) |
|
125 |
+ { |
|
126 |
+ $limit = $this->numberOfItems; |
|
127 |
+ } |
|
128 |
+ |
|
129 |
+ if ($this->perPage > 0 && (!isset($limit) || $this->numberOfItems > $this->perPage)) |
|
130 |
+ { |
|
131 |
+ if (isset($limit)) |
|
132 |
+ { |
|
133 |
+ $total = min($limit, $total); |
|
134 |
+ } |
|
135 |
+ |
|
136 |
+ $id = 'page_n' . $this->id; |
|
137 |
+ $page = Input::get($id) ?? 1; |
|
138 |
+ |
|
139 |
+ if ($page < 1 || $page > max(ceil($total/$this->perPage), 1)) |
|
140 |
+ { |
|
141 |
+ throw new PageNotFoundException('Page not found: ' . Environment::get('uri')); |
|
142 |
+ } |
|
143 |
+ |
|
144 |
+ $limit = $this->perPage; |
|
145 |
+ $offset += (max($page, 1) - 1) * $this->perPage; |
|
146 |
+ $skip = 0; |
|
147 |
+ |
|
148 |
+ if ($offset + $limit > $total + $skip) |
|
149 |
+ { |
|
150 |
+ $limit = $total + $skip - $offset; |
|
151 |
+ } |
|
152 |
+ |
|
153 |
+ $objPagination = new Pagination($total, $this->perPage, Config::get('maxPaginationLinks'), $id); |
|
154 |
+ $this->Template->pagination = $objPagination->generate("\n "); |
|
155 |
+ } |
|
156 |
+ |
|
109 | 157 |
if(empty($arrMembers)) |
110 | 158 |
{ |
111 | 159 |
$this->Template->empty = $GLOBALS['TL_LANG']['MSC']['emptyMemberList']; |
112 | 160 |
} |
113 | 161 |
|
162 |
+ $arrMembers = \array_slice($arrMembers, $offset, ($limit ?: 0), true); |
|
163 |
+ |
|
114 | 164 |
$this->Template->members = $arrMembers; |
115 | 165 |
} |
116 | 166 |
|
... | ... |
@@ -83,30 +83,30 @@ class ModuleMemberList extends ModuleMemberExtension |
83 | 83 |
return; |
84 | 84 |
} |
85 | 85 |
|
86 |
+ $objTemplate = new FrontendTemplate($this->memberListTpl ?: $this->strMemberTemplate); |
|
87 |
+ |
|
86 | 88 |
$objMembers = $this->getMembers(); |
87 | 89 |
$arrMembers = []; |
88 | 90 |
|
89 |
- if($objMembers->count()) |
|
91 |
+ if(null !== $objMembers) |
|
90 | 92 |
{ |
91 | 93 |
while($objMembers->next()) |
92 | 94 |
{ |
93 |
- $memberGroups = StringUtil::deserialize($objMembers->groups); |
|
95 |
+ $objMember = $objMembers->current(); |
|
94 | 96 |
|
95 |
- if(!\count(array_intersect($arrGroups, $memberGroups))) |
|
97 |
+ if(!$this->checkMemberGroups($arrGroups, $objMember)) |
|
96 | 98 |
{ |
97 | 99 |
continue; |
98 | 100 |
} |
99 | 101 |
|
100 | 102 |
$arrMemberFields = StringUtil::deserialize($this->memberFields, true); |
103 |
+ $objTemplate->setData($objMember->row()); |
|
101 | 104 |
|
102 |
- $objTemplate = new FrontendTemplate($this->memberListTpl ?: $this->strMemberTemplate); |
|
103 |
- $objTemplate->setData($objMembers->current()->row()); |
|
104 |
- |
|
105 |
- $arrMembers[] = $this->parseMemberTemplate($objMembers->current(), $objTemplate, $arrMemberFields, $this->imgSize); |
|
105 |
+ $arrMembers[] = $this->parseMemberTemplate($objMember, $objTemplate, $arrMemberFields, $this->imgSize); |
|
106 | 106 |
} |
107 | 107 |
} |
108 | 108 |
|
109 |
- if(null === $arrMembers) |
|
109 |
+ if(empty($arrMembers)) |
|
110 | 110 |
{ |
111 | 111 |
$this->Template->empty = $GLOBALS['TL_LANG']['MSC']['emptyMemberList']; |
112 | 112 |
} |
... | ... |
@@ -115,11 +115,35 @@ class ModuleMemberList extends ModuleMemberExtension |
115 | 115 |
} |
116 | 116 |
|
117 | 117 |
/** |
118 |
+ * Checks whether a member is in any given group |
|
119 |
+ * |
|
120 |
+ * @param array $arrGroups |
|
121 |
+ * @param MemberModel $objMember |
|
122 |
+ * @return bool |
|
123 |
+ */ |
|
124 |
+ private function checkMemberGroups(array $arrGroups, MemberModel $objMember): bool |
|
125 |
+ { |
|
126 |
+ if(empty($arrGroups)) |
|
127 |
+ { |
|
128 |
+ return false; |
|
129 |
+ } |
|
130 |
+ |
|
131 |
+ $arrMemberGroups = StringUtil::deserialize($objMember->groups); |
|
132 |
+ |
|
133 |
+ if(!\is_array($arrMemberGroups) || !\count(array_intersect($arrGroups, $arrMemberGroups))) |
|
134 |
+ { |
|
135 |
+ return false; |
|
136 |
+ } |
|
137 |
+ |
|
138 |
+ return true; |
|
139 |
+ } |
|
140 |
+ |
|
141 |
+ /** |
|
118 | 142 |
* Get members |
119 | 143 |
* |
120 | 144 |
* @return Collection|MemberModel|null |
121 | 145 |
*/ |
122 |
- protected function getMembers() |
|
146 |
+ private function getMembers() |
|
123 | 147 |
{ |
124 | 148 |
$arrOptions = []; |
125 | 149 |
$t = MemberModel::getTable(); |
... | ... |
@@ -25,6 +25,8 @@ use Contao\System; |
25 | 25 |
/** |
26 | 26 |
* Class ModuleMemberList |
27 | 27 |
* |
28 |
+ * @property string $ext_order order of list items |
|
29 |
+ * @property string ext_orderField order field for list items |
|
28 | 30 |
* @property string $ext_groups considered member groups |
29 | 31 |
* @property string $memberFields Fields to be displayed |
30 | 32 |
* @property string $memberListTpl Frontend list template |
... | ... |
@@ -122,6 +124,26 @@ class ModuleMemberList extends ModuleMemberExtension |
122 | 124 |
$arrOptions = []; |
123 | 125 |
$t = MemberModel::getTable(); |
124 | 126 |
|
127 |
+ if (!!$this->ext_orderField) |
|
128 |
+ { |
|
129 |
+ $arrOptions['order'] .= "$t.$this->ext_orderField "; |
|
130 |
+ } |
|
131 |
+ |
|
132 |
+ switch ($this->ext_order) |
|
133 |
+ { |
|
134 |
+ case 'order_random': |
|
135 |
+ $arrOptions['order'] = "RAND()"; |
|
136 |
+ break; |
|
137 |
+ |
|
138 |
+ case 'order_desc': |
|
139 |
+ $arrOptions['order'] .= "DESC"; |
|
140 |
+ break; |
|
141 |
+ |
|
142 |
+ case 'order_asc': |
|
143 |
+ default: |
|
144 |
+ break; |
|
145 |
+ } |
|
146 |
+ |
|
125 | 147 |
return MemberModel::findBy(["$t.disable=''"], null, $arrOptions); |
126 | 148 |
} |
127 | 149 |
} |
... | ... |
@@ -18,6 +18,7 @@ namespace Oveleon\ContaoMemberExtensionBundle; |
18 | 18 |
use Contao\BackendTemplate; |
19 | 19 |
use Contao\FrontendTemplate; |
20 | 20 |
use Contao\MemberModel; |
21 |
+use Contao\Model\Collection; |
|
21 | 22 |
use Contao\StringUtil; |
22 | 23 |
use Contao\System; |
23 | 24 |
|
... | ... |
@@ -80,19 +81,13 @@ class ModuleMemberList extends ModuleMemberExtension |
80 | 81 |
return; |
81 | 82 |
} |
82 | 83 |
|
83 |
- $objMembers = MemberModel::findAll(); |
|
84 |
+ $objMembers = $this->getMembers(); |
|
84 | 85 |
$arrMembers = []; |
85 | 86 |
|
86 | 87 |
if($objMembers->count()) |
87 | 88 |
{ |
88 | 89 |
while($objMembers->next()) |
89 | 90 |
{ |
90 |
- // Skip disabled users instantly |
|
91 |
- if($objMembers->disable) |
|
92 |
- { |
|
93 |
- continue; |
|
94 |
- } |
|
95 |
- |
|
96 | 91 |
$memberGroups = StringUtil::deserialize($objMembers->groups); |
97 | 92 |
|
98 | 93 |
if(!\count(array_intersect($arrGroups, $memberGroups))) |
... | ... |
@@ -116,4 +111,17 @@ class ModuleMemberList extends ModuleMemberExtension |
116 | 111 |
|
117 | 112 |
$this->Template->members = $arrMembers; |
118 | 113 |
} |
114 |
+ |
|
115 |
+ /** |
|
116 |
+ * Get members |
|
117 |
+ * |
|
118 |
+ * @return Collection|MemberModel|null |
|
119 |
+ */ |
|
120 |
+ protected function getMembers() |
|
121 |
+ { |
|
122 |
+ $arrOptions = []; |
|
123 |
+ $t = MemberModel::getTable(); |
|
124 |
+ |
|
125 |
+ return MemberModel::findBy(["$t.disable=''"], null, $arrOptions); |
|
126 |
+ } |
|
119 | 127 |
} |
... | ... |
@@ -24,7 +24,9 @@ use Contao\System; |
24 | 24 |
/** |
25 | 25 |
* Class ModuleMemberList |
26 | 26 |
* |
27 |
- * @author Daniele Sciannimanica <https://github.com/doishub> |
|
27 |
+ * @property string $ext_groups considered member groups |
|
28 |
+ * @property string $memberFields Fields to be displayed |
|
29 |
+ * @property string $memberListTpl Frontend list template |
|
28 | 30 |
*/ |
29 | 31 |
class ModuleMemberList extends ModuleMemberExtension |
30 | 32 |
{ |
... | ... |
@@ -70,17 +72,30 @@ class ModuleMemberList extends ModuleMemberExtension |
70 | 72 |
*/ |
71 | 73 |
protected function compile() |
72 | 74 |
{ |
73 |
- $objGroups = MemberModel::findAll(); |
|
74 |
- $arrGroups = StringUtil::deserialize($this->groups); |
|
75 |
- $arrMembers = null; |
|
75 |
+ $arrGroups = StringUtil::deserialize($this->ext_groups); |
|
76 | 76 |
|
77 |
- if($objGroups->count()) |
|
77 |
+ if(empty($arrGroups) || !\is_array($arrGroups)) |
|
78 | 78 |
{ |
79 |
- while($objGroups->next()) |
|
79 |
+ $this->Template->empty = $GLOBALS['TL_LANG']['MSC']['emptyMemberList']; |
|
80 |
+ return; |
|
81 |
+ } |
|
82 |
+ |
|
83 |
+ $objMembers = MemberModel::findAll(); |
|
84 |
+ $arrMembers = []; |
|
85 |
+ |
|
86 |
+ if($objMembers->count()) |
|
87 |
+ { |
|
88 |
+ while($objMembers->next()) |
|
80 | 89 |
{ |
81 |
- $memberGroups = StringUtil::deserialize($objGroups->groups); |
|
90 |
+ // Skip disabled users instantly |
|
91 |
+ if($objMembers->disable) |
|
92 |
+ { |
|
93 |
+ continue; |
|
94 |
+ } |
|
95 |
+ |
|
96 |
+ $memberGroups = StringUtil::deserialize($objMembers->groups); |
|
82 | 97 |
|
83 |
- if($objGroups->disable || empty($arrGroups) || !\is_array($arrGroups) || !\count(array_intersect($arrGroups, $memberGroups))) |
|
98 |
+ if(!\count(array_intersect($arrGroups, $memberGroups))) |
|
84 | 99 |
{ |
85 | 100 |
continue; |
86 | 101 |
} |
... | ... |
@@ -88,9 +103,9 @@ class ModuleMemberList extends ModuleMemberExtension |
88 | 103 |
$arrMemberFields = StringUtil::deserialize($this->memberFields, true); |
89 | 104 |
|
90 | 105 |
$objTemplate = new FrontendTemplate($this->memberListTpl ?: $this->strMemberTemplate); |
91 |
- $objTemplate->setData($objGroups->current()->row()); |
|
106 |
+ $objTemplate->setData($objMembers->current()->row()); |
|
92 | 107 |
|
93 |
- $arrMembers[] = $this->parseMemberTemplate($objGroups->current(), $objTemplate, $arrMemberFields, $this->imgSize); |
|
108 |
+ $arrMembers[] = $this->parseMemberTemplate($objMembers->current(), $objTemplate, $arrMemberFields, $this->imgSize); |
|
94 | 109 |
} |
95 | 110 |
} |
96 | 111 |
|
... | ... |
@@ -39,7 +39,7 @@ class ModuleMemberList extends ModuleMemberExtension |
39 | 39 |
* Template |
40 | 40 |
* @var string |
41 | 41 |
*/ |
42 |
- protected $strMemberTemplate = 'member_list_default'; |
|
42 |
+ protected $strMemberTemplate = 'memberExtension_list_default'; |
|
43 | 43 |
|
44 | 44 |
/** |
45 | 45 |
* Return a wildcard in the back end |
... | ... |
@@ -1,9 +1,16 @@ |
1 | 1 |
<?php |
2 | 2 |
|
3 |
+declare(strict_types=1); |
|
4 |
+ |
|
3 | 5 |
/* |
4 | 6 |
* This file is part of Oveleon ContaoMemberExtension Bundle. |
5 | 7 |
* |
6 |
- * (c) https://www.oveleon.de/ |
|
8 |
+ * @package contao-member-extension-bundle |
|
9 |
+ * @license MIT |
|
10 |
+ * @author Daniele Sciannimanica <https://github.com/doishub> |
|
11 |
+ * @author Fabian Ekert <https://github.com/eki89> |
|
12 |
+ * @author Sebastian Zoglowek <https://github.com/zoglo> |
|
13 |
+ * @copyright Oveleon <https://www.oveleon.de/> |
|
7 | 14 |
*/ |
8 | 15 |
|
9 | 16 |
namespace Oveleon\ContaoMemberExtensionBundle; |
... | ... |
@@ -12,7 +19,7 @@ use Contao\BackendTemplate; |
12 | 19 |
use Contao\FrontendTemplate; |
13 | 20 |
use Contao\MemberModel; |
14 | 21 |
use Contao\StringUtil; |
15 |
-use Patchwork\Utf8; |
|
22 |
+use Contao\System; |
|
16 | 23 |
|
17 | 24 |
/** |
18 | 25 |
* Class ModuleMemberList |
... | ... |
@@ -41,12 +48,12 @@ class ModuleMemberList extends ModuleMemberExtension |
41 | 48 |
*/ |
42 | 49 |
public function generate() |
43 | 50 |
{ |
44 |
- if (TL_MODE == 'BE') |
|
45 |
- { |
|
46 |
- /** @var BackendTemplate|object $objTemplate */ |
|
47 |
- $objTemplate = new BackendTemplate('be_wildcard'); |
|
51 |
+ $request = System::getContainer()->get('request_stack')->getCurrentRequest(); |
|
48 | 52 |
|
49 |
- $objTemplate->wildcard = '### ' . Utf8::strtoupper($GLOBALS['TL_LANG']['FMD']['memberList'][0]) . ' ###'; |
|
53 |
+ if ($request && System::getContainer()->get('contao.routing.scope_matcher')->isBackendRequest($request)) |
|
54 |
+ { |
|
55 |
+ $objTemplate = new BackendTemplate('be_wildcard'); |
|
56 |
+ $objTemplate->wildcard = '### ' . mb_strtoupper($GLOBALS['TL_LANG']['FMD']['memberList'][0], 'UTF-8') . ' ###'; |
|
50 | 57 |
$objTemplate->title = $this->headline; |
51 | 58 |
$objTemplate->id = $this->id; |
52 | 59 |
$objTemplate->link = $this->name; |
... | ... |
@@ -63,14 +63,17 @@ class ModuleMemberList extends ModuleMemberExtension |
63 | 63 |
*/ |
64 | 64 |
protected function compile() |
65 | 65 |
{ |
66 |
- $objGroups = MemberModel::findByGroups($this->groups); |
|
66 |
+ $objGroups = MemberModel::findAll(); |
|
67 |
+ $arrGroups = StringUtil::deserialize($this->groups); |
|
67 | 68 |
$arrMembers = null; |
68 | 69 |
|
69 | 70 |
if($objGroups->count()) |
70 | 71 |
{ |
71 | 72 |
while($objGroups->next()) |
72 | 73 |
{ |
73 |
- if($objGroups->disable) |
|
74 |
+ $memberGroups = StringUtil::deserialize($objGroups->groups); |
|
75 |
+ |
|
76 |
+ if($objGroups->disable || empty($arrGroups) || !\is_array($arrGroups) || !\count(array_intersect($arrGroups, $memberGroups))) |
|
74 | 77 |
{ |
75 | 78 |
continue; |
76 | 79 |
} |
... | ... |
@@ -66,19 +66,22 @@ class ModuleMemberList extends ModuleMemberExtension |
66 | 66 |
$objGroups = MemberModel::findByGroups($this->groups); |
67 | 67 |
$arrMembers = null; |
68 | 68 |
|
69 |
- while($objGroups->next()) |
|
69 |
+ if($objGroups->count()) |
|
70 | 70 |
{ |
71 |
- if($objGroups->disable) |
|
71 |
+ while($objGroups->next()) |
|
72 | 72 |
{ |
73 |
- continue; |
|
74 |
- } |
|
73 |
+ if($objGroups->disable) |
|
74 |
+ { |
|
75 |
+ continue; |
|
76 |
+ } |
|
75 | 77 |
|
76 |
- $arrMemberFields = StringUtil::deserialize($this->memberFields, true); |
|
78 |
+ $arrMemberFields = StringUtil::deserialize($this->memberFields, true); |
|
77 | 79 |
|
78 |
- $objTemplate = new FrontendTemplate($this->memberListTpl ?: $this->strMemberTemplate); |
|
79 |
- $objTemplate->setData($objGroups->current()->row()); |
|
80 |
+ $objTemplate = new FrontendTemplate($this->memberListTpl ?: $this->strMemberTemplate); |
|
81 |
+ $objTemplate->setData($objGroups->current()->row()); |
|
80 | 82 |
|
81 |
- $arrMembers[] = $this->parseMemberTemplate($objGroups->current(), $objTemplate, $arrMemberFields, $this->imgSize); |
|
83 |
+ $arrMembers[] = $this->parseMemberTemplate($objGroups->current(), $objTemplate, $arrMemberFields, $this->imgSize); |
|
84 |
+ } |
|
82 | 85 |
} |
83 | 86 |
|
84 | 87 |
if(null === $arrMembers) |
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,91 @@ |
1 |
+<?php |
|
2 |
+ |
|
3 |
+/* |
|
4 |
+ * This file is part of Oveleon ContaoMemberExtension Bundle. |
|
5 |
+ * |
|
6 |
+ * (c) https://www.oveleon.de/ |
|
7 |
+ */ |
|
8 |
+ |
|
9 |
+namespace Oveleon\ContaoMemberExtensionBundle; |
|
10 |
+ |
|
11 |
+use Contao\BackendTemplate; |
|
12 |
+use Contao\FrontendTemplate; |
|
13 |
+use Contao\MemberModel; |
|
14 |
+use Contao\StringUtil; |
|
15 |
+use Patchwork\Utf8; |
|
16 |
+ |
|
17 |
+/** |
|
18 |
+ * Class ModuleMemberList |
|
19 |
+ * |
|
20 |
+ * @author Daniele Sciannimanica <https://github.com/doishub> |
|
21 |
+ */ |
|
22 |
+class ModuleMemberList extends ModuleMemberExtension |
|
23 |
+{ |
|
24 |
+ |
|
25 |
+ /** |
|
26 |
+ * Template |
|
27 |
+ * @var string |
|
28 |
+ */ |
|
29 |
+ protected $strTemplate = 'mod_memberList'; |
|
30 |
+ |
|
31 |
+ /** |
|
32 |
+ * Template |
|
33 |
+ * @var string |
|
34 |
+ */ |
|
35 |
+ protected $strMemberTemplate = 'member_list_default'; |
|
36 |
+ |
|
37 |
+ /** |
|
38 |
+ * Return a wildcard in the back end |
|
39 |
+ * |
|
40 |
+ * @return string |
|
41 |
+ */ |
|
42 |
+ public function generate() |
|
43 |
+ { |
|
44 |
+ if (TL_MODE == 'BE') |
|
45 |
+ { |
|
46 |
+ /** @var BackendTemplate|object $objTemplate */ |
|
47 |
+ $objTemplate = new BackendTemplate('be_wildcard'); |
|
48 |
+ |
|
49 |
+ $objTemplate->wildcard = '### ' . Utf8::strtoupper($GLOBALS['TL_LANG']['FMD']['memberList'][0]) . ' ###'; |
|
50 |
+ $objTemplate->title = $this->headline; |
|
51 |
+ $objTemplate->id = $this->id; |
|
52 |
+ $objTemplate->link = $this->name; |
|
53 |
+ $objTemplate->href = 'contao/main.php?do=themes&table=tl_module&act=edit&id=' . $this->id; |
|
54 |
+ |
|
55 |
+ return $objTemplate->parse(); |
|
56 |
+ } |
|
57 |
+ |
|
58 |
+ return parent::generate(); |
|
59 |
+ } |
|
60 |
+ |
|
61 |
+ /** |
|
62 |
+ * Generate the module |
|
63 |
+ */ |
|
64 |
+ protected function compile() |
|
65 |
+ { |
|
66 |
+ $objGroups = MemberModel::findByGroups($this->groups); |
|
67 |
+ $arrMembers = null; |
|
68 |
+ |
|
69 |
+ while($objGroups->next()) |
|
70 |
+ { |
|
71 |
+ if($objGroups->disable) |
|
72 |
+ { |
|
73 |
+ continue; |
|
74 |
+ } |
|
75 |
+ |
|
76 |
+ $arrMemberFields = StringUtil::deserialize($this->memberFields, true); |
|
77 |
+ |
|
78 |
+ $objTemplate = new FrontendTemplate($this->memberListTpl ?: $this->strMemberTemplate); |
|
79 |
+ $objTemplate->setData($objGroups->current()->row()); |
|
80 |
+ |
|
81 |
+ $arrMembers[] = $this->parseMemberTemplate($objGroups->current(), $objTemplate, $arrMemberFields, $this->imgSize); |
|
82 |
+ } |
|
83 |
+ |
|
84 |
+ if(null === $arrMembers) |
|
85 |
+ { |
|
86 |
+ $this->Template->empty = $GLOBALS['TL_LANG']['MSC']['emptyMemberList']; |
|
87 |
+ } |
|
88 |
+ |
|
89 |
+ $this->Template->members = $arrMembers; |
|
90 |
+ } |
|
91 |
+} |