You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							106 lines
						
					
					
						
							2.8 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							106 lines
						
					
					
						
							2.8 KiB
						
					
					
				
								<?php
							 | 
						|
								
							 | 
						|
								use App\Enumerators\SessionElement;
							 | 
						|
								use App\Wrappers\DatabaseInteractions;
							 | 
						|
								use App\Wrappers\SessionWrapper;
							 | 
						|
								use App\Wrappers\SQLQueryBuilderWrapper;
							 | 
						|
								use App\Wrappers\TwigWrapper;
							 | 
						|
								
							 | 
						|
								require_once __DIR__ . "/../../vendor/autoload.php";
							 | 
						|
								
							 | 
						|
								$db = new DatabaseInteractions();
							 | 
						|
								
							 | 
						|
								$tuneDetails = $db->RunOneSelect(
							 | 
						|
								    queryBuilder: SQLQueryBuilderWrapper::SELECT_ONE(
							 | 
						|
								        table: 'Tunes',
							 | 
						|
								        id: $_GET["tune-id"]
							 | 
						|
								    )
							 | 
						|
								        ->cols(cols: [
							 | 
						|
								            'SUM(CASE WHEN T_TR.Rating = 1 THEN 1 ELSE 0 END) AS Likes',
							 | 
						|
								            'SUM(CASE WHEN T_TR.Rating = -1 THEN 1 ELSE 0 END) AS Dislikes',
							 | 
						|
								        ])
							 | 
						|
								        ->join(
							 | 
						|
								            join: 'LEFT',
							 | 
						|
								            spec: 'TuneRatings AS T_TR',
							 | 
						|
								            cond: 'T.ID=T_TR.TuneID',
							 | 
						|
								        )
							 | 
						|
								);
							 | 
						|
								
							 | 
						|
								
							 | 
						|
								
							 | 
						|
								$dances = $db->RunSelect(
							 | 
						|
								    queryBuilder: SQLQueryBuilderWrapper::SELECT(
							 | 
						|
								        table: 'Dances',
							 | 
						|
								    )
							 | 
						|
								        ->cols(cols: [
							 | 
						|
								            "CONCAT('[', GROUP_CONCAT(
							 | 
						|
								                CONCAT(
							 | 
						|
								                    '{\"ID\":', JSON_QUOTE(T_DS.ID), ',',
							 | 
						|
								                    '\"CreatedAt\":', JSON_QUOTE(T_DS.CreatedAt), ',',
							 | 
						|
								                    '\"DanceID\":', JSON_QUOTE(T_DS.DanceID), ',',
							 | 
						|
								                    '\"BarCountAtStart\":', T_DS.BarCountAtStart, ',',
							 | 
						|
								                    '\"BarCountAtEnd\":', T_DS.BarCountAtEnd, ',',
							 | 
						|
								                    '\"Description\":', JSON_QUOTE(T_DS.Description), '}'
							 | 
						|
								                )
							 | 
						|
								            ), ']') AS Steps"
							 | 
						|
								        ])
							 | 
						|
								        ->join(
							 | 
						|
								            join: 'INNER',
							 | 
						|
								            spec: 'DanceSteps AS T_DS',
							 | 
						|
								            cond: 'T.ID=T_DS.DanceID'
							 | 
						|
								        )
							 | 
						|
								        ->join(
							 | 
						|
								            join: 'INNER',
							 | 
						|
								            spec: '_Junction_Tunes_Dances AS _J_T_D',
							 | 
						|
								            cond: 'T.ID=_J_T_D.DanceID'
							 | 
						|
								        )
							 | 
						|
								        ->where(cond: '_J_T_D.TuneID=:__tune_id__')
							 | 
						|
								        ->bindValue(name: '__tune_id__', value: $_GET["tune-id"])
							 | 
						|
								        ->groupBy(spec: [
							 | 
						|
								            'T.ID',
							 | 
						|
								            'T.CreatedAt',
							 | 
						|
								            'T.Title',
							 | 
						|
								            '_J_T_D.ID',
							 | 
						|
								            '_J_T_D.CreatedAt',
							 | 
						|
								            '_J_T_D.TuneID',
							 | 
						|
								            '_J_T_D.DanceID',
							 | 
						|
								        ])
							 | 
						|
								);
							 | 
						|
								
							 | 
						|
								for ($i = 0; $i < count($dances); $i++)
							 | 
						|
								    $dances[$i]['Steps'] = json_decode(
							 | 
						|
								        $dances[$i]['Steps'],
							 | 
						|
								        true,
							 | 
						|
								        JSON_THROW_ON_ERROR
							 | 
						|
								    );
							 | 
						|
								
							 | 
						|
								
							 | 
						|
								$myVote = $db->RunSelect(
							 | 
						|
								    queryBuilder: SQLQueryBuilderWrapper::SELECT(
							 | 
						|
								        table: 'TuneRatings',
							 | 
						|
								    )
							 | 
						|
								        ->cols(cols: [
							 | 
						|
								            'Rating'
							 | 
						|
								        ])
							 | 
						|
								        ->where(cond: 'CreatedBy=:__user_id__')
							 | 
						|
								        ->where(cond: 'TuneID=:__tune_id__')
							 | 
						|
								        ->bindValue(name: '__user_id__', value: SessionWrapper::Get(SessionElement::USER_ID))
							 | 
						|
								        ->bindValue(name: '__tune_id__', value: $_GET["tune-id"])
							 | 
						|
								);
							 | 
						|
								if($myVote == [])
							 | 
						|
								    $myVote = 0;
							 | 
						|
								else
							 | 
						|
								{
							 | 
						|
								    $myVote = $myVote[0]['Rating'];
							 | 
						|
								}
							 | 
						|
								
							 | 
						|
								
							 | 
						|
								TwigWrapper::RenderTwig(
							 | 
						|
								    target: "Pages/tune/uuid.html.twig",
							 | 
						|
								    arguments: [
							 | 
						|
								        "TuneDetails"=>$tuneDetails,
							 | 
						|
								        "Dances"=>$dances,
							 | 
						|
								        "MyVote"=>$myVote,
							 | 
						|
								    ]
							 | 
						|
								);
							 | 
						|
								
							 | 
						|
								
							 |