<?php

class Albums extends CIF_Controller {

    public $layout = 'full';
    public $module = 'albums';
    public $model = 'Sessions_model';

    public function __construct() {
        parent::__construct();
        $this->load->library('form_validation');
        $this->load->model($this->model);
        $this->_primary_key = $this->{$this->model}->_primary_keys[0];
    }

    public function index() {
        $this->{$this->model}->custom_select = 'sessions.*, categories.title as category';
        $this->{$this->model}->joins = array(
            'categories' => array('categories.category_id = sessions.category_id', 'inner')
        );
        $data['categories'] = $this->db->select('categories.*, (SELECT COUNT(*) FROM sessions where categories.category_id = sessions.category_id) as count')->order_by('order')->get('categories')->result();

        $data['items'] = $this->{$this->model}->get();

        $this->load->view($this->module, $data);
    }

}
