Skip to content

Commit

Permalink
New release 4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
franck-paul committed Oct 27, 2023
1 parent 1e654f4 commit 4943e10
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion _define.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
'Ordering category entries',
'Set category entries order',
'Franck Paul',
'4.0',
'4.1',
[
'requires' => [['core', '2.28']],
'permissions' => '',
Expand Down
4 changes: 3 additions & 1 deletion src/FrontendBehaviors.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class FrontendBehaviors
*/
public static function coreBlogBeforeGetPosts(ArrayObject $params): string
{
if (App::url()->type == 'category') {
if (App::url()->getType() == 'category') {
$settings = My::settings();
if ($settings->active) {
$cat_id = App::frontend()->context()->categories->cat_id;
Expand All @@ -43,6 +43,7 @@ public static function coreBlogBeforeGetPosts(ArrayObject $params): string

break;
}

switch ($orders[$cat_id]) {
case 'asc':
case 'title-asc':
Expand All @@ -56,6 +57,7 @@ public static function coreBlogBeforeGetPosts(ArrayObject $params): string
break;
}
}

$numbers = $settings->numbers;
if (is_array($numbers) && array_key_exists($cat_id, $numbers) && $numbers[$cat_id] != '') {
// Specific number of entry per page set for the category
Expand Down
17 changes: 9 additions & 8 deletions src/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,28 @@ public static function process(): bool
// Convert oldschool settings
Upgrade::settings2array('catorder', 'orders');
}
if (version_compare((string) $old_version, '2.0', '<')) {
// Rename settings namespace
if (App::blog()->settings()->exists('catorder')) {
App::blog()->settings()->delWorkspace(My::id());
App::blog()->settings()->renWorkspace('catorder', My::id());
}

// Rename settings namespace
if (version_compare((string) $old_version, '2.0', '<') && App::blog()->settings()->exists('catorder')) {
App::blog()->settings()->delWorkspace(My::id());
App::blog()->settings()->renWorkspace('catorder', My::id());
}

// Chech if settings exist, create them if not
$settings = My::settings();
if (!$settings->getGlobal('active')) {
$settings->put('active', false, App::blogWorkspace()::NS_BOOL, 'Active', false, true);
}

if (!$settings->getGlobal('orders')) {
$settings->put('orders', [], App::blogWorkspace()::NS_ARRAY, 'Categories order', false, true);
}

if (!$settings->getGlobal('numbers')) {
$settings->put('numbers', [], App::blogWorkspace()::NS_ARRAY, 'Categories nb of entries per page', false, true);
}
} catch (Exception $e) {
App::error()->add($e->getMessage());
} catch (Exception $exception) {
App::error()->add($exception->getMessage());
}

return true;
Expand Down
9 changes: 6 additions & 3 deletions src/Manage.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,19 @@ public static function process(): bool
return false;
}

if (!empty($_POST)) {
if ($_POST !== []) {
try {
$co_active = (bool) $_POST['co_active'];
$co_orders = [];
if (!empty($_POST['co_order'])) {
for ($i = 0; $i < (is_countable($_POST['co_order']) ? count($_POST['co_order']) : 0); $i++) {
for ($i = 0; $i < (is_countable($_POST['co_order']) ? count($_POST['co_order']) : 0); ++$i) {
$co_orders[$_POST['co_catid'][$i]] = $_POST['co_order'][$i];
}
}

$co_numbers = [];
if (!empty($_POST['co_number'])) {
for ($i = 0; $i < (is_countable($_POST['co_number']) ? count($_POST['co_number']) : 0); $i++) {
for ($i = 0; $i < (is_countable($_POST['co_number']) ? count($_POST['co_number']) : 0); ++$i) {
$co_numbers[$_POST['co_catid'][$i]] = $_POST['co_number'][$i];
}
}
Expand Down Expand Up @@ -99,6 +100,7 @@ public static function render(): void
if (!is_array($co_orders)) {
$co_orders = [];
}

if (!is_array($co_numbers)) {
$co_numbers = [];
}
Expand Down Expand Up @@ -139,6 +141,7 @@ public static function render(): void
]),
]);
}

$block = (new Para(null, 'table'))
->items([
(new Para(null, 'thead'))->items([
Expand Down

0 comments on commit 4943e10

Please sign in to comment.