static function findAll($dbh)
 {
     //Question 2
     $stmt = $dbh->prepare("select * from " . Enemy::$tableName . " order by priority");
     $stmt->execute();
     $result = array();
     while ($row = $stmt->fetch()) {
         $e = new Enemy();
         $e->copyFromRow($row);
         $result[] = $e;
     }
     return $result;
 }
 public function get($id)
 {
     $enemy = Enemy::with('episodes')->find($id);
     $ratings = Rating::getRating('enemy', $id);
     $comments = Comment::where('item_id', $id)->where('item_type', 'enemy')->with('user')->orderBy('created_at', 'desc')->get();
     return View::make('items.enemy', ['enemy' => $enemy, 'ratings' => $ratings, 'comments' => $comments]);
 }
 public function index()
 {
     $doctors = Doctor::take(4)->orderBy('number')->get();
     $companions = Companion::take(4)->get();
     $enemies = Enemy::take(4)->get();
     $episodes = Episode::take(4)->get();
     return View::make('index', ['doctors' => $doctors, 'companions' => $companions, 'enemies' => $enemies, 'episodes' => $episodes]);
 }
 public function run()
 {
     DB::table('enemies')->delete();
     DB::table('doctor_enemy')->delete();
     // Pull up the doctors to attach to companions
     $doctorNine = Doctor::where('number', 9)->first();
     $doctorTen = Doctor::where('number', 10)->first();
     $doctorEleven = Doctor::where('number', 11)->first();
     $doctorTwelve = Doctor::where('number', 12)->first();
     Enemy::create(array('name' => 'Cybermen', 'description' => 'Originally born on Earth’s twin planet Mondas, the Cybermen were created as the Mondasians replaced parts of their dying bodies with plastic and steel. Eventually they added emotional inhibitors, supressing all feelings – love, hate, even fear. Cybermen can convert humans wherever they go, and take orders from a Cyberleader, whose data can be downloaded to a drone if the leader is destroyed. Like the Daleks, the Cybermen have dogged the Doctor through space and time. He has prevented them destroying Earth’s weather system, getting their hands on the Nemesis statue and taking over Victorian London with their Cyber-King. The Tenth Doctor visited a parallel universe, where Cybus Industries had developed Cybermen to prolong John Lumic’s dwindling life.', 'image' => 'http://thedoctor.coderfaire/assets/img/enemies/cybermen.png'))->doctors()->attach([$doctorTen->id, $doctorEleven->id]);
     Enemy::create(array('name' => 'Daleks', 'description' => 'The Doctor first encountered the Daleks on the radiation-soaked planet of Skaro, waging war with the peaceful Thals. The Daleks were the mangled and mutated remains of the Kaled people, placed in metal war machines by the Kaled’s chief scientist Davros. Pursuing the Doctor across space and time, the Daleks invaded the Earth, developed the Reality Bomb and tried to imprison the Doctor in the Pandorica. They fought the Time Lords in The Last Great Time War – a conflict so powerful and destructive that the universe was said to convulse. In an effort to save reality, the Doctor used ‘the Moment’ to annihilate both races. But that wasn’t the end of the Daleks...', 'image' => 'http://thedoctor.coderfaire/assets/img/enemies/daleks.png'))->doctors()->attach([$doctorNine->id, $doctorTen->id, $doctorEleven->id, $doctorTwelve->id]);
     Enemy::create(array('name' => 'Sontarans', 'description' => 'An aggressive clone-warrior race from Sontar, who travel in spherical ships, the Sontarans were engaged in a war lasting many thousands of years with the Rutans. In pursuit of the advantage, Commander Linx of the Fifth Sontaran Battle Group tried to invade 13th century Earth, until repelled by the Third Doctor. Later meetings with the Doctor saw the Sontarans invading the Time Lord home planet of Gallifrey, forcing the Sixth Doctor to build them a time travel machine, and trying to covert Earth’s atmosphere into one suitable for warrior cloning using the ATMOS machines. Sarah Jane Smith later encountered – and defeated – the last survivor of that invasion, Commander Kaagh.', 'image' => 'http://thedoctor.coderfaire/assets/img/enemies/sontarans.png'))->doctors()->attach([$doctorTen->id, $doctorEleven->id]);
     Enemy::create(array('name' => 'The Silence', 'description' => 'Rather than a specific race, The Silence are a religious order. Their agents on Earth have been there since before the dawn of mankind, directing human evolution. They use post-hypnotic suggestion to make people who see them instantly forget their existence. They believe that silence must fall when the oldest Question in the universe is asked. It will be asked at “the fall of the Eleventh” on the Fields of Trenzalore, and is hidden in plain sight. As a result, the Silence have tried to stop the Doctor reaching Trenzalore. They used their agent Madame Kovarian to kidnap Melody Pond, and raised her as the Doctor’s perfect assassin. Despite the failure of this plan, the Silence remain at large, determined to stop the Question ever being asked.', 'image' => 'http://thedoctor.coderfaire/assets/img/enemies/the-silence.png'))->doctors()->attach([$doctorEleven->id]);
     Enemy::create(array('name' => 'Weeping Angels', 'description' => 'Known as “The Lonely Assassins”, the Weeping Angels are quantum-locked alien killers, as old as the universe itself. Little is known of their origins or culture. When observed, they freeze like stone, but in the blink of an eye they can move vast distances. The touch of an Angel hurls their victim back in time – allowing the Angel to feast on the energy of their unlived days. Initially, the Tenth Doctor encountered four Angels, who sent him back to 1969. He left clues for Sally Sparrow to find and help trap them – releasing him and the TARDIS. Later encounters have seen a whole mausoleum of statues, tiny cherubs and even the Statue of Liberty transformed into Weeping Angels. Both Amy and Rory were trapped by a Weeping Angel, when it sent them back to 1938 to live out their lives together. In the 51st Century, the Doctor trapped the Angels in a crack in time, erasing them from history.', 'image' => 'http://thedoctor.coderfaire/assets/img/enemies/weeping-angels.png'))->doctors()->attach([$doctorTen->id, $doctorEleven->id]);
 }
 public function run()
 {
     DB::table('ratings')->delete();
     // Going to randomize all our ratings for our users, so throw everything in
     // an array.
     $toRate = array(array('item' => Doctor::where('number', 9)->first(), 'type' => 'doctor'), array('item' => Doctor::where('number', 10)->first(), 'type' => 'doctor'), array('item' => Doctor::where('number', 11)->first(), 'type' => 'doctor'), array('item' => Doctor::where('number', 12)->first(), 'type' => 'doctor'), array('item' => Enemy::where('name', 'Cybermen')->first(), 'type' => 'enemy'), array('item' => Enemy::where('name', 'Daleks')->first(), 'type' => 'enemy'), array('item' => Enemy::where('name', 'Sontarans')->first(), 'type' => 'enemy'), array('item' => Enemy::where('name', 'The Silence')->first(), 'type' => 'enemy'), array('item' => Enemy::where('name', 'Weeping Angels')->first(), 'type' => 'enemy'), array('item' => Companion::where('name', 'Amy Pond')->first(), 'type' => 'companion'), array('item' => Companion::where('name', 'Captain Jack')->first(), 'type' => 'companion'), array('item' => Companion::where('name', 'Clara Oswald')->first(), 'type' => 'companion'), array('item' => Companion::where('name', 'Donna Noble')->first(), 'type' => 'companion'), array('item' => Companion::where('name', 'Martha Jones')->first(), 'type' => 'companion'), array('item' => Companion::where('name', 'Mickey Smith')->first(), 'type' => 'companion'), array('item' => Companion::where('name', 'River Song')->first(), 'type' => 'companion'), array('item' => Companion::where('name', 'Rory Williams')->first(), 'type' => 'companion'), array('item' => Companion::where('name', 'Rose Tyler')->first(), 'type' => 'companion'), array('item' => Companion::where('name', 'Wilfred Mott')->first(), 'type' => 'companion'), array('item' => Episode::where('season', 1)->where('episode', 1)->first(), 'type' => 'episode'), array('item' => Episode::where('season', 1)->where('episode', 6)->first(), 'type' => 'episode'), array('item' => Episode::where('season', 1)->where('episode', 10)->first(), 'type' => 'episode'), array('item' => Episode::where('season', 1)->where('episode', 12)->first(), 'type' => 'episode'), array('item' => Episode::where('season', 2)->where('episode', 5)->first(), 'type' => 'episode'), array('item' => Episode::where('season', 2)->where('episode', 12)->first(), 'type' => 'episode'), array('item' => Episode::where('season', 3)->where('episode', 9)->first(), 'type' => 'episode'), array('item' => Episode::where('season', 3)->where('episode', 10)->first(), 'type' => 'episode'), array('item' => Episode::where('season', 4)->where('episode', 4)->first(), 'type' => 'episode'), array('item' => Episode::where('season', 4)->where('episode', 13)->first(), 'type' => 'episode'), array('item' => Episode::where('season', 5)->where('episode', 3)->first(), 'type' => 'episode'), array('item' => Episode::where('season', 5)->where('episode', 4)->first(), 'type' => 'episode'), array('item' => Episode::where('season', 5)->where('episode', 12)->first(), 'type' => 'episode'), array('item' => Episode::where('season', 6)->where('episode', 1)->first(), 'type' => 'episode'), array('item' => Episode::where('season', 6)->where('episode', 10)->first(), 'type' => 'episode'), array('item' => Episode::where('season', 6)->where('episode', 13)->first(), 'type' => 'episode'), array('item' => Episode::where('season', 7)->where('episode', 5)->first(), 'type' => 'episode'), array('item' => Episode::where('season', 7)->where('episode', 12)->first(), 'type' => 'episode'), array('item' => Episode::where('season', 8)->where('episode', 2)->first(), 'type' => 'episode'));
     $users = User::get();
     // Loop through our users
     foreach ($users as $user) {
         // Loop through things to be rated
         foreach ($toRate as $item) {
             $rating = rand(1, 5);
             Rating::create(array('user_id' => $user->id, 'item_id' => $item['item']->id, 'item_type' => $item['type'], 'rating' => $rating));
         }
     }
 }
 public function run()
 {
     DB::table('comments')->delete();
     // Going to randomize all our ratings for our users, so throw everything in
     // an array.
     $toComment = array(array('item' => Doctor::where('number', 9)->first(), 'type' => 'doctor'), array('item' => Doctor::where('number', 10)->first(), 'type' => 'doctor'), array('item' => Doctor::where('number', 11)->first(), 'type' => 'doctor'), array('item' => Doctor::where('number', 12)->first(), 'type' => 'doctor'), array('item' => Enemy::where('name', 'Cybermen')->first(), 'type' => 'enemy'), array('item' => Enemy::where('name', 'Daleks')->first(), 'type' => 'enemy'), array('item' => Enemy::where('name', 'Sontarans')->first(), 'type' => 'enemy'), array('item' => Enemy::where('name', 'The Silence')->first(), 'type' => 'enemy'), array('item' => Enemy::where('name', 'Weeping Angels')->first(), 'type' => 'enemy'), array('item' => Companion::where('name', 'Amy Pond')->first(), 'type' => 'companion'), array('item' => Companion::where('name', 'Captain Jack')->first(), 'type' => 'companion'), array('item' => Companion::where('name', 'Clara Oswald')->first(), 'type' => 'companion'), array('item' => Companion::where('name', 'Donna Noble')->first(), 'type' => 'companion'), array('item' => Companion::where('name', 'Martha Jones')->first(), 'type' => 'companion'), array('item' => Companion::where('name', 'Mickey Smith')->first(), 'type' => 'companion'), array('item' => Companion::where('name', 'River Song')->first(), 'type' => 'companion'), array('item' => Companion::where('name', 'Rory Williams')->first(), 'type' => 'companion'), array('item' => Companion::where('name', 'Rose Tyler')->first(), 'type' => 'companion'), array('item' => Companion::where('name', 'Wilfred Mott')->first(), 'type' => 'companion'), array('item' => Episode::where('season', 1)->where('episode', 1)->first(), 'type' => 'episode'), array('item' => Episode::where('season', 1)->where('episode', 6)->first(), 'type' => 'episode'), array('item' => Episode::where('season', 1)->where('episode', 10)->first(), 'type' => 'episode'), array('item' => Episode::where('season', 1)->where('episode', 12)->first(), 'type' => 'episode'), array('item' => Episode::where('season', 2)->where('episode', 5)->first(), 'type' => 'episode'), array('item' => Episode::where('season', 2)->where('episode', 12)->first(), 'type' => 'episode'), array('item' => Episode::where('season', 3)->where('episode', 9)->first(), 'type' => 'episode'), array('item' => Episode::where('season', 3)->where('episode', 10)->first(), 'type' => 'episode'), array('item' => Episode::where('season', 4)->where('episode', 4)->first(), 'type' => 'episode'), array('item' => Episode::where('season', 4)->where('episode', 13)->first(), 'type' => 'episode'), array('item' => Episode::where('season', 5)->where('episode', 3)->first(), 'type' => 'episode'), array('item' => Episode::where('season', 5)->where('episode', 4)->first(), 'type' => 'episode'), array('item' => Episode::where('season', 5)->where('episode', 12)->first(), 'type' => 'episode'), array('item' => Episode::where('season', 6)->where('episode', 1)->first(), 'type' => 'episode'), array('item' => Episode::where('season', 6)->where('episode', 10)->first(), 'type' => 'episode'), array('item' => Episode::where('season', 6)->where('episode', 13)->first(), 'type' => 'episode'), array('item' => Episode::where('season', 7)->where('episode', 5)->first(), 'type' => 'episode'), array('item' => Episode::where('season', 7)->where('episode', 12)->first(), 'type' => 'episode'), array('item' => Episode::where('season', 8)->where('episode', 2)->first(), 'type' => 'episode'));
     $titles = array('Fabulous!', 'My favorite!', 'This stank more than anything has stunk before', 'This one put me to sleep', 'Stay away', 'Not impressed', 'Vote for Pedro', 'Cheap Wristwatch', 'I hope to see this again', 'Blew my mind', 'Ripoff', 'The old one was better', 'Better than ever');
     $comments = array("It's time to play the music. It's time to light the lights. It's time to meet the Muppets on the Muppet Show tonight. Movin' on up to the east side. We finally got a piece of the pie. Doin' it our way. There's nothing we wont try. Never heard the word impossible. This time there's no stopping us. The first mate and his Skipper too will do their very best to make the others comfortable in their tropic island nest. I have always wanted to have a neighbor just like you. I've always wanted to live in a neighborhood with you. Straightnin' the curves. Flatnin' the hills Someday the mountain might get ‘em but the law never will. Well the first thing you know ol' Jeds a millionaire. Kinfolk said Jed move away from there. black gold.\" Fish don't fry in the kitchen and beans don't burn on the grill. Took a whole lotta tryin' just to get up that hill.", "But they got diff'rent strokes. It takes diff'rent strokes - it takes diff'rent strokes to move the world. You wanna be where you can see our troubles are all the same. You wanna be where everybody knows Your name. Then one day he was shootin' at some food and up through the ground came a bubblin' crude. Oil that is It's time to put on makeup. It's time to dress up right. It's time to raise the curtain on the Muppet Show tonight. They were four men living all together yet they were all alone. Come and listen to a story about a man named Jed - a poor mountaineer barely kept his family fed. The year is 1987 and NASA launches the last of Americas deep space probes. The Brady Bunch the Brady Bunch that's the way we all became the Brady Bunch? It's time to put on makeup. It's time to dress up right. It's time to raise the curtain on the Muppet Show tonight. Here's the story of a lovely lady who was bringing up three very lovely girls. Here he comes Here comes Speed Racer. He's a demon on wheels!", "Fleeing from the Cylon tyranny the last Battlestar – Galactica - leads a rag-tag fugitive fleet on a lonely quest - a shining planet known as Earth. So lets make the most of this beautiful day. Since we're together The movie star the professor and Mary Ann here on Gilligans Isle. Wouldn't you like to get away? Sometimes you want to go where everybody knows your name. And they're always glad you came. We're gonna do it. On your mark get set and go now. Got a dream and we just know now we're gonna make our dream come true. Goodbye gray sky hello blue. There's nothing can hold me when I hold you. Feels so right it cant be wrong. Rockin' and rollin' all week long. Sunny Days sweepin' the clouds away. On my way to where the air is sweet. Can you tell me how to get how to get to Sesame Street? And if you threw a party - invited everyone you knew. You would see the biggest gift would be from me and the card attached would say thank you for being a friend. Well we're movin' on up to the east side. To a deluxe apartment in the sky. Knight Rider: A shadowy flight into the dangerous world of a man who does not exist. Believe it or not I'm walking on air. I never thought I could feel so free.", "Baby if you've ever wondered - wondered whatever became of me. I'm living on the air in Cincinnati. Cincinnati WKRP. Didn't need no welfare states. Everybody pulled his weight. Gee our old Lasalle ran great. Those were the days. And if you threw a party - invited everyone you knew. You would see the biggest gift would be from me and the card attached would say thank you for being a friend. Come and listen to a story about a man named Jed - a poor mountaineer barely kept his family fed! One two three four five six seven eight Sclemeel schlemazel hasenfeffer incorporated. black gold But they got diff'rent strokes. It takes diff'rent strokes - it takes diff'rent strokes to move the world.", "All of them had hair of gold like their mother the youngest one in curls! All of them had hair of gold like their mother the youngest one in curls. Believe it or not I'm walking on air. I never thought I could feel so free. Just two good ol' boys Never meanin' no harm. Beats all you've ever saw been in trouble with the law since the day they was born. The ship set ground on the shore of this uncharted desert isle with Gilligan the Skipper too the millionaire and his wife. Doin' it our way. Nothin's gonna turn us back now. Straight ahead and on the track now. We're gonna make our dreams come true. If you have a problem if no one else can help and if you can find them maybe you can hire The A-Team!", "If you have a problem if no one else can help and if you can find them maybe you can hire The A-Team. But they got diff'rent strokes. It takes diff'rent strokes - it takes diff'rent strokes to move the world. Now the world don't move to the beat of just one drum. What might be right for you may not be right for some.", "Were gonna do it. Give us any chance well take it. Give us any rule we'll break it. We're gonna make our dreams come true. Why do we always come here? I guess well never know. Its like a kind of torture to have to watch the show.", "black gold Why do we always come here? I guess well never know. Its like a kind of torture to have to watch the show. Here's the story of a lovely lady who was bringing up three very lovely girls. They were four men living all together yet they were all alone. Maybe you and me were never meant to be. But baby think of me once in awhile. I'm at WKRP in Cincinnati. The Brady Bunch the Brady Bunch that's the way we all became the Brady Bunch. Believe it or not I'm walking on air. I never thought I could feel so free. And we'll do it our way yes our way. Make all our dreams come true for me and you. Come and knock on our door. We've been waiting for you. Where the kisses are hers and hers and his. Three's company too? Texas tea., Till the one day when the lady met this fellow and they knew it was much more than a hunch. It's a beautiful day in this neighborhood a beautiful day for a neighbor. Would you be mine? Could you be mine? Its a neighborly day in this beautywood a neighborly day for a beauty. Would you be mine? Could you be mine. On the most sensational inspirational celebrational Muppetational… This is what we call the Muppet Show.", "The movie star the professor and Mary Ann here on Gilligans Isle. They're creepy and they're kooky mysterious and spooky. They're all together ooky the Addams Family. They call him Flipper Flipper faster than lightning. No one you see is smarter than he. The first mate and his Skipper too will do their very best to make the others comfortable in their tropic island nest. So get a witch's shawl on a broomstick you can crawl on. Were gonna pay a call on the Addams Family. Now the world don't move to the beat of just one drum. What might be right for you may not be right for some. Believe it or not I'm walking on air. I never thought I could feel so free. Flying away on a wing and a prayer. Who could it be? Believe it or not its just me. Doin' it our way. There's nothing we wont try. Never heard the word impossible. This time there's no stopping us.", "Movin' on up to the east side. We finally got a piece of the pie. Come and knock on our door. We've been waiting for you. Where the kisses are hers and hers and his. Three's company too. Just two good ol' boys Wouldn't change if they could. Fightin' the system like a true modern day Robin Hood. Space. The final frontier. These are the voyages of the Starship Enterprise. Doin' it our way. Nothin's gonna turn us back now. Straight ahead and on the track now. We're gonna make our dreams come true. Michael Knight a young loner on a crusade to champion the cause of the innocent. The helpless. The powerless in a world of criminals who operate above the law.", "Texas tea. I have always wanted to have a neighbor just like you. I've always wanted to live in a neighborhood with you? No phone no lights no motor car not a single luxury. Like Robinson Crusoe it's primitive as can be. black gold. And when the odds are against him and their dangers work to do. You bet your life Speed Racer he will see it through. we might as well say... Would you be mine? Could you be mine? Won't you be my neighbor. One two three four five six seven eight Sclemeel schlemazel hasenfeffer incorporated., It's time to put on makeup. It's time to dress up right. It's time to raise the curtain on the Muppet Show tonight!", "Goodbye gray sky hello blue. There's nothing can hold me when I hold you. Feels so right it cant be wrong. Rockin' and rollin' all week long. The mate was a mighty sailin' man the Skipper brave and sure. Five passengers set sail that day for a three hour tour a three hour tour.", "Knight Rider: A shadowy flight into the dangerous world of a man who does not exist. It's time to put on makeup. It's time to dress up right. It's time to raise the curtain on the Muppet Show tonight. The Brady Bunch the Brady Bunch that's the way we all became the Brady Bunch. Just two good ol' boys Wouldn't change if they could. Fightin' the system like a true modern day Robin Hood.", "So this is the tale of our castaways they're here for a long long time. They'll have to make the best of things its an uphill climb. It's time to play the music. It's time to light the lights. It's time to meet the Muppets on the Muppet Show tonight. It's time to put on makeup. It's time to dress up right. It's time to raise the curtain on the Muppet Show tonight. Here's the story of a lovely lady who was bringing up three very lovely girls. Baby if you've ever wondered - wondered whatever became of me. I'm living on the air in Cincinnati. Cincinnati WKRP.", "These days are all Happy and Free. These days are all share them with me oh baby. The ship set ground on the shore of this uncharted desert isle with Gilligan the Skipper too the millionaire and his wife. Believe it or not I'm walking on air. I never thought I could feel so free. Flying away on a wing and a prayer. Who could it be? Believe it or not its just me. Their house is a museum where people come to see ‘em. They really are a scream the Addams Family. And if you threw a party - invited everyone you knew. You would see the biggest gift would be from me and the card attached would say thank you for being a friend?\" Goodbye gray sky hello blue. There's nothing can hold me when I hold you. Feels so right it cant be wrong. Rockin' and rollin' all week long.");
     $users = User::get();
     // Loop through our users
     foreach ($users as $user) {
         // Loop through things to be rated
         foreach ($toComment as $item) {
             $title = $titles[rand(0, sizeof($titles) - 1)];
             $comment = $comments[rand(0, sizeof($comments) - 1)];
             Comment::create(array('user_id' => $user->id, 'item_id' => $item['item']->id, 'item_type' => $item['type'], 'title' => $title, 'content' => $comment));
         }
     }
 }
