Beispiel #1
0
 /**
  * Execute the command.
  *
  * @return void
  */
 public function handle()
 {
     \Log::info('[' . $this->job->getJobId() . ':' . $this->attempts() . '] Category assignment started.');
     $category = Category::find($this->cat_id);
     $projects = Project::all();
     foreach ($projects as $project) {
         $project->assignCategory($category);
     }
     \Log::info('[' . $this->job->getJobId() . ':' . $this->attempts() . '] Category assignment completed.');
 }
Beispiel #2
0
 public function showMap()
 {
     $projects = \DB::table('projects')->take(10)->get();
     $projects_all = Project::select('id', 'geo_lat', 'geo_lng')->hasGeo()->get();
     $categories = Category::geocoded();
     foreach ($categories as $key => $category) {
         $pivot = \DB::table('project_category')->where('category_id', $category->id)->lists('project_id');
         $categories[$key] = array_add($categories[$key], 'projects_pivot', $pivot);
     }
     $data = compact('projects', 'projects_all', 'categories');
     return view('home.map', $data);
 }
Beispiel #3
0
 static function geocoded()
 {
     $sel_cols_projects = array('projects.id', 'projects.data_id', 'projects.title', 'projects.description', 'projects.geo_type', 'projects.geo_address', 'projects.geo_lat', 'projects.geo_lng', 'projects.status');
     $sel_cols_geocodes = array('geocodes.lat', 'geocodes.lng', 'geocodes.status as geo_status');
     $projects_lat_lng = \DB::table('projects')->where('geo_type', 'lat_lng')->select($sel_cols_projects)->get();
     $projects_address = \DB::table('projects')->join('geocodes', 'projects.geo_address', '=', 'geocodes.address')->where('projects.geo_type', '=', 'address')->select(array_merge($sel_cols_projects, $sel_cols_geocodes))->get();
     $projects = array_merge($projects_lat_lng, $projects_address);
     $projects_id = array();
     foreach ($projects as $project) {
         array_push($projects_id, $project->id);
     }
     $projects_categories = \DB::table('project_category')->whereIn('project_id', $projects_id)->select('category_id')->distinct()->get();
     $category_ids = array();
     foreach ($projects_categories as $projects_category) {
         array_push($category_ids, $projects_category->category_id);
     }
     if (count($category_ids) == 0) {
         return null;
     }
     $categories = Category::whereIn('id', $category_ids)->get();
     return $categories;
 }
Beispiel #4
0
 function setProjects($csv, $ds_sync)
 {
     $cols = $this->columns;
     // String Keys
     $config = $this->config;
     // Integer position
     $categories = Category::all();
     foreach ($csv as $row) {
         $project = Project::firstOrCreate(array('data_id' => $row[$cols[$config->id->col]]));
         $project->datasource_id = $this->id;
         $project->data_source_sync_id = $ds_sync->id;
         $project->title = $row[$cols[$config->title->col]];
         $project->description = $row[$cols[$config->desc->col]];
         if ($config->geo->type == 'address') {
             $project->geo_type = 'address';
             $project->geo_address = $row[$cols[$config->geo->address->col]];
         }
         if ($config->geo->type == 'lat_lng') {
             $project->geo_type = 'lat_lng';
             $project->geo_lat = $row[$cols[$config->geo->lat_lng->lat->col]];
             $project->geo_lng = $row[$cols[$config->geo->lat_lng->lng->col]];
         }
         $project->status = $row[$cols[$config->status->col]];
         $project->data = $row;
         foreach ($categories as $category) {
             $project->assignCategory($category);
         }
         $project->save();
     }
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int $id
  *
  * @return Response
  */
 public function destroy($id)
 {
     Category::find($id)->delete();
     return response()->json(array('error' => false, 'message' => 'Category deleted.'), 200);
 }
 public function showCategories()
 {
     $categories = Category::all();
     $data = array('categories' => $categories);
     return view('dashboard.categories', $data);
 }