/**
  * get the list of announcements for givin hood.
  *
  * @return json
  * @author gcg
  */
 public function getList($hood_id = null, $start = 0, $take = 25)
 {
     $hood = [];
     if (empty($hood_id) or $hood_id == 'null') {
         if (Auth::check()) {
             if (isset(Auth::user()->hood_id) and !empty(Auth::user()->hood_id)) {
                 $hood = Hood::with('district.city')->find(Auth::user()->hood_id);
                 $hood_id = $hood->id;
             }
         }
     } else {
         $hood = Hood::with('district.city')->find($hood_id);
     }
     if (empty($hood)) {
         if ($this->isApi) {
             return response()->api(404, 'No hood spesified.', []);
         }
         return redirect('/')->with('error', 'Lütfen profil ayarlarınızdan mahallenizi girip tekrar deneyin.');
     }
     $hood_id = $hood->id;
     $announcements = Announcement::with('user')->where('hood_id', $hood_id)->orderBy('id', 'desc')->skip($start)->take($take)->get();
     if ($this->isApi) {
         if ($announcements === null) {
             return response()->api(200, 'Announcements: ', []);
         }
         return response()->api(200, 'Announcements: ', $announcements->toArray());
     }
     return response()->app(200, 'announcements.list', ['announcements' => $announcements, 'hood' => $hood]);
 }
Example #2
0
 /**
  * get issues based on pagination and filters
  *
  * @return view
  * @author Me
  */
 public function getIssues($hood_id = null)
 {
     $issues = Issue::with('user', 'tags', 'images');
     $hood = null;
     if ($hood_id != 'all') {
         if (!empty($hood_id)) {
             $hood = Hood::with('district.city')->find(Auth::user()->hood_id);
             $issues->where('hood_id', $hood->id);
         }
         if (empty($hood)) {
             if (Request::has('location')) {
                 $hood = Hood::fromLocation(Request::get('location'));
                 if (isset($hood) and isset($hood->id)) {
                     $issues->where('hood_id', $hood->id);
                 }
             } else {
                 if (Auth::check()) {
                     if (isset(Auth::user()->hood_id) and !empty(Auth::user()->hood_id)) {
                         $hood = Hood::with('district.city')->find(Auth::user()->hood_id);
                         $issues->where('hood_id', $hood->id);
                     }
                 }
             }
         }
     }
     $o1 = 'id';
     $o2 = 'desc';
     if (Request::has('sort')) {
         $sort = Request::get('sort');
         if ($sort == 'popular') {
             $o1 = 'supporter_count';
         }
     }
     $issues->orderBy($o1, $o2);
     if (Request::has('map') and (int) Request::get('map') === 1) {
         $data = $issues->paginate(100);
         return $this->displayMapData($data);
     }
     if (Request::ajax()) {
         return view('partials.issues', ['issues' => $issues->paginate(20), 'hood' => $hood]);
     }
     if ($this->isApi) {
         return response()->api(200, 'Issues', $issues->toArray());
     }
     view()->share('pageTitle', 'Fikir listesi - ');
     session(['last_page' => Request::path()]);
     return response()->app(200, 'issues.list', ['issues' => $issues->paginate(20), 'hood' => $hood]);
 }