Skip to content

Commit 2379395

Browse files
authored
fead: add date field to moduleinfo.json (#149)
* feat: add date to module info * feat: sort modules by date in list view
1 parent 4c71ed4 commit 2379395

7 files changed

Lines changed: 61 additions & 1 deletion

File tree

src/Classes/ModuleConverter.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public static function convertToArray(Module $module): array
2525
'sourceDir' => $module->getSourceDir(),
2626
'sourceMmlcDir' => $module->getSourceMmlcDir(),
2727
'version' => $module->getVersion(),
28+
'date' => $module->getDate(),
2829
'shortDescription' => $module->getShortDescription(),
2930
'description' => $module->getDescription(),
3031
'developer' => $module->getDeveloper(),

src/Classes/ModuleFactory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public static function createFromArray(array $array): Module
7979
$module->setSourceDir($array['sourceDir'] ?? self::DIR_MODULE_SRC);
8080
$module->setSourceMmlcDir($array['sourceMmlcDir'] ?? self::DIR_MODULE_SRC_MMLC);
8181
$module->setVersion($array['version'] ?? 'auto');
82+
$module->setDate($array['date'] ?? 'unknown');
8283
$module->setShortDescription($array['shortDescription'] ?? '');
8384
$module->setDescription($array['description'] ?? '');
8485
$module->setDeveloper($array['developer'] ?? '');

src/Classes/ModuleInfo.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ class ModuleInfo
6666
*/
6767
protected $version;
6868

69+
/**
70+
* Beispiel: 2023-06-20 19:42:32
71+
*
72+
* @var string
73+
*/
74+
protected $date;
75+
6976
/**
7077
* Eine Kurzbeschreibung des Moduls in menschen lesbarer Form.
7178
*
@@ -247,6 +254,16 @@ public function setVersion(string $value): void
247254
$this->version = $value;
248255
}
249256

257+
public function getDate(): string
258+
{
259+
return $this->date;
260+
}
261+
262+
public function setDate(string $value): void
263+
{
264+
$this->date = $value;
265+
}
266+
250267
public function getShortDescription(): string
251268
{
252269
return $this->shortDescription;

src/Classes/ModuleSorter.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,31 @@ public static function sortByVersion(array $modules): array
8282
});
8383
return $modules;
8484
}
85+
86+
/**
87+
* @param Module[] $modules
88+
* @return Module[] Return a array of modules sorted by version.
89+
*/
90+
public static function sortByDate(array $modules): array
91+
{
92+
usort($modules, function (Module $moduleA, Module $moduleB): int {
93+
$dateA = $moduleA->getDate();
94+
if ($dateA === 'unknown') {
95+
$dateA = '0000-00-00 00:00:00';
96+
}
97+
98+
$dateB = $moduleB->getDate();
99+
if ($dateB === 'unknown') {
100+
$dateB = '0000-00-00 00:00:00';
101+
}
102+
103+
if ($dateA < $dateB) {
104+
return 1;
105+
} elseif ($dateA > $dateB) {
106+
return -1;
107+
}
108+
return 0;
109+
});
110+
return $modules;
111+
}
85112
}

src/Classes/ViewModels/ModuleViewModel.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,11 @@ public function getVersion(): string
169169
return $this->module->getVersion();
170170
}
171171

172+
public function getDate(): string
173+
{
174+
return $this->module->getDate();
175+
}
176+
172177
public function isRemote(): bool
173178
{
174179
return $this->module->isRemote();

src/Templates/ModuleInfo.tmpl.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,11 @@
254254
<td><?= $moduleView->getVersion(); ?></td>
255255
</tr>
256256

257+
<tr>
258+
<td>Datum</td>
259+
<td><?= $moduleView->getDate(); ?></td>
260+
</tr>
261+
257262
<tr>
258263
<td>Kompatibel mit Modified</td>
259264
<td>
@@ -332,7 +337,9 @@
332337
<td>Alle Versionen</td>
333338
<td>
334339
<?php foreach ($module->getVersions() as $moduleVersion) {?>
335-
<a href="?action=moduleInfo&archiveName=<?= $moduleVersion->getArchiveName() ?>&version=<?= $moduleVersion->getVersion()?>"><?= $moduleVersion->getVersion(); ?></a>
340+
<a href="?action=moduleInfo&archiveName=<?= $moduleVersion->getArchiveName() ?>&version=<?= $moduleVersion->getVersion()?>">
341+
<?= $moduleVersion->getVersion(); ?>
342+
</a>
336343
<?php if ($moduleVersion->isInstalled()) { ?>
337344
<span>installiert</span>
338345
<?php } elseif ($moduleVersion->isLoaded()) { ?>

src/Templates/ModuleListing.tmpl.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
use RobinTheHood\ModifiedModuleLoaderClient\ModuleStatus;
55
use RobinTheHood\ModifiedModuleLoaderClient\Category;
6+
use RobinTheHood\ModifiedModuleLoaderClient\ModuleSorter;
67
use RobinTheHood\ModifiedModuleLoaderClient\Notification;
78
use RobinTheHood\ModifiedModuleLoaderClient\ViewModels\NotificationViewModel;
89

@@ -35,6 +36,7 @@
3536
<h2><?= Category::getCategoryName($category); ?></h2>
3637
<div class="category">
3738
<?php
39+
$modules = ModuleSorter::sortByDate($modules);
3840
foreach ($modules as $module) {
3941
if ($module->getVisibility() == 'hidden') {
4042
continue;

0 commit comments

Comments
 (0)