/**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $location = \Issue\Location::create(['parent_id' => 0]);
     $locationNames = ['ro' => 'Locatii', 'en' => 'Locations'];
     foreach (['ro', 'en'] as $locale) {
         $location->translateOrNew($locale)->name = $locationNames[$locale];
     }
     $location->save();
 }
 public function getExternalIssueInfo($id, $name)
 {
     $issue = Issue::findOrFail($id);
     if ($name != Str::slug($issue->name)) {
         abort(403);
     }
     $newsList = $issue->connectedNews()->orderBy('date', 'DESC')->paginate(10);
     $stakeholdersList = $issue->connectedStakeholders->chunk(10);
     $initiatorsList = $issue->connectedInitiatorsStakeholders->chunk(10);
     $dateNow = (new \DateTime())->format('Y-m-d H:i:s');
     return view('frontend.external.issue', ['issue' => $issue, 'locations' => Location::all(), 'newsList' => $newsList, 'stakeholdersList' => $stakeholdersList, 'initiatorsList' => $initiatorsList, 'dateNow' => $dateNow]);
 }
 public function queryLocation(Request $request)
 {
     $queryLocationName = $request->input('name');
     $locationIds = LocationTranslation::where('name', 'like', '%' . $queryLocationName . '%')->where('locale', \App::getLocale())->lists('location_id');
     $locations = Location::whereIn('id', $locationIds)->where('parent_id', '>', 0)->with(['translations', 'parent'])->get();
     $result = [];
     foreach ($locations as $location) {
         $result[] = ['id' => $location->id, 'name' => ($location->parent->id > 1 ? $location->parent->name . " - " : "") . $location->name];
     }
     return $result;
 }
 public function getIssueInfo($id, $name)
 {
     $issue = Issue::findOrFail($id);
     $issueDomains = $issue->connectedDomains;
     if (!$issueDomains || $issueDomains->isEmpty()) {
         abort(403);
     }
     $allowedDomains = Domain::getUserAndPublicDomains();
     $intersection = $allowedDomains->intersect($issueDomains);
     if (!$intersection || $intersection->isEmpty()) {
         abort(403);
     }
     if ($name != Str::slug($issue->name)) {
         abort(403);
     }
     $newsList = $issue->connectedNews()->orderBy('date', 'desc')->paginate(10);
     $stakeholdersList = $issue->connectedStakeholders->chunk(10);
     $initiatorsList = $issue->connectedInitiatorsStakeholders->chunk(10);
     $dateNow = (new \DateTime())->format('Y-m-d H:i:s');
     return view('frontend.pages.info-issue', ['issue' => $issue, 'domain' => $issueDomains[0]->id, 'locations' => Location::all(), 'newsList' => $newsList, 'stakeholdersList' => $stakeholdersList, 'initiatorsList' => $initiatorsList, 'dateNow' => $dateNow]);
 }
 protected function importLocations()
 {
     $location = Location::create(['parent_id' => 0]);
     $locationNames = ['ro' => 'Locatii', 'en' => 'Locations'];
     foreach (['ro', 'en'] as $locale) {
         $location->translateOrNew($locale)->name = $locationNames[$locale];
     }
     $location->save();
     $locations = DB::connection('oldissue')->select('select * from lexlocation');
     foreach ($locations as $location) {
         $newLocation = new Location();
         $newLocation->id = $location->id + 1;
         $newLocation->parent_id = $location->parentid + 1;
         $translatableData = ['ro' => ['name' => $location->name ? $location->name : ''], 'en' => ['name' => $location->enname ? $location->enname : '']];
         $newLocation->fill($translatableData);
         $newLocation->save();
     }
     return print_r('Au fost importate: ' . Location::count() . ' locatii procedurale.' . "\n");
 }