<?php
namespace Modules\Admin\CronJobs\Logs;

class Controller extends \App\Mvc\Controller\Window\PaginatedListing\ListingAbstract
{
	protected $listOrderingColumns = ['addTime'];

	protected function initialize()
	{
		parent::initialize();

		$this->actionsCfg['viewMessage'] =       	['checkSection'=>false, 'checkOption'=>false];

	}


	/**
	 * (non-PHPdoc)
	 * @see \App\Mvc\Controller\Window\PaginatedListing\ListingAbstract::optionDefineParams()
	 */
	protected function optionDefineParams(\App\Mvc\View\Utils\RowOptions\Option\Option $option, $selection)
	{
		switch($option->getId()){
			case 'viewMessage':
			break;
			default:
				return false;
		}

		return true;

	}

	/**
	 * {@inheritDoc}
	 * @see \App\Mvc\Controller\Window\PaginatedListing\ListingAbstract::actionList_getViewObject()
	 */
	protected function actionList_getViewObject($R)
	{
		$view = parent::actionList_getViewObject($R);
		$view->setOutputVar('mvcModel', new Model());

		return $view;
	}

	/**
	 * (non-PHPdoc)
	 * @see \App\Mvc\Controller\Window\PaginatedListing\ListingAbstract::optionGetEntityName()
	 */
	protected function optionGetEntityName($id)
	{
		return '';
	}


	/**
	 *
	 * @param array $R
	 */
	public function actionViewMessage($R)
	{
		// instantiate the view
		$view = new View_ViewMessage($this);

		$class = getClassNamespace(get_class($this)).'\Model';
		$model = new $class();

		$log = $model->getLogDetails($R['id']);
		$view->setOutputVar("log", $log);
		$view->setOutputVar("page", ($R['page']??0));
		$view->setOutputVar("id", $R['id']);
		$view->setPageTitle(sprintf("%s #%s", $view->getPageTitle(), $R['id']));

		// render the view
		return new \Engine\Mvc\Response\Html($view->render());
	}
}