/**
  * @inheritdoc
  */
 public function handle($arguments)
 {
     if (!Cache::has('site-' . $arguments)) {
         $this->replyWithMessage("Não foi encontrado nenhum site com esse argumento.");
         return;
     }
     $site = Cache::get('site-' . $arguments);
     // Validate if the URL isn't on the database yet
     if (Site::where('url', '=', $site)->first() != null) {
         $this->replyWithMessage("O site {$site} já se encontra na base de dados.");
         return;
     }
     $site_obj = new Site();
     $site_obj->url = $site;
     $site_obj->save();
     $this->replyWithMessage($site . " foi adicionado à base de dados.", true);
     // Notify the sitesbloqueados.pt about the new site
     $url = 'https://sitesbloqueados.pt/wp-json/ahoy/refresh';
     $cmd = "curl -X GET -H 'Content-Type: application/json'";
     $cmd .= " " . "'" . $url . "'";
     $cmd .= " > /dev/null 2>&1 &";
     exec($cmd, $output);
     // Flush the PAC cache
     Cache::tags(['generate_pac'])->flush();
     // Remove the cache
     Cache::forget('site-' . $arguments);
     Cache::forget('site-list');
 }
Exemple #2
0
 /**
  * Define the application's command schedule.
  *
  * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
  * @return void
  */
 protected function schedule(Schedule $schedule)
 {
     // :00 :20 :40 Ping all the update URLs for site/variable
     // Limit to Red Butte sites
     $siteCodeContains = ['RB_'];
     // $siteCodeContains = ['RB_', 'PR_', 'LR_'];
     try {
         foreach ($siteCodeContains as $piece) {
             $sites = Site::where('sitecode', 'LIKE', '%' . $piece . '%')->get();
             foreach ($sites as $site) {
                 $series = DB::table('series')->select('variablecode')->where('sitecode', '=', $site->sitecode)->get();
                 foreach ($series as $s) {
                     $sitecode = $site->sitecode;
                     $variablecode = $s->variablecode;
                     $url = url('/sites/' . $site->sitecode . '/' . $s->variablecode . '/update');
                     $schedule->exec("wget -O/dev/null {$url}")->cron('0,20,40 * * * *');
                 }
             }
         }
     } catch (\Exception $ex) {
         // Ignore all exceptions... this will catch if 'php artisan migration' hasn't been done yet
     }
     // :10 :30 :50 Ping the update URLs for cameras
     $url = url('/cameras/update');
     $schedule->exec("wget -O/dev/null {$url}")->cron('10,30,50 * * * *');
 }
 public function getTag($tagName = null)
 {
     // 该用户下所有标签
     $tags = Tag::where('user_id', '=', Auth::id())->get();
     // 没有数据返回空页面
     if (count($tags) == 0) {
         return view('site.empty');
     }
     // 标签名
     $tagName = isset($tagName) ? $tagName : $tags[0]->name;
     // 标签ID
     $tid = Tag::where('user_id', '=', Auth::id())->whereName($tagName)->first()->id;
     // 标签下所有站点
     $sites = Site::where('tag_id', '=', $tid)->orderBy('created_at', 'desc')->get();
     // 获取标签下站点总数
     for ($i = 0; $i < count($tags); $i++) {
         $tags[$i]->count = Tag::find($tags[$i]->id)->sites->count();
     }
     // 将关键词以逗号进行分割
     for ($i = 0; $i < count($sites); $i++) {
         if (isset($sites[$i]->keywords)) {
             $sites[$i]->keywords = explode(',', $sites[$i]->keywords);
         }
     }
     // 返回试图
     return view('site.show', compact('tags', 'sites', 'tid'));
 }
Exemple #4
0
 public function index()
 {
     $events = \App\Event::get();
     $sliders = \App\Slider::get();
     $services = \App\Service::get();
     $site = \App\Site::where('active', '1')->firstOrFail();
     return view('pages.index', ['events' => $events, 'sliders' => $sliders, 'services' => $services, 'site' => $site]);
 }
Exemple #5
0
 public function app()
 {
     // Get RB sites that are not USGS
     // (USGS now removed in DataController sitesUpdate)
     $sites = Site::where('sitecode', 'LIKE', '%RB_%')->get();
     foreach ($sites as $site) {
         $site->series = Series::where('sitecode', '=', $site->sitecode)->get();
     }
     return view('pages.rbc', compact('sites'));
 }
