public function all()
{
$this->load->library('country');
$this->load->library('pagination');
$this->load->library('cart');
// load the cart library
$this->load->model('Image_tool_model');
$url = '?';
$filter = array();
if ($this->input->get('page')) {
$filter['page'] = (int) $this->input->get('page');
} else {
$filter['page'] = '';
}
if ($this->config->item('menus_page_limit')) {
$filter['limit'] = $this->config->item('menus_page_limit');
}
$filter['filter_status'] = '1';
$filter['order_by'] = 'ASC';
if ($this->input->get('search')) {
$filter['filter_search'] = $this->input->get('search');
$url .= 'search=' . $filter['filter_search'] . '&';
}
if ($this->input->get('sort_by')) {
$sort_by = $this->input->get('sort_by');
if ($sort_by === 'newest') {
$filter['sort_by'] = 'location_id';
$filter['order_by'] = 'DESC';
} else {
if ($sort_by === 'name') {
$filter['sort_by'] = 'location_name';
}
}
$url .= 'sort_by=' . $sort_by . '&';
}
$this->template->setBreadcrumb('<i class="fa fa-home"></i>', '/');
$this->template->setBreadcrumb($this->lang->line('text_heading'), 'local/all');
$this->template->setTitle($this->lang->line('text_heading'));
$this->template->setHeading($this->lang->line('text_heading'));
$review_totals = $this->Reviews_model->getTotalsbyId();
// retrieve all customer reviews from getMainList method in Reviews model
$data['locations'] = array();
$locations = $this->Locations_model->getList($filter);
if ($locations) {
foreach ($locations as $location) {
$this->location->setLocation($location['location_id'], FALSE);
$opening_status = $this->location->workingStatus('opening');
$delivery_status = $this->location->workingStatus('delivery');
$collection_status = $this->location->workingStatus('collection');
$delivery_time = $this->location->deliveryTime();
if ($delivery_status === 'closed') {
$delivery_time = 'closed';
} else {
if ($delivery_status === 'opening') {
$delivery_time = $this->location->workingTime('delivery', 'open');
}
}
$collection_time = $this->location->collectionTime();
if ($collection_status === 'closed') {
$collection_time = 'closed';
} else {
if ($collection_status === 'opening') {
$collection_time = $this->location->workingTime('collection', 'open');
}
}
$review_totals = isset($review_totals[$location['location_id']]) ? $review_totals[$location['location_id']] : 0;
$data['locations'][] = array('location_id' => $location['location_id'], 'location_name' => $location['location_name'], 'description' => strlen($location['description']) > 120 ? substr($location['description'], 0, 120) . '...' : $location['description'], 'address' => $this->location->getAddress(TRUE), 'total_reviews' => $review_totals, 'location_image' => $this->location->getImage(), 'is_opened' => $this->location->isOpened(), 'is_closed' => $this->location->isClosed(), 'opening_status' => $opening_status, 'delivery_status' => $delivery_status, 'collection_status' => $collection_status, 'delivery_time' => $delivery_time, 'collection_time' => $collection_time, 'opening_time' => $this->location->openingTime(), 'closing_time' => $this->location->closingTime(), 'min_total' => $this->location->minimumOrder($this->cart->total()), 'delivery_charge' => $this->location->deliveryCharge($this->cart->total()), 'has_delivery' => $this->location->hasDelivery(), 'has_collection' => $this->location->hasCollection(), 'last_order_time' => $this->location->lastOrderTime(), 'distance' => round($this->location->checkDistance()), 'distance_unit' => $this->config->item('distance_unit') === 'km' ? $this->lang->line('text_kilometers') : $this->lang->line('text_miles'), 'href' => site_url('local?location_id=' . $location['location_id']));
}
}
if (!empty($sort_by) and $sort_by === 'distance') {
$data['locations'] = sort_array($data['locations'], 'distance');
} else {
if (!empty($sort_by) and $sort_by === 'rating') {
$data['locations'] = sort_array($data['locations'], 'total_reviews');
}
}
$config['base_url'] = site_url('local/all' . $url);
$config['total_rows'] = $this->Locations_model->getCount($filter);
$config['per_page'] = $filter['limit'];
$this->pagination->initialize($config);
$data['pagination'] = array('info' => $this->pagination->create_infos(), 'links' => $this->pagination->create_links());
$this->location->initialize();
$data['locations_filter'] = $this->filter($url);
$this->template->render('local_all', $data);
}