*/
abstract class Mage_Adminhtml_Controller_Report_Abstract extends Mage_Adminhtml_Controller_Action
{
/**
* Admin session model
*
* @var null|Mage_Admin_Model_Session
*/
protected $_adminSession = null;
/**
* Retrieve admin session model
*
* @return Mage_Admin_Model_Session
*/
protected function _getSession()
{
if (is_null($this->_adminSession)) {
$this->_adminSession = Mage::getSingleton('admin/session');
}
return $this->_adminSession;
}
/**
* Add report breadcrumbs
*
* @return Mage_Adminhtml_Controller_Report_Abstract
*/
public function _initAction()
{
$this->loadLayout()
->_addBreadcrumb(Mage::helper('reports')->__('Reports'), Mage::helper('reports')->__('Reports'));
return $this;
}
/**
* Report action init operations
*
* @param array|Varien_Object $blocks
* @return Mage_Adminhtml_Controller_Report_Abstract
*/
public function _initReportAction($blocks)
{
if (!is_array($blocks)) {
$blocks = array($blocks);
}
$requestData = Mage::helper('adminhtml')->prepareFilterString($this->getRequest()->getParam('filter'));
$requestData = $this->_filterDates($requestData, array('from', 'to'));
$requestData['store_ids'] = $this->getRequest()->getParam('store_ids');
$params = new Varien_Object();
foreach ($requestData as $key => $value) {
if (!empty($value)) {
$params->setData($key, $value);
}
}
foreach ($blocks as $block) {
if ($block) {
$block->setPeriodType($params->getData('period_type'));
$block->setFilterData($params);
}
}
return $this;
}
/**
* Add refresh statistics links
*
* @param string $flagCode
* @param string $refreshCode
* @return Mage_Adminhtml_Controller_Report_Abstract
*/
protected function _showLastExecutionTime($flagCode, $refreshCode)
{
$flag = Mage::getModel('reports/flag')->setReportFlagCode($flagCode)->loadSelf();
$updatedAt = ($flag->hasData())
? Mage::app()->getLocale()->storeDate(
0, new Zend_Date($flag->getLastUpdate(), Varien_Date::DATETIME_INTERNAL_FORMAT), true
)
: 'undefined';
$refreshStatsLink = $this->getUrl('*/report_statistics');
$directRefreshLink = $this->getUrl('*/report_statistics/refreshRecent', array('code' => $refreshCode));
Mage::getSingleton('adminhtml/session')->addNotice(Mage::helper('adminhtml')->__('Last updated: %s. To refresh last day\'s statistics, click here.', $updatedAt, $refreshStatsLink, $directRefreshLink));
return $this;
}
}