Exemple #6
0
 /**
  * Find a site based on province, city and slug input
  *
  * @param string $province
  * @param string $city
  * @param string $slug
  *
  * @return mixed
  */
 public function findByProvinceCity($province, $city, $slug)
 {
     $p = new Province();
     $province = $p->where('slug', $province)->first();
     $c = new City();
     $city = $c->where(['province_id' => $province->id, 'slug' => $city])->first();
     $s = new Site();
     $site = $s->where(['city_id' => $city->id, 'slug' => $slug])->first();
     return $site;
 }
Exemple #7
0
 public function statitics()
 {
     $sites = Site::all();
     $cats = Category::all();
     $districts = District::all();
     $cats_total = 0;
     foreach ($cats as $cat_id => $cat_name) {
         $cats_total += Site::where('cat_id', '=', $cat_id)->count();
     }
     return view('pages.statitics', compact(['sites', 'cats', 'districts', 'cats_total']));
 }
 public function edit(Request $request)
 {
     $site = Site::where('idSite', $request->input('idSite'))->get()->first();
     $site->nomSite = $request->input('nomSite');
     $site->adr1Site = $request->input('adr1Site');
     $site->adr2Site = $request->input('adr2Site');
     $site->idUniv = $request->input('idUniv');
     $site->inseeVille = $request->input('inseeVille');
     $site->save();
     return redirect()->route('backsite');
 }
 /**
  * Display search
  *
  * @return Response
  */
 public function search(Request $request)
 {
     $id = $request->input('id');
     $site_id = 0;
     $trade_id = 0;
     if (Site::where('code', 'LIKE', '%' . $id . '%')->orWhere('name', 'LIKE', '%' . $id . '%')->first() != null) {
         $site_id = Site::where('code', 'LIKE', '%' . $id . '%')->orWhere('name', 'LIKE', '%' . $id . '%')->first()->id;
     }
     if (Trade::where('name', 'LIKE', '%' . $id . '%')->first() != null) {
         $trade_id = Trade::where('name', 'LIKE', '%' . $id . '%')->first()->id;
     }
     $labors = Labor::where('employee_no', '=', $id)->orWhere('name', 'LIKE', '%' . $id . '%')->orWhere('site_id', '=', $site_id)->orWhere('trade_id', '=', $trade_id)->where('deleted', '=', 'false')->paginate(20);
     //dd($labors->toArray()['total']);
     return view('pages.index_labor', compact('labors'));
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     // Retrieve the path
     $csv_path = $this->argument('csv');
     $file = file($csv_path);
     $dry_run = $this->option('dry');
     $domains = array_map('str_getcsv', $file);
     if ($dry_run) {
         $this->warn('Running on dry-mode');
     }
     $success = 0;
     foreach ($domains as $domain) {
         // Set the time
         $date = strtotime($domain[1]);
         if ($date === false) {
             $date = time();
         }
         $date = date('Y-m-d H:i:s', $date);
         // Set the domain
         $domain = strtolower($domain[0]);
         // Domain already exists, skip.
         if (Site::where('url', '=', $domain)->first() != null) {
             $this->error(" * " . $domain . " already exists. Skipping.");
             continue;
         }
         $new_site = new Site();
         $new_site->url = $domain;
         $new_site->setCreatedAt($date);
         if ($dry_run) {
             $this->info(" * Should add " . $domain . " at " . $date . ".");
         } else {
             $this->info(" * Added add " . $domain . " at " . $date . ".");
             $new_site->save();
         }
         $success++;
     }
     $this->info("\nDone! Added {$success} new sites");
 }
Exemple #11
0
 private function sites($like)
 {
     $sites = Site::where('sitecode', 'LIKE', "%{$like}%")->get();
     $cameras = Cameras::sites();
     foreach ($sites as $site) {
         // Cleanup site name
         $remove = [' Basic Aquatic', ' Advanced Aquatic', 'Provo River at ', 'Provo River near ', 'Provo River Below ', 'Logan River at ', 'Logan River near '];
         foreach ($remove as $r) {
             $site['sitename'] = str_replace($r, '', $site['sitename']);
         }
         // Convert Lat/Lon to float
         $site['latitude'] = floatval($site['latitude']);
         $site['longitude'] = floatval($site['longitude']);
         // Check to see if site has a camera
         $site['camera'] = false;
         if (in_array($site['sitecode'], $cameras)) {
             $site['camera'] = true;
         }
         // Append array of series at site
         $series = [];
         foreach (DB::table('series')->select('variablecode')->where('sitecode', '=', $site->sitecode)->get() as $var) {
             $series[] = $var->variablecode;
         }
         $site->series = $series;
     }
     return $sites;
 }