<?php

require_once "models/DB.php";
require_once "models/Enemy.php";
//Bonus Question
session_start();
if (isset($_SESSION['doomed'])) {
    $_SESSION['doomed'] = $_SESSION['doomed'] + 1;
} else {
    $_SESSION['deleted'] = 1;
}
//Question 4
if (isset($_GET['id'])) {
    $id = $_GET['id'];
    $doom = Enemy::find($id, $dbh);
    $doom->delete($dbh);
} else {
    # no id to delete, failed!
    echo json_encode(array('status' => 'fail'));
}
 public function run()
 {
     DB::table('episodes')->delete();
     DB::table('doctor_episode')->delete();
     DB::table('companion_episode')->delete();
     DB::table('enemy_episode')->delete();
     // Pull up doctors, companions, and enemies to attach to episodes
     $doctorNine = Doctor::where('number', 9)->first();
     $doctorTen = Doctor::where('number', 10)->first();
     $doctorEleven = Doctor::where('number', 11)->first();
     $doctorTwelve = Doctor::where('number', 12)->first();
     $cybermen = Enemy::where('name', 'Cybermen')->first();
     $daleks = Enemy::where('name', 'Daleks')->first();
     $sontarans = Enemy::where('name', 'Sontarans')->first();
     $silence = Enemy::where('name', 'The Silence')->first();
     $angels = Enemy::where('name', 'Weeping Angels')->first();
     $amy = Companion::where('name', 'Amy Pond')->first();
     $jack = Companion::where('name', 'Captain Jack')->first();
     $clara = Companion::where('name', 'Clara Oswald')->first();
     $donna = Companion::where('name', 'Donna Noble')->first();
     $martha = Companion::where('name', 'Martha Jones')->first();
     $mickey = Companion::where('name', 'Mickey Smith')->first();
     $river = Companion::where('name', 'River Song')->first();
     $rory = Companion::where('name', 'Rory Williams')->first();
     $rose = Companion::where('name', 'Rose Tyler')->first();
     $wilfred = Companion::where('name', 'Wilfred Mott')->first();
     $episode = Episode::create(array('season' => 1, 'episode' => 1, 'name' => 'Rose', 'image' => 'http://thedoctor.coderfaire/assets/img/episodes/1.1.jpg', 'description' => 'Rose Tyler believes she is living another day of her "ordinary" life, but after being threatened by Autons (living plastic) controlled by the Nestene Consciousness, she meets the Ninth Doctor.'));
     $episode->doctors()->attach([$doctorNine->id]);
     $episode->companions()->attach([$rose->id, $mickey->id]);
     $episode = Episode::create(array('season' => 1, 'episode' => 6, 'name' => 'Dalek', 'image' => 'http://thedoctor.coderfaire/assets/img/episodes/1.6.jpg', 'description' => 'The Ninth Doctor and Rose Tyler arrive in 2012 to answer a distress signal and meet a collector of alien artefacts who has one living specimen. However, the Doctor is horrified to find out that the creature is a member of a race he thought was destroyed: a Dalek.'));
     $episode->doctors()->attach([$doctorNine->id]);
     $episode->companions()->attach([$rose->id]);
     $episode->enemies()->attach([$daleks->id]);
     $episode = Episode::create(array('season' => 1, 'episode' => 10, 'name' => 'The Doctor Dances', 'image' => 'http://thedoctor.coderfaire/assets/img/episodes/1.10.jpg', 'description' => 'The Child\'s plague is spreading throughout wartime London, and its zombie army is on the march. The Ninth Doctor and Rose form an alliance with intergalactic con man Captain Jack, but find themselves trapped in the abandoned hospital. They head to the crash site of Jack\'s supposed space junk and discover the ground zero for the mysterious plague.'));
     $episode->doctors()->attach([$doctorNine->id]);
     $episode->companions()->attach([$rose->id, $jack->id]);
     $episode = Episode::create(array('season' => 1, 'episode' => 12, 'name' => 'Bad Wolf', 'image' => 'http://thedoctor.coderfaire/assets/img/episodes/1.12.jpg', 'description' => 'Separated and with no TARDIS, the Ninth Doctor, Rose, and Jack have to fight for their lives on board the Game Station, but a far more dangerous threat is lurking, just out of sight. The Doctor realises that the entire human race has been blinded to the threat on its doorstep, and Armageddon is fast approaching.'));
     $episode->doctors()->attach([$doctorNine->id]);
     $episode->companions()->attach([$rose->id, $mickey->id, $jack->id]);
     $episode->enemies()->attach([$daleks->id]);
     $episode = Episode::create(array('season' => 2, 'episode' => 5, 'name' => 'Rise of the Cybermen', 'image' => 'http://thedoctor.coderfaire/assets/img/episodes/2.5.jpg', 'description' => 'On a parallel Earth, a deadly new version of the Doctor\'s old enemy is about to be reborn.'));
     $episode->doctors()->attach([$doctorTen->id]);
     $episode->companions()->attach([$rose->id, $mickey->id]);
     $episode->enemies()->attach([$cybermen->id]);
     $episode = Episode::create(array('season' => 2, 'episode' => 12, 'name' => 'Army of Ghosts', 'image' => 'http://thedoctor.coderfaire/assets/img/episodes/2.12.jpg', 'description' => 'Rose and the Tenth Doctor return to modern-day London to find a mysterious epidemic of ghosts all over the world. As the Doctor searches Torchwood Tower to find answers, something sinister lurks in the building.'));
     $episode->doctors()->attach([$doctorTen->id]);
     $episode->companions()->attach([$rose->id, $mickey->id]);
     $episode->enemies()->attach([$daleks->id, $cybermen->id]);
     $episode = Episode::create(array('season' => 3, 'episode' => 9, 'name' => 'The Family of Blood', 'image' => 'http://thedoctor.coderfaire/assets/img/episodes/3.9.jpg', 'description' => '1913, and war comes to England a year early as the terrifying Family hunt for the Tenth Doctor.'));
     $episode->doctors()->attach([$doctorTen->id]);
     $episode->companions()->attach([$martha->id]);
     $episode = Episode::create(array('season' => 3, 'episode' => 10, 'name' => 'Blink', 'image' => 'http://thedoctor.coderfaire/assets/img/episodes/3.10.jpg', 'description' => 'In an abandoned house, the Weeping Angels wait. The only hope to stop them is a young woman named Sally Sparrow and her friend Larry Nightingale. The only catch: The Weeping Angels can move in the blink of an eye. To defeat the ruthless enemy — with only a half of a conversation from the Tenth Doctor as help — the one rule is this: don\'t turn your back, don\'t look away and don\'t blink!'));
     $episode->doctors()->attach([$doctorTen->id]);
     $episode->companions()->attach([$martha->id]);
     $episode->enemies()->attach([$angels->id]);
     $episode = Episode::create(array('season' => 4, 'episode' => 4, 'name' => 'The Sontaran Stratagem', 'image' => 'http://thedoctor.coderfaire/assets/img/episodes/4.4.png', 'description' => 'Fifty-two people across the world in eleven different time zones die at the exact same time. The only connection: they all have ATMOS installed in their vehicles. Martha Jones, now a UNIT medic, summons the Tenth Doctor back to modern-day Earth to help figure out why, but an old enemy lies in wait...'));
     $episode->doctors()->attach([$doctorTen->id]);
     $episode->companions()->attach([$martha->id, $donna->id]);
     $episode->enemies()->attach([$sontarans->id]);
     $episode = Episode::create(array('season' => 4, 'episode' => 13, 'name' => 'Journey\'s End', 'image' => 'http://thedoctor.coderfaire/assets/img/episodes/4.13.jpg', 'description' => 'All hell has broken loose! Davros and the New Dalek Empire prepare to detonate a bomb that will wipe out all of existence. The Tenth Doctor is helpless, and the TARDIS faces destruction. The only hope lies with the Doctor\'s companions — the "Children of Time" — but Dalek Caan predicts that one will die...'));
     $episode->doctors()->attach([$doctorTen->id]);
     $episode->companions()->attach([$rose->id, $donna->id, $martha->id, $jack->id, $mickey->id, $wilfred->id]);
     $episode->enemies()->attach([$daleks->id]);
     $episode = Episode::create(array('season' => 5, 'episode' => 3, 'name' => 'Victory of the Daleks', 'image' => 'http://thedoctor.coderfaire/assets/img/episodes/5.3.jpg', 'description' => 'Receiving a call for help from his old friend Winston Churchill, the Eleventh Doctor and Amy Pond head for World War II to assist the Prime Minister. Once there, though, the Doctor reunites with his greatest enemies, the scum of the universe — the Daleks. But why are these survivors of the Medusa Cascade War passing themselves off as man-made weapons? And why don\'t they recognise the Doctor? What could these "Ironsides" have planned?'));
     $episode->doctors()->attach([$doctorEleven->id]);
     $episode->companions()->attach([$amy->id]);
     $episode->enemies()->attach([$daleks->id]);
     $episode = Episode::create(array('season' => 5, 'episode' => 4, 'name' => 'The Time of Angels', 'image' => 'http://thedoctor.coderfaire/assets/img/episodes/5.4.jpg', 'description' => 'The enigmatic River Song hurtles back into the Eleventh Doctor\'s life, but she\'s not the only familiar face returning — the Weeping Angels are back! Following River\'s calling card, the Doctor is recruited to help track down the last of the Angels, which has escaped from the Byzantium starliner and into the terrifying Maze of the Dead.'));
     $episode->doctors()->attach([$doctorEleven->id]);
     $episode->companions()->attach([$amy->id, $river->id]);
     $episode->enemies()->attach([$angels->id]);
     $episode = Episode::create(array('season' => 5, 'episode' => 12, 'name' => 'The Pandorica Opens', 'image' => 'http://thedoctor.coderfaire/assets/img/episodes/5.12.jpg', 'description' => 'A Van Gogh painting ferried across thousands of years offering a terrifying prophecy, a message on the oldest cliff-face in the universe and a love that lasts a thousand years: in 102 AD England, Romans receive a surprise visit from Cleopatra. Nearby, Stonehenge hides a legendary prison-box. As it slowly unlocks from the inside, terrible forces gather in the heavens. The fates are closing around the TARDIS. The Pandorica, which contains the most dangerous threat in the Universe, is opening. Only one thing is certain: "The Pandorica will open... Silence will fall".'));
     $episode->doctors()->attach([$doctorEleven->id]);
     $episode->companions()->attach([$amy->id, $rory->id, $river->id]);
     $episode->enemies()->attach([$silence->id]);
     $episode = Episode::create(array('season' => 6, 'episode' => 1, 'name' => 'The Impossible Astronaut', 'image' => 'http://thedoctor.coderfaire/assets/img/episodes/6.1.jpg', 'description' => 'Amy Pond, Rory Williams, River Song and the Eleventh Doctor receive a mysterious summons that takes them on an adventure to 21st century Utah and Florida in 1969. Along the way they meet Richard Nixon, president of the United States of America, and former FBI agent Canton Delaware.'));
     $episode->doctors()->attach([$doctorEleven->id]);
     $episode->companions()->attach([$amy->id, $rory->id, $river->id]);
     $episode->enemies()->attach([$silence->id]);
     $episode = Episode::create(array('season' => 6, 'episode' => 10, 'name' => 'The Girl Who Waited', 'image' => 'http://thedoctor.coderfaire/assets/img/episodes/6.10.jpg', 'description' => 'The Eleventh Doctor, Rory Williams and Amy Pond land on Apalapucia in the middle of a plague. Amy is left behind, and the Doctor and Rory must save her...but time for Amy is running at a different speed.'));
     $episode->doctors()->attach([$doctorEleven->id]);
     $episode->companions()->attach([$amy->id, $rory->id]);
     $episode = Episode::create(array('season' => 6, 'episode' => 13, 'name' => 'The Wedding of River Song', 'image' => 'http://thedoctor.coderfaire/assets/img/episodes/6.13.jpg', 'description' => 'The Eleventh Doctor is prepared to meet his death at Lake Silencio. However, all of history is happening at once. What is happening and who is responsible?'));
     $episode->doctors()->attach([$doctorEleven->id]);
     $episode->companions()->attach([$amy->id, $rory->id, $river->id]);
     $episode->enemies()->attach([$silence->id]);
     $episode = Episode::create(array('season' => 7, 'episode' => 5, 'name' => 'The Angels Take Manhattan', 'image' => 'http://thedoctor.coderfaire/assets/img/episodes/7.5.jpg', 'description' => 'A simple trip to 2012 New York goes horribly wrong when the Eleventh Doctor\'s companion, Rory Williams, is sent back to the 1930s by the Weeping Angels. There, he finds that his daughter, River Song, is investigating the Angels, as Manhattan has become their hunting grounds. The Doctor and Amy Pond must find Rory before it is too late, but they soon find that not every point in time can be changed. And here, the Doctor must face the one thing he has been dreading — a final farewell to the Ponds.'));
     $episode->doctors()->attach([$doctorEleven->id]);
     $episode->companions()->attach([$amy->id, $rory->id, $river->id]);
     $episode->enemies()->attach([$angels->id]);
     $episode = Episode::create(array('season' => 7, 'episode' => 12, 'name' => 'Nightmare in Silver', 'image' => 'http://thedoctor.coderfaire/assets/img/episodes/7.12.jpg', 'description' => 'The Eleventh Doctor takes his companion, Clara Oswald, and her wards, Angie and Artie, to the biggest amusement park, Hedgewick\'s World of Wonders. The theme park is empty, occupied by a "punishment platoon" and a lone impresario with empty Cyberman shells as exhibits. The Doctor decides to stay a while, however, to investigate strange insect creatures that are roaming the park. But these insects are really machines seeking to convert the life forms on Hedgewick\'s World into the newest generation of the ever-upgrading menace...'));
     $episode->doctors()->attach([$doctorEleven->id]);
     $episode->companions()->attach([$clara->id]);
     $episode->enemies()->attach([$cybermen->id]);
     $episode = Episode::create(array('season' => 8, 'episode' => 2, 'name' => 'Into the Dalek', 'image' => 'http://thedoctor.coderfaire/assets/img/episodes/8.2.jpg', 'description' => 'Surrounded by his greatest enemies, the newest Doctor will journey into the most dangerous place in all of the universe. With the limits of his compassion being tested, the Doctor will be forced to ask a question about himself that he doesn\'t know: "Am I a good man?"'));
     $episode->doctors()->attach([$doctorTwelve->id]);
     $episode->companions()->attach([$clara->id]);
     $episode->enemies()->attach([$daleks->id]);
 }
    {
        if (!isset(self::$_INSTANCES[get_called_class()]) || !self::$_INSTANCES[get_called_class()] instanceof static) {
            self::$_INSTANCES[get_called_class()] = new static();
        }
        return self::$_INSTANCES[get_called_class()];
    }
    private function __clone()
    {
        throw new Exception('clone error');
    }
}
class Player extends SingletonBase
{
    private $_user_id = null;
    protected function _init()
    {
        $this->_user_id = 19999;
    }
}
class Enemy extends SingletonBase
{
    private $_enemy_id = null;
    protected function _init()
    {
        $this->_enemy_id = 29999;
    }
}
$player = Player::getInstance();
$enemy = Enemy::getInstance();
var_dump($player);
var_dump($enemy);
<?php

