From bd5640fb50d62096c58307518f0b533fa20affcd Mon Sep 17 00:00:00 2001 From: Cerys Date: Mon, 27 Jan 2025 01:25:56 +0000 Subject: [PATCH] better handling of tune variants --- App/Wrappers/SQLQueryBuilderWrapper.php | 2 +- Pages/tune/uuid.php | 11 +++++- Public/API/V1/GetABCFile.php | 47 +++++++++--------------- Public/Static/CSS/Elements/Accordion.css | 22 +++++++++++ Public/Static/CSS/Elements/_General.css | 4 ++ Public/Static/CSS/Mapper.css | 1 + Public/Static/JS/General/ABCWrapper.js | 2 +- 7 files changed, 57 insertions(+), 32 deletions(-) create mode 100644 Public/Static/CSS/Elements/Accordion.css diff --git a/App/Wrappers/SQLQueryBuilderWrapper.php b/App/Wrappers/SQLQueryBuilderWrapper.php index ae51c99..3d19b1d 100644 --- a/App/Wrappers/SQLQueryBuilderWrapper.php +++ b/App/Wrappers/SQLQueryBuilderWrapper.php @@ -25,7 +25,7 @@ class SQLQueryBuilderWrapper public static function SELECT_ONE(string $table, string $id) { return self::SELECT(table: $table) - ->where(cond: "ID=:__id__") + ->where(cond: "T.ID=:__id__") ->bindValue(name: "__id__", value: $id) ->limit(limit: 1) ; diff --git a/Pages/tune/uuid.php b/Pages/tune/uuid.php index 4d0a3bf..6f2d966 100644 --- a/Pages/tune/uuid.php +++ b/Pages/tune/uuid.php @@ -11,14 +11,23 @@ $db = new DatabaseInteractions(); $tuneDetails = $db->RunOneSelect( queryBuilder: SQLQueryBuilderWrapper::SELECT_ONE( table: 'Tunes', - id: $_GET['tune-id'] + id: $_GET["tune-id"] ), ); +$variants = $db->RunSelect( + queryBuilder: SQLQueryBuilderWrapper::SELECT( + table: 'TuneVariants', + ) + ->where(cond: 'T.TuneID=:__tune_id__') + ->bindValue(name: '__tune_id__', value: $_GET["tune-id"]) +); + TwigWrapper::RenderTwig( target: "Pages/tune/uuid.html.twig", arguments: [ "TuneDetails"=>$tuneDetails, + "TuneVariants"=>$variants, ] ); diff --git a/Public/API/V1/GetABCFile.php b/Public/API/V1/GetABCFile.php index 985eced..c16cd1b 100644 --- a/Public/API/V1/GetABCFile.php +++ b/Public/API/V1/GetABCFile.php @@ -6,28 +6,18 @@ use App\Wrappers\DatabaseInteractions; use App\Wrappers\SQLQueryBuilderWrapper; $tuneDir = __DIR__ . '/../../../LocalStorage/Tunes'; -$targetTuneID = $_GET['tune-id']; +$targetTuneVariantID = $_GET['tune-variant-id']; $db = new DatabaseInteractions(); -$tuneDetails = (new DatabaseInteractions())->RunOneSelect( +$variantDetails = $db->RunOneSelect( queryBuilder: SQLQueryBuilderWrapper::SELECT_ONE( - table: 'Tunes', - id: $targetTuneID - ) - ->cols(cols: [ - 'T.*', - ]) -); - -$variants = $db->RunOneSelect( - queryBuilder: SQLQueryBuilderWrapper::SELECT( - table: 'Tunes' + table: 'TuneVariants', + id: $targetTuneVariantID ) ->cols([ - 'T.ID AS TuneID', - 'T_TV.ID AS TuneVariantID', - 'T.Title', + 'T.ID AS TuneVariantID', + 'T.TuneID AS TuneID', "CONCAT('[', GROUP_CONCAT( CONCAT( '{\"TimeSignature\":', JSON_QUOTE(T_TVP.TimeSignature), ',', @@ -38,27 +28,26 @@ $variants = $db->RunOneSelect( ]) ->join( join: 'INNER', - spec: 'TuneVariants T_TV', - cond: 'T.ID = T_TV.TuneID' - ) - ->join( - join: 'INNER', - spec: 'TuneVariantParts T_TVP', - cond: 'T_TV.ID = T_TVP.TuneVariantID' + spec: 'TuneVariantParts AS T_TVP', + cond: 'T.ID = T_TVP.TuneVariantID' ) - ->where(cond: 'T.ID = :__tune_id__') ->groupBy(spec: [ 'T.ID', - 'T_TV.ID', - 'T.Title', ]) - ->bindValue(name: '__tune_id__', value: $targetTuneID) ); +$tuneDetails = $db->RunOneSelect( + queryBuilder: SQLQueryBuilderWrapper::SELECT_ONE( + table: 'Tunes', + id: $variantDetails['TuneID'] + ) +); + + $tuneDetails = new DatabaseFolkTuneDetails($tuneDetails); -$tuneDetails->Variants[] = new TuneVariant($tuneDetails, $variants); +$variantDetails = new TuneVariant($tuneDetails, $variantDetails); header(header: "Content-type: text/text"); -echo $tuneDetails->Variants[0]->Build(); +echo $variantDetails->Build(); die(); diff --git a/Public/Static/CSS/Elements/Accordion.css b/Public/Static/CSS/Elements/Accordion.css new file mode 100644 index 0000000..0657dc3 --- /dev/null +++ b/Public/Static/CSS/Elements/Accordion.css @@ -0,0 +1,22 @@ +.accordion { + background-color: #eee; + color: #444; + cursor: pointer; + padding: 18px; + width: 100%; + text-align: left; + border: none; + outline: none; + transition: 0.4s; +} + +.active, .accordion:hover { + background-color: #ccc; +} + +.panel { + padding: 0 18px; + background-color: white; + display: none; + overflow: hidden; +} \ No newline at end of file diff --git a/Public/Static/CSS/Elements/_General.css b/Public/Static/CSS/Elements/_General.css index 80ec035..c1dad74 100644 --- a/Public/Static/CSS/Elements/_General.css +++ b/Public/Static/CSS/Elements/_General.css @@ -19,3 +19,7 @@ main { background: var(--colour--main--background); } +.InnerContent { + width: 80%; +} + diff --git a/Public/Static/CSS/Mapper.css b/Public/Static/CSS/Mapper.css index cdf31ab..2c1ca18 100644 --- a/Public/Static/CSS/Mapper.css +++ b/Public/Static/CSS/Mapper.css @@ -8,6 +8,7 @@ /* ELEMENTS */ @import "/Static/CSS/Elements/_General.css"; +@import "/Static/CSS/Elements/Accordion.css"; @import "/Static/CSS/Elements/Columns.css"; @import "/Static/CSS/Elements/DescriptionLists.css"; @import "/Static/CSS/Elements/HomePage.css"; diff --git a/Public/Static/JS/General/ABCWrapper.js b/Public/Static/JS/General/ABCWrapper.js index ec56c8b..83f7efc 100644 --- a/Public/Static/JS/General/ABCWrapper.js +++ b/Public/Static/JS/General/ABCWrapper.js @@ -2,7 +2,7 @@ function RenderABC(containerID, targetTuneID) { - API_GET("/V1/GetABCFile.php?tune-id=" + targetTuneID).then(payload => { + API_GET("/V1/GetABCFile.php?tune-variant-id=" + targetTuneID).then(payload => { const tunes = ABCJS.renderAbc( containerID,