Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/tobi nba try #99

Draft
wants to merge 13 commits into
base: develop
Choose a base branch
from
48 changes: 48 additions & 0 deletions packages/wp-plugin/essentials/inc/dashboard/blocks/nba/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace ionos_wordpress\essentials\dashboard\blocks\next_best_actions;
use const ionos_wordpress\essentials\PLUGIN_DIR;

\add_action('init', function () {
\register_block_type(
PLUGIN_DIR . '/build/dashboard/blocks/next-best-actions',
// [
// 'render_callback' => function ($attributes) {
// require_once __DIR__ . '/render.php';
// },
// ]
);
});

\add_action('admin_init', function () {
if (isset($_GET['complete_nba'])) {
require_once __DIR__ . '/model.php';
$nba_id = $_GET['complete_nba'];

$nba = \ionos_wordpress\essentials\dashboard\blocks\next_best_actions\model\NBA::getNBA($nba_id);
$nba->setStatus( "completed", true);
}
});

\add_action('rest_api_init', function () {
\register_rest_route('ionos/v1', '/dismiss_nba/(?P<id>[a-zA-Z0-9-]+)', [
'methods' => 'GET',
'callback' => function ($request) {
require_once __DIR__ . '/model.php';
$params = $request->get_params();
$nba_id = $params['id'];

$nba = \ionos_wordpress\essentials\dashboard\blocks\next_best_actions\model\NBA::getNBA($nba_id);
$res = $nba->setStatus( "dismissed", true);
if ($res) {
return new \WP_REST_Response(['status' => 'success', 'res' => $res], 200);
}
return new \WP_REST_Response(['status' => 'error'], 500);
},
'permission_callback' => function () {
return true || \current_user_can('manage_options');
},
]);
});


162 changes: 162 additions & 0 deletions packages/wp-plugin/essentials/inc/dashboard/blocks/nba/model.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
<?php

/**
* This class represents the Next Best Action (NBA) model.
*/

namespace ionos_wordpress\essentials\dashboard\blocks\next_best_actions\model;

class NBA
{
private static $option_name = 'ionos_nba_status';

private static $option_value;
private static array $actions = [];

private function __construct(
readonly string $id,
readonly string $title,
readonly string $description,
readonly string $link,
readonly bool $completed
) {
$a = "b";
self::$actions[$this->id] = $this;
}

public function __get($property)
{
if ('active' === $property) {
$status = $this->_get_status();
if (isset($status["completed"]) && $status["completed"] || isset($status["dismissed"]) && $status["dismissed"]) {
return false;
}
// $status = (object) $this->_get_status();
// if ($status?->completed ?? false || $status?->dismissed ?? false) {
// return false;
// }
return ! $this->completed;
}
}

private static function _get_option()
{
if (! isset(self::$option_value)) {
self::$option_value = \get_option(self::$option_name, []);
}
return self::$option_value;
}

private static function _set_option(array $option)
{
return \update_option(self::$option_name, $option);
}

private function _get_status()
{
$option = $this->_get_option();
return $option[$this->id] ?? [];
}

function setStatus($key, $value) {
$id = $this->id;
$option = self::_get_option();

$option[$id] ??= [];
$option[$id][$key] = $value;
return self::_set_option($option);
}

public static function getNBA($id)
{
return self::$actions[$id];
}

public static function getActions()
{
return self::$actions;
}

public static function register($id, $title, $description, $link, $completed = false)
{
new NBA($id, $title, $description, $link, $completed);
}

}
NBA::register(
id: 'addPage',
title: 'Add a page',
description: 'Create some content for your website visitor.',
link: admin_url('post-new.php?post_type=page'),
completed: wp_count_posts('page')->publish > 0
);

NBA::register(
id: 'checkPluginsPage',
title: 'Check plugins page',
description: 'Ensure all your plugins are up-to-date and functioning correctly.',
link: admin_url('plugins.php?complete_nba=checkPluginsPage'),
// completed: (function(){
// return false;
// })()
);

NBA::register(
id: 'checkThemesPage',
title: 'Check themes page',
description: 'Review and manage your installed themes for a fresh look.',
link: admin_url('themes.php?complete_nba=checkThemesPage'),
// completed: (function(){
// return false;
// })()
);

NBA::register(
id: 'checkSettingsPage',
title: 'Check settings page',
description: 'Verify your site settings to ensure everything is configured properly.',
link: admin_url('options-general.php?complete_nba=checkSettingsPage'),
// completed: (function(){
// return false;
// })()
);

NBA::register(
id: 'checkUpdatesPage',
title: 'Check updates page',
description: 'Stay secure by keeping your WordPress installation up-to-date.',
link: admin_url('update-core.php?complete_nba=checkUpdatesPage'),
// completed: (function(){
// return false;
// })()
);

NBA::register(
id: 'checkCommentsPage',
title: 'Check comments page',
description: 'Moderate and manage comments to keep your community engaged.',
link: admin_url('edit-comments.php?complete_nba=checkCommentsPage'),
// completed: (function(){
// return false;
// })()
);

NBA::register(
id: 'checkPostsPage',
title: 'Check posts page',
description: 'Review your posts to ensure they are up-to-date and relevant.',
link: admin_url('edit.php?post_type=post&complete_nba=checkPostsPage'),
// completed: (function(){
// return false;
// })()
);

