<?php
	lt_include( PLOG_CLASS_PATH."class/view/admin/adminplugintemplatedview.class.php" );
	lt_include( PLOG_CLASS_PATH."class/data/pager/pager.class.php" );
	lt_include( PLOG_CLASS_PATH."plugins/clean/class/dao/unusedblogs.class.php" );
		
    /**
     * \ingroup View
     * @private
     *
	 * shows a list with all the blogs from the site
	 */
	class AdminCleanView extends AdminPluginTemplatedView
	{
        const LAST_UPDATE_DEFAULT = 30;
        const TOTAL_POSTS_LESS_THAN_DEFAULT = 5;
        const SEARCH_TERMS_DEFAULT = "";
        
		var $_page;
		var $_last_update = self::LAST_UPDATE_DEFAULT;
		var $_total_posts_less_than = self::TOTAL_POSTS_LESS_THAN_DEFAULT;
		var $_search_terms = self::SEARCH_TERMS_DEFAULT;
		var $_pagerUrl;
		function AdminCleanView( $blogInfo, $params = Array() )
		{
			$this->AdminPluginTemplatedView( $blogInfo, "clean", "cleanblogs" );
			$this->_pagerUrl = "?op=cleanUnusedBlogs";
			$this->_page = $this->getCurrentPageFromRequest();

            if(!empty($params["search_terms"]))
                $this->_search_terms = $params["search_terms"];
            if(!empty($params["last_update"]))
                $this->_last_update = $params["last_update"];
            if(!empty($params["total_posts_less_than"]))
                $this->_total_posts_less_than = $params["total_posts_less_than"];
		}
		
		function render()
		{			
            // we need to get all the blogs
			$blogs = new UnusedBlogs();
            $siteBlogs = $blogs->getAllBlogs( $this->_last_update,
                                              $this->_total_posts_less_than,
                                              BLOG_STATUS_ALL,
                                              ALL_BLOG_CATEGORIES,
                                              $this->_search_terms,
                                              $this->_page,
                                              DEFAULT_ITEMS_PER_PAGE );
            if( !$siteBlogs ) {
            	$siteBlogs = Array();
            }

			$numBlogs = $blogs->getNumBlogs( $this->_last_update,
                                             $this->_total_posts_less_than,
                                             BLOG_STATUS_ALL,
                                             ALL_BLOG_CATEGORIES,
                                             $this->_search_terms );
            
            // throw the right event
			$this->notifyEvent( EVENT_BLOGS_LOADED, Array( "blogs" => &$siteBlogs ));            
            
			// calculate the links to the different pages
			$pager = new Pager( $this->_pagerUrl."&amp;searchTerms=".$this->_search_terms."&amp;last_update=".$this->_last_update."&amp;total_posts_less_than=".$this->_total_posts_less_than."&amp;page=",
			                    $this->_page, 
								$numBlogs, 
								DEFAULT_ITEMS_PER_PAGE );

			$this->setValue( "siteblogs", $siteBlogs );
			$this->setValue( "pager", $pager );
			$this->setValue( "currentstatus", $this->_last_update );
			$this->setValue( "blogstatus", BlogStatus::getStatusList( true ));
			$this->setValue( "searchTerms", $this->_search_terms );
			$this->setValue( "total_posts_less_than", $this->_total_posts_less_than );
 
			// let the parent view do its job
			parent::render();                        
		}	
	}
?>