classes/Gems/Default/LogAction.php
<?php
/**
*
* @package Gems
* @subpackage Controller
* @author Matijs de Jong <mjong@magnafacta.nl>
* @copyright Copyright (c) 2011 Erasmus MC
* @license New BSD License
* @version $Id$
*/
/**
* Show the action log
*
* @package Gems
* @subpackage Default
* @copyright Copyright (c) 2011 Erasmus MC
* @license New BSD License
* @since Class available since version 1.4
*/
class Gems_Default_LogAction extends \Gems_Controller_ModelSnippetActionAbstract
{
/**
* The snippets used for the autofilter action.
*
* @var mixed String or array of snippets name
*/
protected $autofilterSnippets = 'Log\\LogTableSnippet';
/**
* The snippets used for the index action, before those in autofilter
*
* @var mixed String or array of snippets name
*/
protected $indexStartSnippets = array('Generic\\ContentTitleSnippet', 'Log\\LogSearchSnippet');
/**
*
* @var \Gems_Loader
*/
public $loader;
/**
* The snippets used for the show action
*
* @var mixed String or array of snippets name
*/
protected $showSnippets = array('Generic\\ContentTitleSnippet', 'Log\\LogShowSnippet');
/**
* Creates a model for getModel(). Called only for each new $action.
*
* The parameters allow you to easily adapt the model to the current action. The $detailed
* parameter was added, because the most common use of action is a split between detailed
* and summarized actions.
*
* @param boolean $detailed True when the current action is not in $summarizedActions.
* @param string $action The current action.
* @return \MUtil_Model_ModelAbstract
*/
protected function createModel($detailed, $action)
{
$model = $this->loader->getModels()->createLogModel();
if ($detailed) {
$model->applyDetailSettings();
} else {
$model->applyBrowseSettings();
}
return $model;
}
/**
* Helper function to get the title for the index action.
*
* @return $string
*/
public function getIndexTitle()
{
return $this->_('Logging');
}
/**
* Function to allow the creation of search defaults in code
*
* @see getSearchFilter()
*
* @return array
*/
public function getSearchDefaults()
{
if (! $this->defaultSearchData) {
$from = new \MUtil_Date();
$from->subWeek(2);
$until = new \MUtil_Date();
$until->addDay(1);
$this->defaultSearchData = array(
'datefrom' => $from,
'dateuntil' => $until,
'dateused' => 'gla_created',
);
}
return parent::getSearchDefaults();
}
/**
* Get the filter to use with the model for searching
*
* @param boolean $useRequest Use the request as source (when false, the session is used)
* @return array or false
*/
public function getSearchFilter($useRequest = true)
{
$filter = parent::getSearchFilter($useRequest);
$where = \Gems_Snippets_AutosearchFormSnippet::getPeriodFilter($filter, $this->db);
if ($where) {
$filter[] = $where;
}
return $filter;
}
/**
* Helper function to allow generalized statements about the items in the model.
*
* @param int $count
* @return $string
*/
public function getTopic($count = 1)
{
return $this->plural('log', 'log', $count);
}
}