public/lib/library.php
/**
     * Takes a RefCode and returns an array with all library information included
     * @global \TPS\mysqli $mysqli
     * @param type $term
     * @return array|boolean
     * @todo Optomize
     */
Takes a RefCode and returns an array with all library information included
@global \TPS\mysqli $mysqli
@param type $term
@return array|boolean
@todo Optomize
Takes a RefCode and returns an array with all library information included @global \ TPS \ mysqli $mysqli @param type $term @return array|boolean @todo Optomize
public function GetFullAlbum($term){
        $this->mysqli;
        $maxResult = 100;
	$selectAlbum = "SELECT " .
			"library.RefCode, " .
			"if(band_websites.ID is NULL,'No','Yes') as hasWebsite, " .
			"if(review.id is NULL,0,1) as reviewed, " .
			"library.Locale, " .
			"library.variousartists, " .
			"library.format, " .
			"library.year, " .
			"library.album, " .
			"library.artist, " .
			"library.CanCon, " .
			"library.datein, " .
			"library.playlist_flag, " .
			"library.genre " .
		"FROM " .
			"library " .
			"left join review on library.RefCode = review.RefCode " .
			"left join band_websites on library.RefCode=band_websites.ID " .
		"WHERE " .
			"library.refcode = ? order by library.datein asc limit ?;";
        $selectWebsites = "Select band_websites.URL, band_websites.Service, band_websites.date_available, band_websites.date_discontinue"
                . " from band_websites where band_websites.ID=?;";
        $params = array();
        if($stmt = $this->mysqli->prepare($selectAlbum)){
            $stmt->bind_param('si',$term,$maxResult);
            $stmt->execute();
            $stmt->bind_result($RefCode,$hasWebsite,$reviewed,$locale,$variousArtists,$format,$year,$album,$artist,$canCon,$datein,$playlist_flag,$genre);
            while($stmt->fetch()){
                $params['album'] = array( 
                        "RefCode"=>$RefCode,
                        "hasWebsite"=>$hasWebsite,
                        "hasReview"=>$reviewed,
                        "format"=>$format,
                        "year"=>$year,
                        "album"=>$album,
                        "artist"=>$artist,
                        "CanCon"=>$canCon,
                        "datein"=>$datein,
                        "playlist"=>$playlist_flag,
                        "genre"=>$genre,
                        "locale"=>$locale,
                        "variousArtists"=>$variousArtists,
			"labels"=>[]
                    );
            }
            $stmt->close();
	    $labels = $this->getLabelsByRefCode($RefCode);
	    foreach($labels as $label) {
		$label_info = array(
		    "Name"=>$label['Name'],
		    "Id"=>$label['LabelNumber']
		);
		array_push($params['album']['labels'], $label_info);
	    }
        }
        else{
            $params['error']=$mysqli->error;
        }
        if($bands = $this->mysqli->prepare($selectWebsites)){
            $websites = array();
            $bands->bind_param('i',$term);
            $bands->execute();
            $bands->bind_result($url,$service,$available,$discontinue);
            while($bands->fetch()){
                $websites[$service]=array(
                    "url" => $url,
                    "available" => $available,
                    "discontinue" => $discontinue);
            }
            $bands->close();
        }
        else{
            error_log($this->mysqli->errno.": ".$this->mysqli->error);
            $params['error']=$this->mysqli->error;
        }
        $params['websites']=$websites?:NULL;
        return $params;
    }
public function GetFullAlbum ( $ term ) { $ this -> mysqli ; $ maxResult = 100 ; $ selectAlbum = " SELECT  " . " library.RefCode,  " . " if(band_websites.ID is NULL,'No','Yes') as hasWebsite,  " . " if(review.id is NULL,0,1) as reviewed,  " . " library.Locale,  " . " library.variousartists,  " . " library.format,  " . " library.year,  " . " library.album,  " . " library.artist,  " . " library.CanCon,  " . " library.datein,  " . " library.playlist_flag,  " . " library.genre  " . " FROM  " . " library  " . " left join review on library.RefCode = review.RefCode  " . " left join band_websites on library.RefCode=band_websites.ID  " . " WHERE  " . " library.refcode = ? order by library.datein asc limit ?; " ; $ selectWebsites = " Select band_websites.URL, band_websites.Service, band_websites.date_available, band_websites.date_discontinue " . "  from band_websites where band_websites.ID=?; " ; $ params = array ( ) ; if ( $ stmt = $ this -> mysqli -> prepare ( $ selectAlbum ) ) { $ stmt -> bind_param ( 'si' , $ term , $ maxResult ) ; $ stmt -> execute ( ) ; $ stmt -> bind_result ( $ RefCode , $ hasWebsite , $ reviewed , $ locale , $ variousArtists , $ format , $ year , $ album , $ artist , $ canCon , $ datein , $ playlist_flag , $ genre ) ; while ( $ stmt -> fetch ( ) ) { $ params [ 'album' ] = array ( " RefCode " => $ RefCode , " hasWebsite " => $ hasWebsite , " hasReview " => $ reviewed , " format " => $ format , " year " => $ year , " album " => $ album , " artist " => $ artist , " CanCon " => $ canCon , " datein " => $ datein , " playlist " => $ playlist_flag , " genre " => $ genre , " locale " => $ locale , " variousArtists " => $ variousArtists , " labels " => [ ] ) ; } $ stmt -> close ( ) ; $ labels = $ this -> getLabelsByRefCode ( $ RefCode ) ; foreach ( $ labels as $ label ) { $ label_info = array ( " Name " => $ label [ 'Name' ] , " Id " => $ label [ 'LabelNumber' ] ) ; array_push ( $ params [ 'album' ] [ 'labels' ] , $ label_info ) ; } } else { $ params [ 'error' ] = $ mysqli -> error ; } if ( $ bands = $ this -> mysqli -> prepare ( $ selectWebsites ) ) { $ websites = array ( ) ; $ bands -> bind_param ( 'i' , $ term ) ; $ bands -> execute ( ) ; $ bands -> bind_result ( $ url , $ service , $ available , $ discontinue ) ; while ( $ bands -> fetch ( ) ) { $ websites [ $ service ] = array ( " url " => $ url , " available " => $ available , " discontinue " => $ discontinue ) ; } $ bands -> close ( ) ; } else { error_log ( $ this -> mysqli -> errno . " :  " . $ this -> mysqli -> error ) ; $ params [ 'error' ] = $ this -> mysqli -> error ; } $ params [ 'websites' ] = $ websites ? : NULL ; return $ params ; }
Takes a RefCode and returns an array with all library information included
 @global \TPS\mysqli $mysqli
 @param type $term
 @return array|boolean
 @todo Optomize
Takes a RefCode and returns an array with all library information included @global \ TPS \ mysqli $mysqli @param type $term @return array|boolean @todo Optomize
// this is ok as if the review ID is null there will also be no other entries as ID is a PK