From ffcd75b13111a96ce16793421966ffd9c68cbdfb Mon Sep 17 00:00:00 2001 From: Aaron Parecki Date: Tue, 4 Jul 2017 12:14:53 -0700 Subject: [PATCH] bonus points for certain documents --- app/Mission.php | 14 ++++++++ .../2017_07_04_184748_flexible_doc_points.php | 32 +++++++++++++++++++ database/seeds/DocumentSeeder.php | 21 ++++++------ 3 files changed, 57 insertions(+), 10 deletions(-) create mode 100644 database/migrations/2017_07_04_184748_flexible_doc_points.php diff --git a/app/Mission.php b/app/Mission.php index 6e29f46..750a1ea 100644 --- a/app/Mission.php +++ b/app/Mission.php @@ -195,6 +195,11 @@ class Mission extends Model if($this->complete($team)) { $score = 50; + // +10 if any of their photos are tipping the bus driver + $num = Tweet::where('team_id', $team->id)->where('m5_complete', 1)->where('m5_tip', 1)->count(); + if($num > 0) + $score += 10; + return $score; } else { return 0; @@ -207,6 +212,15 @@ class Mission extends Model if($extra_docs > 0) { $score += $extra_docs * 5; } + // add bonus points for certain documents + $tweets = DB::table('tweets')->select('m7_document_id', 'm7_documents.points') + ->where('team_id', $team->id) + ->join('m7_documents', 'm7_documents.id', '=', 'tweets.m7_document_id') + ->whereNotNull('m7_document_id') + ->distinct()->get(); + foreach($tweets as $tweet) { + $score += $tweet->points; + } return $score; } else { return 0; diff --git a/database/migrations/2017_07_04_184748_flexible_doc_points.php b/database/migrations/2017_07_04_184748_flexible_doc_points.php new file mode 100644 index 0000000..944ba61 --- /dev/null +++ b/database/migrations/2017_07_04_184748_flexible_doc_points.php @@ -0,0 +1,32 @@ +integer('points'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('m7_documents', function (Blueprint $table) { + $table->removeColumn('points'); + }); + } +} diff --git a/database/seeds/DocumentSeeder.php b/database/seeds/DocumentSeeder.php index f86d573..b8ef4b0 100644 --- a/database/seeds/DocumentSeeder.php +++ b/database/seeds/DocumentSeeder.php @@ -12,17 +12,18 @@ class DocumentSeeder extends Seeder public function run() { $documents = [ - ['Fare Inspection', 'Getting the fare inspected but not by a bus driver'], - ['Employee Pass', 'Someone using their employer-provided pass to ride TriMet'], - ['Purchase at Books with Pictures', 'A receipt for a purchase at Books with Pictures'], - ['TriMet Clothing', 'A team member wearing a TriMet-branded item of clothing or gear'], - ['Biketown', 'A team member holding up their Biketown card'], - ['TriMet High-Five', 'A team member high-fiving a TriMet employee who is wearing official agency clothing'], - ['Streetcar Dancing', 'Team members dancing on the Portland Streetcar'], - ['Vintage Heavy Rail', 'Your team posing with a vintage heavy-rail train'], - ['Public Art', 'Your team posing with a piece of public art'], + ['Fare Inspection', 'Getting the fare inspected but not by a bus driver', 5], + ['Employee Pass', 'Someone using their employer-provided pass to ride TriMet', 5], + ['Purchase at Books with Pictures', 'A receipt for a purchase at Books with Pictures', 5], + ['TriMet Clothing', 'A team member wearing a TriMet-branded item of clothing or gear', 5], + ['Biketown', 'A team member holding up their Biketown card', 5], + ['TriMet High-Five', 'A team member high-fiving a TriMet employee who is wearing official agency clothing', 5], + ['Streetcar Dancing', 'Team members dancing on the Portland Streetcar', 5], + ['Vintage Heavy Rail', 'Your team posing with a vintage heavy-rail train', 5], + ['Public Art', 'Your team posing with a piece of public art', 5], + ['Airport Carpet', 'Your team posing with the PDX airpor carpet (old or new)', 20], ]; foreach($documents as $d) - DB::table('m7_documents')->insert(['name' => $d[0], 'description' => $d[1]]); + DB::table('m7_documents')->insert(['name' => $d[0], 'description' => $d[1], 'points' => $d[2]]); } }