<?php
/**
 * Bigace - a PHP and MySQL based Web CMS.
 *
 * LICENSE
 *
 * This source file is subject to the new GNU General Public License
 * that is bundled with this package in the file LICENSE.
 * It is also available through the world-wide-web at this URL:
 * http://www.bigace.de/license.html
 *
 * Bigace is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * @category   Bigace
 * @package    Bigace_Admin
 * @subpackage Portlet
 * @copyright  Copyright (c) 2009-2010 Keleo (http://www.keleo.de)
 * @license    http://www.bigace.de/license.html     GNU Public License
 * @version    $Id$
 */

/**
 * A portlet to flush all Community caches.
 *
 * @category   Bigace
 * @package    Bigace_Admin
 * @subpackage Portlet
 * @copyright  Copyright (c) 2009-2010 Keleo (http://www.keleo.de)
 * @license    http://www.bigace.de/license.html     GNU Public License
 */
class Bigace_Admin_Portlet_CacheFlush extends Bigace_Admin_Portlet_Default
{

    public function getFilename()
    {
        return 'portlets/cacheflush.phtml';
    }

    public function flushAllAction()
    {
        $start = microtime(true);

        $cache = new Bigace_Cache();
        $cache->flushAll($this->getController()->getCommunity());
        
        $end = microtime(true);
        $this->getController()->getRequest()->setParam('FLUSHED_CACHES', (int)($end - $start));
    }

    public function getParameter()
    {
        $params = array(
            'ACTION' => $this->createLink('flush-all')
        );
        $duration = $this->getController()->getRequest()->getParam('FLUSHED_CACHES');
        if ($duration !== null) {
            $params['DURATION'] = $duration;
        }
        return $params;
    }

}
