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