Question: i need this Databases; / / PHP class declaration and logic class ShowsLibrary { public function displayEpisodes ( $showNumber ) { $showRepo = new ShowRepository

i need this Databases";
// PHP class declaration and logic
class ShowsLibrary {
public function displayEpisodes($showNumber){
$showRepo = new ShowRepository();
$rows = $showRepo->findAll($showNumber);
if (count($rows)<1){
$response = TvAPI::episodes($showNumber);
$shows = Show::fromAPIResponse($response);
foreach ($shows as $s){
$showRepo->create($s, $showNumber);
}
} else {
$shows = Show::fromTableRows($rows);
}
// Display episodes
foreach ($shows as $show){
echo "Name: {$show->name}| Season: {$show->season}| Episode: {$show->episode}| Summary: {$show->summary}";
}
}
}
?> added to name = $name;
$this->image = $image;
$this->season = $season;
$this->episode = $episode;
$this->summary = $summary;
$this->showNumber = $showNumber;
}
public static function fromTableRows($rows){
return array_map(function($row){
return new Show($row['name'], $row['image'], $row['season'], $row['episode'], $row['summary'], $row['show_number']);
}, $rows);
}
public static function fromAPIResponse($response){
return array_map(function($item){
return new Show($item['name'], $item['image'], $item['season'], $item['episode'], $item['summary'], $item['show_number']);
}, $response);
}
}
class ShowRepo {
public $database;
public function __construct(){
$this->database = new SQLite3('shows.db');
$this->database->exec('CREATE TABLE IF NOT EXISTS shows (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, image TEXT, season INTEGER NOT NULL, episode INTEGER NOT NULL, summary TEXT NOT NULL, show_number INTEGER NOT NULL)');
}
public function create($show){
$sql = "INSERT INTO shows (name, image, season, episode, summary, show_number) VALUES (?,?,?,?,?,?)";
$stmt = $this->database->prepare($sql);
$stmt->bindValue(1, $show->name);
$stmt->bindValue(2, $show->image);
$stmt->bindValue(3, $show->season);
$stmt->bindValue(4, $show->episode);
$stmt->bindValue(5, $show->summary);
$stmt->bindValue(6, $show->showNumber);
$stmt->execute();
}
// Add the rest of your code here...
}
class TvAPI {
public static function show($showNumber){
// API call to get show details...
}
}
?>

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!