/** * Run the database seeds. * * @return void */ public function run() { Model::unguard(); // $this->call('UserTableSeeder'); Setting::create(['name' => 'password', 'setting' => Hash::make(env('ADMIN_PASSWORD'))]); Setting::create(['name' => 'name', 'setting' => env('NAME')]); Setting::create(['name' => 'email', 'setting' => env('ADMIN_EMAIL')]); Setting::create(['name' => 'email_period_lower_bound', 'setting' => 22]); Setting::create(['name' => 'email_period_upper_bound', 'setting' => 8]); Setting::create(['name' => 'last_email', 'setting' => 0]); Depression::create(['is_depressed' => 'no']); Model::reguard(); }
public function mainStats() { $depressions = Depression::all(); $chartData = array(); $labels = array(); $currentCount = 0; foreach ($depressions as $key => $depression) { if ($currentCount > 0 && $depression->is_depressed == 'no') { $currentCount--; } else { if ($depression->is_depressed == 'yes') { $currentCount++; } } $date = date("M j, Y, g:i a", strtotime($depression->created_at)); $labels[] = $date; $chartData[] = [strtotime($depression->created_at) * 1000, $currentCount]; // $chartData[][0] = "Date.UTC('".strtotime($depression->created_at)."')"; } $data = ['chartData' => $chartData, 'labels' => $labels]; return View::make('stats.main_chart')->with('data', $data); }
</div> <script type="text/javascript" src="https://code.jquery.com/jquery-2.1.4.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.96.1/js/materialize.min.js"></script> <script type="text/javascript" src="{{ URL::to('/') }}/js/app.js"></script> @yield('extra-js') <script type="text/javascript"> <?php $depressionStatus = !isset($depressionStatus) ? \App\Depression::orderBy('created_at', "DESC")->first()->is_depressed == 'yes' : $depressionStatus; ?> $(document).ready(function(){ @if( ($depressionStatus == 'yes') ) particlesJS.load('particles-js', 'sluggish.json', function() {}); @else particlesJS.load('particles-js', 'energetic.json', function() {}); @endif }); </script> </body> </html>
public static function sendEmail() { $lowerBound = Setting::where('name', 'email_period_lower_bound')->first()->setting; $upperBound = Setting::where('name', 'email_period_upper_bound')->first()->setting; $currentHour = (int) date('H'); $email = Setting::where('name', 'email')->first()->setting; $name = Setting::where('name', 'name')->first()->setting; $lastEmail = Setting::where('name', 'last_email')->first(); $lastEmail->setting = time(); $lastEmail->save(); $lastNumber = Depression::orderBy('created_at', "DESC")->first()->id; // Encrypt yes and no so people can't accidentally trigger a choice $yes = Crypt::encrypt("yes"); $no = Crypt::encrypt("no"); if ($currentHour <= $lowerBound && $currentHour >= $upperBound) { // Do not send emails unless they're outside the set bounds $baseUrl = URL::to('/'); Mail::send('emails.reminder', ["yes" => $yes, "no" => $no, 'baseUrl' => $baseUrl], function ($m) use($email, $name, $lastNumber) { $m->from(env('MAIL_FROM_ADDRESS'), env('MAIL_FROM_NAME')); $m->to($email, $name)->subject('Are You Depressed? (' . ($lastNumber + 1) . ')'); }); } }
<?php /* |-------------------------------------------------------------------------- | Application Routes |-------------------------------------------------------------------------- | | Here is where you can register all of the routes for an application. | It's a breeze. Simply tell Laravel the URIs it should respond to | and give it the controller to call when that URI is requested. | */ Route::get('/', 'DepressionController@areTheyDepressed'); Route::get('/admin', ['as' => 'admin', 'uses' => 'DepressionController@adminForm']); Route::post('/admin/post', ['as' => 'handleAdmin', 'uses' => 'DepressionController@handleAdmin']); Route::get('/password', ['as' => 'password', 'uses' => 'DepressionController@setPassword']); Route::get('/answer/{choice}', ['as' => 'answer', 'uses' => 'DepressionController@handleEmail']); Route::group(['prefix' => 'stats'], function () { Route::get('/', 'StatsController@mainStats'); }); Route::get('/json', function () { return response()->json(\App\Depression::orderBy('created_at', "DESC")->first()); }); Route::get('/json/all', function () { return response()->json(\App\Depression::orderBy('created_at', "DESC")->get()); }); Route::get('/yes', ['as' => 'yes', 'uses' => 'DepressionController@viewYes']); Route::get('/no', ['as' => 'no', 'uses' => 'DepressionController@viewNo']);