generate_release_description()   B
last analyzed

Complexity

Conditions 8
Paths 128

Size

Total Lines 48
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
eloc 24
nc 128
nop 5
dl 0
loc 48
rs 8.2111
c 0
b 0
f 0
1
<?php
2
require "../../config/common.php";
3
4
require_once __DIR__."/../../common/DAO/GameDAO.php";
5
require_once __DIR__."/../../common/DAO/GameReleaseDAO.php";
6
require_once __DIR__."/../../common/DAO/LocationDAO.php";
7
require_once __DIR__."/../../common/DAO/GameReleaseAkaDAO.php";
8
require_once __DIR__."/../../common/DAO/PubDevDAO.php";
9
require_once __DIR__."/../../common/DAO/LanguageDAO.php";
10
require_once __DIR__."/../../common/DAO/SystemDAO.php";
11
require_once __DIR__."/../../common/DAO/EmulatorDAO.php";
12
require_once __DIR__."/../../common/DAO/TosDAO.php";
13
require_once __DIR__."/../../common/DAO/EnhancementDAO.php";
14
require_once __DIR__."/../../common/DAO/MemoryDAO.php";
15
require_once __DIR__."/../../common/DAO/CopyProtectionDAO.php";
16
require_once __DIR__."/../../common/DAO/DiskProtectionDAO.php";
17
require_once __DIR__."/../../common/DAO/MediaDAO.php";
18
require_once __DIR__."/../../common/DAO/DumpDAO.php";
19
require_once __DIR__."/../../common/DAO/MediaScanDAO.php";
20
require_once __DIR__."/../../common/DAO/GameReleaseScanDAO.php";
21
require_once __DIR__."/../../common/DAO/CrewDAO.php";
22
23
$gameDao = new \AL\Common\DAO\GameDAO($mysqli);
24
$gameReleaseDao = new \AL\Common\DAO\GameReleaseDAO($mysqli);
25
$locationDao = new \AL\Common\DAO\LocationDAO($mysqli);
26
$gameReleaseAkaDao = new \AL\Common\DAO\GameReleaseAkaDAO($mysqli);
27
$pubDevDao = new \AL\Common\DAO\PubDevDAO($mysqli);
28
$languageDao = new \AL\Common\DAO\LanguageDAO($mysqli);
29
$systemDao = new \AL\Common\DAO\SystemDao($mysqli);
30
$emulatorDao = new \AL\Common\DAO\EmulatorDAO($mysqli);
31
$tosDao = new \AL\Common\DAO\TosDAO($mysqli);
32
$enhancementDao = new \AL\Common\DAO\EnhancementDAO($mysqli);
33
$memoryDao = new \AL\Common\DAO\MemoryDAO($mysqli);
34
$copyProtectionDao = new \AL\Common\DAO\CopyProtectionDAO($mysqli);
35
$diskProtectionDao = new \AL\Common\DAO\DiskProtectionDAO($mysqli);
36
$mediaDao = new \AL\Common\DAO\MediaDAO($mysqli);
37
$dumpDao = new \AL\Common\DAO\DumpDAO($mysqli);
38
$mediaScanDao = new \AL\Common\DAO\MediaScanDAO($mysqli);
39
$gameReleaseScanDao = new AL\Common\DAO\GameReleaseScanDAO($mysqli);
40
$crewDao = new \AL\Common\DAO\CrewDAO($mysqli);
41
42
function generate_release_description(
43
    $release,
44
    $game,
45
    $release_locations,
46
    $media,
47
    $dumps
48
) {
49
    $year = $release->getDate()
50
        ? date("Y", strtotime($release->getDate()))
51
        : "[no date]";
52
53
    $desc[] = "$year release of ".$game->getName();
0 ignored issues
show
Comprehensibility Best Practice introduced by
$desc was never initialized. Although not strictly required by PHP, it is generally a good practice to add $desc = array(); before regardless.
Loading history...
54
55
    if ($release->getName()) {
56
        $desc[] = "(".$release->getName().")";
57
    }
58
59
    if (count($release_locations) > 0) {
60
        $desc[] = "in ".join(
61
            ", ",
62
            array_map(
63
                function ($location) {
64
                    return $location->getName();
65
                },
66
                $release_locations
67
            )
68
        );
69
    }
70
71
    if ($release->getPublisher()) {
72
        $desc[] = "published by ".$release->getPublisher()->getName();
73
    }
74
75
    $items = [];
76
    if (count($media) > 0) {
77
        $items[] = count($media)." media";
78
    }
79
80
    if (count($dumps) > 0) {
81
        $items[] = count($dumps). " downloads";
82
    }
83
84
    $description = join(" ", $desc);
85
    if (count($items) > 0) {
86
        $description .= " (".join(", ", $items).")";
87
    }
88
89
    return $description;
90
}
91
92
$release = $gameReleaseDao->getRelease($release_id);
93
$game = $gameDao->getGame($release->getGameId());
94
95
$smarty->assign('game', $game);
96
$smarty->assign('release', $release);
97
98
$release_locations = $locationDao->getLocationsForRelease($release->getId());
99
$smarty->assign('release_locations', $release_locations);
100
$smarty->assign('release_akas', $gameReleaseAkaDao->getAllGameReleaseAkas($release->getId()));
101
$smarty->assign('release_distributors', $pubDevDao->getDistributorsForRelease($release->getId()));
102
$smarty->assign('release_languages', $languageDao->getReleaseLanguages($release->getId()));
103
104
$smarty->assign('systems_incompatible', $systemDao->getIncompatibleSystemsForRelease($release->getId()));
105
$smarty->assign('emulators_incompatible', $emulatorDao->getIncompatibleEmulatorForRelease($release->getId()));
106
$smarty->assign('tos_incompatible', $tosDao->getIncompatibleTosForRelease($release->getId()));
107
108
$smarty->assign('systems_enhanced', $systemDao->getEnhancedSystemsForRelease($release->getId()));
109
$smarty->assign('memory_enhancements', $memoryDao->getMemoryForRelease($release->getId()));
110
$smarty->assign('minimum_memory', $memoryDao->getMinimumMemoryForRelease($release->getId()));
111
$smarty->assign('memory_incompatible', $memoryDao->getMemoryIncompatibleForRelease($release->getId()));
112
$smarty->assign('copy_protections', $copyProtectionDao->getCopyProtectionsForRelease($release->getId()));
113
$smarty->assign('disk_protections', $diskProtectionDao->getDiskProtectionsForRelease($release->getId()));
114
$smarty->assign('release_scans', $gameReleaseScanDao->getScansForRelease($release->getId()));
115
$smarty->assign('crews', $crewDao->getCrewsForRelease($release->getId()));
116
117
$media = $mediaDao->getAllMediaFromRelease($release->getId());
118
$smarty->assign('medias', $media);
119
120
$dumps = [];
121
$mediaScans = [];
122
foreach ($media as $medium) {
123
    $dumps[$medium->getId()] = $dumpDao->getAllDumpsFromMedia($medium->getId());
124
    $mediaScans[$medium->getId()] = $mediaScanDao->getAllMediaScansFromMedia($medium->getId());
125
}
126
$smarty->assign('dumps', $dumps);
127
$smarty->assign('media_scans', $mediaScans);
128
$smarty->assign('media_scans_path', $media_scan_path);
129
130
$smarty->assign('release_description', generate_release_description(
131
    $release,
132
    $game,
133
    $release_locations,
134
    $media,
135
    $dumps
136
));
137
138
$smarty->display("file:" . $mainsite_template_folder. "games/games_release_main.html");
139