Exemple #12
0
 public function sitesUpdate()
 {
     echo "<pre>";
     // Limit the types of sites and variables loaded
     // change these to load more or less
     // Only interested in GAMUT sites
     // ( Issues exist with USGS duplicates that break unique constraints if those sites are included )
     $siteCodeContains = ['RB_', 'PR_', 'LR_'];
     // Revised to focus on suffix
     $siteCodeContains = ['_BA', '_AA'];
     // Only interested in Stream data
     $siteTypes = ['Stream'];
     // Only interested in common variables
     $variableLevels = ['Common'];
     // Only interested in RAW data
     // Can't rely on QC data
     $qualityControlLevelCodes = [0];
     // Get sites
     $siteKeys = ['network' => '', 'sitecode' => '', 'sitename' => '', 'latitude' => '', 'longitude' => ''];
     $sitesJSON = file_get_contents("http://data.iutahepscor.org/tsa/api/v1/sites/?limit=0");
     $sites = json_decode($sitesJSON);
     // Process sites into database
     foreach ($sites->objects as $site) {
         // Only add desiered site types
         if (in_array($site->sitetype, $siteTypes)) {
             // Only add desired sitecodes
             foreach ($siteCodeContains as $piece) {
                 if (strpos($site->sitecode, $piece) !== false) {
                     // Clean up array
                     $site = (array) $site;
                     $site = array_intersect_key($site, $siteKeys);
                     // Add
                     try {
                         Site::firstOrCreate((array) $site);
                         break;
                     } catch (Exception $e) {
                         // Didn't add to DB because of conflict, ignore...
                     }
                 }
             }
         }
     }
     // Get series
     $seriesKeys = ['sitecode' => '', 'variablecode' => '', 'getdataurl' => ''];
     $variableKeys = ['variablecode' => '', 'variablename' => '', 'variableunitsname' => '', 'variableunitsabbreviation' => ''];
     $seriesJSON = file_get_contents("http://data.iutahepscor.org/tsa/api/v1/dataseries/?limit=0");
     $series = json_decode($seriesJSON);
     // Process series into database
     foreach ($series->objects as $s) {
         // Only add series if site was added
         if (!Site::where(['sitecode' => $s->sitecode])->get()->isempty()) {
             // Only add desired variables
             if (in_array($s->variablelevel, $variableLevels) && in_array($s->qualitycontrollevelcode, $qualityControlLevelCodes)) {
                 // Strip down arrays for insert
                 $s = (array) $s;
                 $v = array_intersect_key($s, $variableKeys);
                 $s = array_intersect_key($s, $seriesKeys);
                 // Add Series
                 try {
                     Series::firstOrCreate($s);
                 } catch (Exception $e) {
                     // Series already exists
                 }
                 // Add Variable
                 try {
                     Variable::firstOrCreate($v);
                 } catch (Exception $e) {
                     // Variable already exists, this will catch a lot!
                 }
             }
         }
     }
     // Redirect to sites list
     return redirect()->action('DataController@sites');
 }
 /**
  * Display list of labors under the signed in user
  *
  * @return Response
  */
 public function showSearch($site)
 {
     if (!$this->siteIsLocked($site)) {
         $labors = Site::where('code', $site)->first()->labor()->get();
         session()->put('site', $site);
         return view('pages.add_attendance', compact('labors', 'site'));
     } else {
         flash()->error('Attendance for this site has been already submitted.');
         return redirect('attendance/list');
     }
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $site = Site::where('code', '=', $id)->first();
     if ($site == null) {
         return redirect('sites');
     }
     $site->delete();
     return redirect('sites');
 }
 public function getForceDestroy($id)
 {
     DB::transaction(function () use($id) {
         Tag::destroy($id);
         Site::where('tag_id', '=', $id)->delete();
     });
 }
Exemple #16
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function nemonico()
 {
     $req = Request::all();
     $o = $req['name_startsWith'];
     $data = Site::where('nemonico', 'LIKE', '%' . $o . '%')->get();
     return $data;
 }