Refactored code, wee faster sort

Co-Authored-By: wunderfeyd <7998283+wunderfeyd@users.noreply.github.com>
This commit is contained in:
markseu 2024-04-23 22:09:57 +02:00
parent 9ef0ce3fb5
commit dedd5179b1
3 changed files with 13 additions and 13 deletions

View file

@ -148,14 +148,14 @@ system/themes/copenhagen.css: copenhagen.css, create, update, careful
system/themes/copenhagen.png: copenhagen.png, create system/themes/copenhagen.png: copenhagen.png, create
Extension: Core Extension: Core
Version: 0.9.5 Version: 0.9.6
Description: Core functionality of your website. Description: Core functionality of your website.
Developer: Anna Svensson Developer: Anna Svensson
Tag: feature Tag: feature
DownloadUrl: https://github.com/annaesvensson/yellow-core/archive/refs/heads/main.zip DownloadUrl: https://github.com/annaesvensson/yellow-core/archive/refs/heads/main.zip
DocumentationUrl: https://github.com/annaesvensson/yellow-core DocumentationUrl: https://github.com/annaesvensson/yellow-core
DocumentationLanguage: en, de, sv DocumentationLanguage: en, de, sv
Published: 2024-04-23 10:16:44 Published: 2024-04-23 21:35:24
Status: available Status: available
system/workers/core.php: core.php, create, update system/workers/core.php: core.php, create, update
system/extensions/core.php: coreupdate.txt, update system/extensions/core.php: coreupdate.txt, update
@ -602,14 +602,14 @@ Status: available
system/workers/private.php: private.php, create, update system/workers/private.php: private.php, create, update
Extension: Publish Extension: Publish
Version: 0.9.3 Version: 0.9.4
Description: Make and publish extensions. Description: Make and publish extensions.
Developer: Anna Svensson Developer: Anna Svensson
Tag: feature Tag: feature
DownloadUrl: https://github.com/annaesvensson/yellow-publish/archive/refs/heads/main.zip DownloadUrl: https://github.com/annaesvensson/yellow-publish/archive/refs/heads/main.zip
DocumentationUrl: https://github.com/annaesvensson/yellow-publish DocumentationUrl: https://github.com/annaesvensson/yellow-publish
DocumentationLanguage: en, de, sv DocumentationLanguage: en, de, sv
Published: 2024-04-10 10:20:07 Published: 2024-04-23 22:01:41
Status: available Status: available
system/workers/publish.php: publish.php, create, update system/workers/publish.php: publish.php, create, update

View file

@ -1,14 +1,14 @@
# Datenstrom Yellow extension settings # Datenstrom Yellow extension settings
Extension: Core Extension: Core
Version: 0.9.5 Version: 0.9.6
Description: Core functionality of your website. Description: Core functionality of your website.
Developer: Anna Svensson Developer: Anna Svensson
Tag: feature Tag: feature
DownloadUrl: https://github.com/annaesvensson/yellow-core/archive/refs/heads/main.zip DownloadUrl: https://github.com/annaesvensson/yellow-core/archive/refs/heads/main.zip
DocumentationUrl: https://github.com/annaesvensson/yellow-core DocumentationUrl: https://github.com/annaesvensson/yellow-core
DocumentationLanguage: en, de, sv DocumentationLanguage: en, de, sv
Published: 2024-04-23 10:16:44 Published: 2024-04-23 21:35:24
Status: available Status: available
system/workers/core.php: core.php, create, update system/workers/core.php: core.php, create, update
system/extensions/core.php: coreupdate.txt, update system/extensions/core.php: coreupdate.txt, update

View file

@ -2,7 +2,7 @@
// Core extension, https://github.com/annaesvensson/yellow-core // Core extension, https://github.com/annaesvensson/yellow-core
class YellowCore { class YellowCore {
const VERSION = "0.9.5"; const VERSION = "0.9.6";
const RELEASE = "0.9"; const RELEASE = "0.9";
public $content; // content files public $content; // content files
public $media; // media files public $media; // media files
@ -3656,14 +3656,14 @@ class YellowPageCollection extends ArrayObject {
public function sort($key, $ascendingOrder = true): YellowPageCollection { public function sort($key, $ascendingOrder = true): YellowPageCollection {
$array = $this->getArrayCopy(); $array = $this->getArrayCopy();
$sortIndex = 0; $sortIndex = 0;
$sortKeys = array();
foreach ($array as $page) { foreach ($array as $page) {
$page->set("sortIndex", ++$sortIndex); $sortKeys[$page->location] = $page->get($key)." ".++$sortIndex;
} }
$callback = function ($a, $b) use ($key, $ascendingOrder) { $callback = function ($a, $b) use ($sortKeys, $ascendingOrder) {
$result = $ascendingOrder ? return $ascendingOrder ?
strnatcasecmp($a->get($key), $b->get($key)) : strnatcasecmp($sortKeys[$a->location], $sortKeys[$b->location]) :
strnatcasecmp($b->get($key), $a->get($key)); strnatcasecmp($sortKeys[$b->location], $sortKeys[$a->location]);
return $result==0 ? $a->get("sortIndex") - $b->get("sortIndex") : $result;
}; };
usort($array, $callback); usort($array, $callback);
$this->exchangeArray($array); $this->exchangeArray($array);