Последняя версия с сервера прошлого разработчика
This commit is contained in:
54
nova-components/NovaLeader/src/CardServiceProvider.php
Executable file
54
nova-components/NovaLeader/src/CardServiceProvider.php
Executable file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace Ysv\NovaLeader;
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Laravel\Nova\Events\ServingNova;
|
||||
use Laravel\Nova\Nova;
|
||||
|
||||
class CardServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$this->app->booted(function () {
|
||||
$this->routes();
|
||||
});
|
||||
|
||||
Nova::serving(function (ServingNova $event) {
|
||||
Nova::script('nova-leader', __DIR__.'/../dist/js/card.js');
|
||||
Nova::style('nova-leader', __DIR__.'/../dist/css/card.css');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the card's routes.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function routes()
|
||||
{
|
||||
if ($this->app->routesAreCached()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Route::middleware(['nova'])
|
||||
->prefix('nova-vendor/nova-leader')
|
||||
->group(__DIR__.'/../routes/api.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* Register any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
52
nova-components/NovaLeader/src/NovaLeader.php
Executable file
52
nova-components/NovaLeader/src/NovaLeader.php
Executable file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace Ysv\NovaLeader;
|
||||
|
||||
use App\Domain\Subscriptions\Service\SubscriptionService;
|
||||
use App\Models\User;
|
||||
use Laravel\Nova\Card;
|
||||
|
||||
class NovaLeader extends Card
|
||||
{
|
||||
/**
|
||||
* The width of the card (1/3, 1/2, or full).
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $width = '1/3';
|
||||
|
||||
public $height = 'fixed';
|
||||
|
||||
public function currentLeader()
|
||||
{
|
||||
$mode = nova_get_setting('vote_paid_mode');
|
||||
$leader_count = nova_get_setting('vote_leader_count');
|
||||
|
||||
if($mode){
|
||||
$leaders = collect(SubscriptionService::leaders())->take($leader_count);
|
||||
$ids = $leaders->pluck('user_id');
|
||||
$users = User::whereIn('id', $ids)->get();
|
||||
$leaderUsers = $leaders->map(function($item) use($users) {
|
||||
$item->user = $users->where('id', $item->user_id)->first()->only(['id', 'first_name', 'last_name', 'username']);
|
||||
return $item;
|
||||
});
|
||||
}else{
|
||||
$leaderUsers = SubscriptionService::freeLeaders();
|
||||
}
|
||||
|
||||
|
||||
$amount = SubscriptionService::amount();
|
||||
|
||||
return $this->withMeta(['leaders' => $leaderUsers, 'amount' => $amount, 'mode' => (boolean) $mode]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the component name for the element.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function component()
|
||||
{
|
||||
return 'nova-leader';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user