require_once "models/DB.php";
require_once "models/Enemy.php";
$add_enemy = new Enemy();
if ($_POST) {
    $add_enemy->copyFromRow($_POST);
    if ($add_enemy->validate()) {
        $add_enemy->save($dbh);
        # success! try a redirect to reset the URL
        header('Location: TheList.php');
        die;
    }
}
# if failed, include main controller to show list again
include_once "TheList.php";
<?php

require_once "models/DB.php";
require_once "models/Enemy.php";
session_start();
if (isset($_SESSION['doomed'])) {
    $doomed = $_SESSION['doomed'];
} else {
    $_SESSION['deleted'] = 0;
    $doomed = $_SESSION['deleted'];
}
$enemies = Enemy::findAll($dbh);
include_once "views/thelist.php";
Exemple #12
0
 public function position($pos)
 {
     $enemies = Enemy::all();
 }
<?php

# set up empty object if necessary, so error display code below can expect it
if (!isset($add_enemy)) {
    $add_enemy = new Enemy();
}
?>
<html>

<?php 
require_once dirname(__FILE__) . '/../TheList.php';
?>

<head>
	<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
	<link rel="stylesheet" href="views/main.css">
</head>

<body>

<div class="container">

<div class="page-header">
	<h1>The List</h1>
</div>

<p id="doomed"><?php 
echo $doomed;
?>
 have been deleted!</p>