mirror of
https://github.com/flarum/framework.git
synced 2025-03-29 18:55:14 +08:00
Use Frontend extender for embedding statistics in admin frontend
Refs flarum/core#1602, flarum/core#1608.
This commit is contained in:
parent
54266ea341
commit
6d2ebadcbf
@ -11,14 +11,10 @@
|
||||
|
||||
use Flarum\Extend;
|
||||
use Flarum\Statistics\Listener;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
|
||||
return [
|
||||
(new Extend\Frontend('admin'))
|
||||
->js(__DIR__.'/js/dist/admin.js')
|
||||
->css(__DIR__.'/less/admin.less'),
|
||||
|
||||
function (Dispatcher $events) {
|
||||
$events->subscribe(Listener\AddStatisticsData::class);
|
||||
}
|
||||
->css(__DIR__.'/less/admin.less')
|
||||
->content(Listener\AddStatisticsData::class),
|
||||
];
|
||||
|
@ -14,12 +14,12 @@ namespace Flarum\Statistics\Listener;
|
||||
use DateTime;
|
||||
use DateTimeZone;
|
||||
use Flarum\Discussion\Discussion;
|
||||
use Flarum\Frontend\HtmlDocument;
|
||||
use Flarum\Post\Post;
|
||||
use Flarum\User\User;
|
||||
use Flarum\Frontend\Event\Rendering;
|
||||
use Flarum\Settings\SettingsRepositoryInterface;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
|
||||
class AddStatisticsData
|
||||
{
|
||||
@ -36,25 +36,12 @@ class AddStatisticsData
|
||||
$this->settings = $settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Dispatcher $events
|
||||
*/
|
||||
public function subscribe(Dispatcher $events)
|
||||
public function __invoke(HtmlDocument $view)
|
||||
{
|
||||
$events->listen(Rendering::class, [$this, 'addStatisticsData']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Rendering $event
|
||||
*/
|
||||
public function addStatisticsData(Rendering $event)
|
||||
{
|
||||
if ($event->isAdmin()) {
|
||||
$event->view->setVariable('statistics', array_merge(
|
||||
$this->getStatistics(),
|
||||
['timezoneOffset' => $this->getUserTimezone()->getOffset(new DateTime)]
|
||||
));
|
||||
}
|
||||
$view->payload['statistics'] = array_merge(
|
||||
$this->getStatistics(),
|
||||
['timezoneOffset' => $this->getUserTimezone()->getOffset(new DateTime)]
|
||||
);
|
||||
}
|
||||
|
||||
private function getStatistics()
|
||||
|
Loading…
x
Reference in New Issue
Block a user