¡Hola, amigos! I’m Señor FAQ, the mustached maestro of questions and answers! With my trusty glasses and a book of endless wisdom, I turn dudas into solutions. Soy el héroe de los curiosos and the champion of clarity.
on_dashboard_boxes
The on_dashboard_boxes
hook in JScms allows developers to dynamically add custom boxes to the admin dashboard. This feature is particularly useful for providing administrators with additional information, statistics, or tools directly in their dashboard view.
on_dashboard_boxes
HookDynamicHooks::addHook()
function to define your custom logic and generate dashboard boxes.Here is an example of how to add a custom box to display marketplace statistics on the admin dashboard:
DynamicHooks::addHook('on_dashboard_boxes', function () use ($jakdb, $jkv, $lang) {
// Fetch marketplace statistics
$chartData = mp_getAdminMarketplaceStats($jakdb);
// Generate the styled list content
$boxContent = <<<HTML
<ul class="list-group">
<li class="list-group-item d-flex justify-content-between align-items-center">
<div class="d-flex align-items-center">
<i class="fas fa-dollar-sign me-2 text-success"></i> {$lang['marketplace_earnings_before_commission']}
</div>
<span class="badge bg-success rounded-pill text-white">{$chartData['total_earnings_before_commission']} {$jkv["marketplace_currency"]}</span>
</li>
<!-- Add additional statistics here -->
</ul>
HTML;
// Return the box data for the dashboard
return [
[
'id' => 'unique_name',
'title' => $lang['your_plugin_phrase'],
'icon' => 'fas fa-store',
'content' => $boxContent,
],
];
}, 'your_plugin');
marketplace_stats
).In your admin dashboard file, make sure to include the following code to render the boxes dynamically:
<?php
$dashboardBoxes = DynamicHooks::executeHook('on_dashboard_boxes', true);
if (!empty($dashboardBoxes)) {
foreach ($dashboardBoxes as $box) {
echo '<div class="col-12" data-id="' . htmlspecialchars($box['id']) . '>';
echo '<div class="card">';
echo '<div class="card-header move-cursor">';
echo '<h3 class="card-title">';
if (!empty($box['icon'])) {
echo '<i class="' . htmlspecialchars($box['icon']) . '"></i> ';
}
echo htmlspecialchars($box['title']);
echo '</h3>';
echo '<div class="card-options">';
echo '<button class="btn btn-sm btn-outline-secondary toggle-visibility" data-id="' . htmlspecialchars($box['id']) . '" data-visible="true">';
echo '<i class="fas fa-eye"></i>';
echo '</button>';
echo '</div>';
echo '</div>';
echo '<div class="card-body">';
echo $box['content'] ?? '';
echo '</div>';
echo '</div>';
echo '</div>';
}
}
?>
on_dashboard_boxes
This hook allows developers to extend the admin dashboard with dynamic content, providing administrators with valuable insights and tools in a centralized location.