public function getCommuneStatistics() { $communes = User::notAdmins()->select('commune', 'type', \DB::raw('COUNT(*) as total'))->groupBy('commune', 'type')->orderBy('commune', 'asc')->get()->groupBy('commune'); $stat = ['content' => [['label' => 'Número de tenderos', 'data' => []], ['label' => 'Número de productores', 'data' => []]], 'names' => []]; $count = 0; foreach ($communes as $commune => $types) { foreach ($types as $type) { if ($type->type == 'shopkeeper') { array_push($stat['content'][0]['data'], [$count + 1, $type->total]); } else { array_push($stat['content'][1]['data'], [$count + 2, $type->total]); } } if ($types->count() < 2) { if ($types->first()->type == 'producer') { array_push($stat['content'][0]['data'], [$count + 1, 1]); } else { array_push($stat['content'][1]['data'], [$count + 2, 1]); } } if ($commune > 0) { array_push($stat['names'], [$count + 2, 'Comuna ' . $commune]); } else { array_push($stat['names'], [$count + 2, 'Fuera de Villavicencio']); } $count += 2.5; } return $stat; }
/** * Display a listing of the resource. * * @return Response */ public function index() { $producers = User::notAdmins()->orderBy('name')->paginate(20); $this->form_data = ['route' => self::$prefixRoute . 'store', 'method' => 'POST']; return $this->getFormView('lists', ['producers' => $producers]); }