<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Welcome extends MX_Controller {

    var $paths;
    var $is_logged_in;
    var $theme;
    var $base_url;
    var $adminConfig;
    var $latestListing;
    var $currentUser;
    var $data;

    function __construct() {
        parent::__construct();
        $this->load->config('app', TRUE);
        $this->load->model('listings/listing_model', 'listing');
        $this->load->model('requests/request_model', 'request');
        $this->load->model('listings/listing_image_model', 'listing_image');
        $this->paths = $this->config->item('paths','app');
        $this->theme = $this->paths['cur_themes'];
        $this->base_url = BASE_URL;
        $this->base = BASE;
        if (array_key_exists('user_info',$this->session->all_userdata())){
            $this->currentUser = $this->session->all_userdata()['user_info'];
        }

      //var_dump($this->session->all_userdata()); exit;
    }

    public function index(){
        $data = $this->data;
        //var_dump($data); exit;
        $data['theme'] = $this->paths['cur_themes'];
        $data['base_url'] = BASE_URL;
        $data['base'] = BASE;
        $data['account_info'] = $this->session->all_userdata();
        //var_dump($data['latestListing']); exit;



        $this->parser->parse("home", $data);
    }


    protected function bindImagesToLatestListings($listings){
        $listingsWithImage = [];
        foreach($listings as $listing){
            $listing['image'] = $this->listing_image->get_by(array('listing_id' => $listing['id']));
            if($listing['image']){
                array_push($listingsWithImage,$listing);
            }
        }
        return $listingsWithImage;
    }
}

/* End of file users.php */
/* Location: ./application/modules/users/controllers/users.php */