NBA::register(
id: 'checkUsersPage',
title: 'Check users page',
description: 'Manage user roles and permissions to maintain site security.',
link: admin_url('users.php?complete_nba=checkUsersPage'),
// completed: (function(){
// return false;
// })()
);
50 changes: 50 additions & 0 deletions packages/wp-plugin/essentials/inc/dashboard/blocks/nba/render.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace ionos_wordpress\essentials\dashboard\blocks\next_best_actions;

use ionos_wordpress\essentials\dashboard\blocks\next_best_actions\model\NBA;

require_once __DIR__ . '/model.php';
$actions = NBA::getActions();
if (empty($actions)) {
return;
}

$template = '<div id="ionos-dashboard__essentials_nba" class="wp-block-group alignwide">'
. '<div class="wp-block-group is-vertical is-content-justification-left is-layout-flex wp-container-core-group-is-layout-2 wp-block-group-is-layout-flex">'
. sprintf('<h2 class="wp-block-heading">%s</h2>', \esc_html__('Next best actions ⚡', 'ionos-essentials'))
. sprintf('<p>%s</p>', \esc_html__('Description of this block', 'ionos-essentials'))
. '</div>'
. '<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-1 wp-block-columns-is-layout-flex">'
. '%s'
. '</div></div>';

$body = '';
foreach ($actions as $action) {
$active = $action->active;
if (! $active) {
continue;
}
$body .= '<div class="wp-block-column is-style-default has-border-color is-layout-flow wp-block-column-is-layout-flow">'
. sprintf('<h2 class="wp-block-heading">%s</h2>', \esc_html($action->title, 'ionos-essentials'))
. sprintf('<p>%s</p>', \esc_html($action->description, 'ionos-essentials'))
. '<div class="wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex">'
. sprintf(
'<div class="wp-block-button"><a href="%s" class="wp-block-button__link wp-element-button" target="_top">%s</a></div>',
\esc_url($action->link),
\esc_html("Primary button", 'ionos-essentials'),
)
. '<div class="wp-block-button is-style-outline is-style-outline--1">'
. sprintf(
'<div class="wp-block-button"><a id="%s" class="wp-block-button__link wp-element-button dismiss-nba" target="_top">%s</a></div>',
$action->id,
\esc_html("Dismiss", 'ionos-essentials')
)
. '</div></div></div>';
}

if (empty($body)) {
return;
}

\printf($template, $body);
35 changes: 35 additions & 0 deletions packages/wp-plugin/essentials/inc/dashboard/blocks/nba/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#ionos-dashboard__essentials_nba {
min-height:0px;
}

#ionos-dashboard__essentials_nba > .wp-block-group {
margin-top:0px;
margin-bottom:15px;
padding-top:0;
padding-right:0;
padding-bottom:0;
padding-left:0
}

#ionos-dashboard__essentials_nba > .wp-block-columns {
border-style:none;
border-width:0px;
display: flex;
flex-wrap: wrap !important;
}

#ionos-dashboard__essentials_nba > .wp-block-columns > .wp-block-column {
border-color:#bcc8d4;
border-width:1px;
border-radius:24px;
flex: 1 1 calc(33.333% - 14px);
max-width: calc(33.333% - 14px);
box-sizing: border-box;
}

/* Ensure the last columns do not stretch */
#ionos-dashboard__essentials_nba > .wp-block-columns > .wp-block-column:nth-child(3n+1) {
margin-left: 0;
}


Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ <h2 class="wp-block-heading">Next best action 1</h2>
<!-- /wp:columns --></div>
<!-- /wp:group -->

<!-- wp:ionos-dashboard-page/next-best-actions /-->

<!-- wp:columns -->
<div class="wp-block-columns"><!-- wp:column -->
<div class="wp-block-column"><!-- wp:heading {"level":3} -->
Expand Down

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions packages/wp-plugin/essentials/inc/dashboard/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
require_once __DIR__ . '/editor.php';
}

require_once __DIR__ . '/blocks/nba/index.php';

\add_action('init', function () {
define('IONOS_ESSENTIALS_DASHBOARD_ADMIN_PAGE_TITLE', __('IONOS Dashboard', 'ionos-essentials'));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ msgstr "IONOS-Gruppe"
msgid "https://www.ionos-group.com/brands.html"
msgstr "https://www.ionos-group.com/brands.html"

#: inc/dashboard/index.php:35
#: inc/dashboard/index.php:37
msgid "IONOS Dashboard"
msgstr "IONOS Dashboard"

Expand Down Expand Up @@ -195,3 +195,21 @@ msgstr "Sicherheits-Scan"
#: build/dashboard/blocks/vulnerability/render.php:36
msgid "IONOS Security Plugin not available"
msgstr "IONOS Security Plugin nicht verfügbar"

#: inc/dashboard/blocks/nba/render.php:15
msgid "Next best actions ⚡"
msgstr ""

#: build/dashboard/blocks/next-best-actions/block.json
msgctxt "block title"
msgid "NBA"
msgstr ""

#: build/dashboard/blocks/next-best-actions/block.json
msgctxt "block description"
msgid "Next Best Actions"
msgstr ""

#: inc/dashboard/blocks/nba/render.php:16
msgid "Description of this block"
msgstr ""
Loading