示例#1
0
 public function showSubscriptions()
 {
     if (\Auth::user()->role_id == 1) {
         $subscriptions = Subscription::withTrashed()->paginate(10);
     } else {
         $subscriptions = User::find(\Auth::id())->subscriptions()->withTrashed()->paginate(10);
     }
     $data = compact('subscriptions');
     return view('dashboard.subscriptions', $data);
 }
示例#2
0
 /**
  * STATUS CODE
  * -----------
  * 0: Created
  * 1: Confirmed
  * 2: Suspended
  * 3: Deleted
  */
 public static function boot()
 {
     parent::boot();
     // Setup event bindings...
     Subscription::created(function ($subscription) {
         $user = $subscription->user;
         $project_id = $subscription->project_id;
         $confirm_url = secure_url('subscriptions/' . $subscription->confirm_token);
         if ($subscription->project_id == 0) {
             $map_image_link = 'https://api.tiles.mapbox.com/v4/codeforafrica.ji193j10' . '/geojson(' . urlencode($subscription->geojson) . ')' . '/auto/600x250.png?' . 'access_token=pk.eyJ1IjoiY29kZWZvcmFmcmljYSIsImEiOiJVLXZVVUtnIn0.JjVvqHKBGQTNpuDMJtZ8Qg';
         } else {
             $map_image_link = 'http://api.tiles.mapbox.com/v4/codeforafrica.ji193j10/' . $subscription->geojson . '/600x250.png256?' . 'access_token=pk.eyJ1IjoiY29kZWZvcmFmcmljYSIsImEiOiJVLXZVVUtnIn0.JjVvqHKBGQTNpuDMJtZ8Qg';
             $project_title = $subscription->project->title;
         }
         $data = compact('subscription', 'user', 'project_id', 'project_title', 'map_image_link', 'confirm_url');
         \Mail::queue('emails.subscription.new', $data, function ($message) use($user) {
             $message->to($user->email)->subject('#GreenAlert | Confirm Subscription!');
         });
     });
 }
示例#3
0
 /**
  * Execute the command.
  *
  * @return void
  */
 public function handle()
 {
     $alert = Alert::find($this->alert_id);
     if ($alert->status != 0) {
         return;
     } else {
         $alert->status = 1;
         $alert->save();
     }
     $project = Project::find($alert->project_id);
     $project_lat = $project->geo->lat;
     $project_lng = $project->geo->lng;
     if ($project_lat != 450.0 && $project_lng != 450.0) {
         $subscriptions = Subscription::where('sw_lat', '<', $project_lat)->where('sw_lng', '<', $project_lng)->where('ne_lat', '>', $project_lat)->where('ne_lng', '>', $project_lng)->select('user_id')->distinct()->get();
         foreach ($subscriptions as $subscription) {
             $user = User::find($subscription->user_id);
             $data = compact('user', 'project');
             \Mail::queue('emails.alerts.status', $data, function ($message) use($user) {
                 $message->to($user->email, '')->subject('[#GreenAlert] You\'ve got an update');
             });
         }
     }
 }
 public function email()
 {
     // Get fisrt subscription
     $subscription = Subscription::first();
     $user = User::find($subscription->user_id);
     // Get first project
     $project = Project::first();
     $project_geo = $project->geo();
     if (strlen($project->title) > 80) {
         $project->title = substr($project->title, 0, 80) . '...';
     }
     if (strlen($project->description) > 200) {
         $project->description = substr($project->description, 0, 200) . '...';
     }
     // Check email type
     if (preg_match('/alert*/', \Input::get('type'))) {
         $view_name = 'emails.alerts.default';
         $map_image_link = 'https://api.tiles.mapbox.com/v4/codeforafrica.ji193j10' . '/pin-l-star+27AE60(' . $project_geo->lng . ',' . $project_geo->lat . ')' . '/' . $project_geo->lng . ',' . $project_geo->lat . ',11' . '/600x250.png?' . 'access_token=pk.eyJ1IjoiY29kZWZvcmFmcmljYSIsImEiOiJVLXZVVUtnIn0.JjVvqHKBGQTNpuDMJtZ8Qg';
         if (\Input::get('type') == 'alert_status') {
             $view_name = 'emails.alerts.status';
         }
         $project_title = $project->title;
         $project_id = $project->id;
     } else {
         $view_name = 'emails.subscription.new';
         $map_image_link = 'https://api.tiles.mapbox.com/v4/codeforafrica.ji193j10' . '/geojson(' . urlencode($subscription->geojson) . ')' . '/auto/600x250.png?' . 'access_token=pk.eyJ1IjoiY29kZWZvcmFmcmljYSIsImEiOiJVLXZVVUtnIn0.JjVvqHKBGQTNpuDMJtZ8Qg';
         $project_id = $subscription->project_id;
     }
     // New Subscription
     $confirm_url = secure_asset('subscriptions/' . $subscription->confirm_token);
     $data = compact('subscription', 'user', 'map_image_link', 'confirm_url', 'project_title', 'project_id');
     $view = view($view_name, $data);
     if (\Input::get('inline', 0) == 1) {
         // TODO: Make inline view
         // return Inliner::inline($view);
     }
     return $view;
 }