<?php
namespace Andy\XFRMDownloadHistory\XFRM\Pub\Controller;
use XF\Mvc\ParameterBag;
class ResourceItem extends XFCP_ResourceItem
{
public function actionDownloadHistory(ParameterBag $params)
{
// get visitor
$visitor = \XF::visitor();
// get permission
if (!$visitor->hasPermission('XFRMDownloadHistory', 'view'))
{
return $this->noPermission();
}
// get options
$options = \XF::options();
// get options from Admin CP -> Options -> XFRM download history -> Limit
$limit = $options->XFRMDownloadHistoryLimit;
// get resourceId
$resourceId = $params->resource_id;
// get resource
$finder = \XF::finder('XFRM:ResourceItem');
$resource = $finder
->where('resource_id', $resourceId)
->fetchOne();
// get resourceTitle
$resourceTitle = $resource['title'];
// get results
$finder = \XF::finder('XFRM:ResourceItem');
$results = $finder
->where('resource_id', $resourceId)
->order('CurrentVersion.resource_version_id', 'DESC')
->order('CurrentVersion.release_date', 'DESC')
->limit($limit)
->fetch();
// prepare viewParams
$viewParams = [
'resourceTitle' => $resourceTitle,
'results' => $results
];
// send to template
return $this->view('Andy\XFRMDownloadHistory:DownloadHistory', 'andy_xfrmdownloadhistory', $viewParams);
}
}