<?php
/**
 * Main Controller
 */
class Main extends Controller
{
    /**
     * Process
     */
    public function process()
    {    

		$AuthUser		= $this->getVariable("AuthUser");
		$Route			= $this->getVariable("Route");

        // Config
        $Config['nav']  = 'main';
        $Config['btn']  = 'game';
        $Config['search']  = true;


        $Total['games']     = $this->db->from(null,'SELECT count(posts.id) as total FROM `posts`')->total(); 
        $Total['categories']     = $this->db->from(null,'SELECT count(categories.id) as total FROM `categories`')->total(); 
        $Total['users']      = $this->db->from(null,'SELECT count(users.id) as total FROM `users`')->total(); 
        $Total['comments']      = $this->db->from(null,'SELECT count(comments.id) as total FROM `comments`')->total(); 

        $Listings = $this->db->from(null,'
            SELECT 
            posts.*,
            categories.name
            FROM `posts`  
            LEFT JOIN (
                  SELECT
                    post_id, 
                    category_id 
                  FROM `posts_category`   
                  GROUP BY posts_category.post_id
                  ORDER BY posts_category.category_id DESC
                ) posts_category ON posts.id = posts_category.post_id
            LEFT JOIN categories ON categories.id = posts_category.category_id
            ORDER BY posts.id DESC
            LIMIT 0,10')
            ->all();
        $this->setVariable("Config", $Config);  
        $this->setVariable("Total", $Total);  
        $this->setVariable("Listings", $Listings);  
        
        $this->view("main", "admin");
    }
}