where('display_on_medal_page', 1); $q = htmlspecialchars($_REQUEST['q'] ?? ''); if (!empty($q)) { $query->where('username', 'name', "%{$q}%"); } $total = (clone $query)->count(); $perPage = 20; list($paginationTop, $paginationBottom, $limit, $offset) = pager($perPage, $total, "?"); $rows = (clone $query)->offset($offset)->take($perPage)->orderBy('id', 'desc')->get(); $q = htmlspecialchars($q); $title = nexus_trans('medal.label'); $columnNameLabel = nexus_trans('label.name'); $columnImageLargeLabel = nexus_trans('medal.fields.image_large'); $columnPriceLabel = nexus_trans('medal.fields.price'); $columnDurationLabel = nexus_trans('medal.fields.duration'); $columnDescriptionLabel = nexus_trans('medal.fields.description'); $columnActionLabel = nexus_trans('nexus.action'); $columnSaleBeginEndTimeLabel = nexus_trans('medal.fields.sale_begin_end_time'); $columnInventoryLabel = nexus_trans('medal.fields.inventory'); $columnBonusAdditionFactorLabel = nexus_trans('medal.fields.bonus_addition_factor'); $header = '

'.$title.'

'; $filterForm = <<
FORM; stdhead($title); begin_main_frame(); $table = << TABLE; $now = now(); $table .= ''; $userMedals = \App\Models\UserMedal::query()->where('uid', $CURUSER['id']) ->orderBy('id', 'desc') ->get() ->keyBy('medal_id') ; foreach ($rows as $row) { $disabled = ' disabled'; $class = ''; if ($userMedals->has($row->id)) { $btnText = nexus_trans('medal.buy_already'); } elseif ($row->get_type == \App\Models\Medal::GET_TYPE_GRANT) { $btnText = nexus_trans('medal.grant_only'); } elseif ($row->sale_begin_time && $row->sale_begin_time->gt($now)) { $btnText = nexus_trans('medal.before_sale_begin_time'); } elseif ($row->sale_end_time && $row->sale_end_time->lt($now)) { $btnText = nexus_trans('medal.after_sale_end_time'); } elseif ($row->inventory !== null && $row->inventory <= 0) { $btnText = nexus_trans('medal.inventory_empty'); } elseif ($CURUSER['seedbonus'] < $row->price) { $btnText = nexus_trans('medal.require_more_bonus'); } else { $btnText = nexus_trans('medal.buy_btn'); $disabled = ''; $class = 'buy'; } $action = sprintf( '', $class, $row->id, $btnText, $disabled ); $table .= sprintf( '', $row->id, $row->name, $row->image_large, $row->sale_begin_time ?? '--', $row->sale_end_time ?? '--', $row->bonus_addition_factor, number_format($row->price), $row->durationText, $row->inventory ?? nexus_trans('label.infinite'), $row->description, $action ); } $table .= '
ID $columnNameLabel $columnImageLargeLabel $columnSaleBeginEndTimeLabel $columnBonusAdditionFactorLabel $columnPriceLabel $columnDurationLabel $columnInventoryLabel $columnDescriptionLabel $columnActionLabel
%s%s%s ~
%s
%s%s%s%s%s%s
'; echo $header . $table . $paginationBottom; end_main_frame(); $confirmMsg = nexus_trans('medal.confirm_to_buy'); $js = <<