×
@@ -1562,6 +1568,23 @@ jQuery(document).ready(function($) {
}
});
+ // --- Add New Prize ---
+ $('.add-new-prize').on('click', function(e) {
+ e.preventDefault();
+
+ // Clear form for new prize
+ $('#edit-prize-form')[0].reset();
+ $('#edit-prize-id').val(''); // Clear prize ID for new prize
+
+ // Get wheel_id from the modal's data attribute
+ var wheelId = $('#edit-prize-modal').data('wheel-id');
+ $('#edit-wheel-id').val(wheelId);
+
+ console.log('Opening modal for new prize with wheel_id:', wheelId);
+
+ modal.show();
+ });
+
// --- Edit Prize ---
$('.edit-prize').on('click', function(e) {
e.preventDefault();
@@ -1570,7 +1593,7 @@ jQuery(document).ready(function($) {
// AJAX call to get prize details
$.post(ajaxurl, {
action: 'wheel_get_prize_details',
- nonce: wheel_admin_nonce.nonce,
+ _ajax_nonce: wheel_admin_nonce._ajax_nonce,
prize_id: prizeId
}, function(response) {
if (response.success) {
@@ -1592,6 +1615,8 @@ jQuery(document).ready(function($) {
} else {
alert(response.data.message || 'An error occurred.');
}
+ }).fail(function() {
+ alert('An error occurred while loading prize details.');
});
});
@@ -1602,7 +1627,7 @@ jQuery(document).ready(function($) {
// Pripravimo podatke iz forme
const formData = {
action: 'wheel_save_prize',
- nonce: wheel_admin_nonce.nonce,
+ _ajax_nonce: wheel_admin_nonce._ajax_nonce,
wheel_id: $('#edit-wheel-id').val(), // **KLJUČNO: pošljemo wheel_id**
prize_id: $('#edit-prize-id').val(),
name: $('#edit-prize-name').val(),
@@ -1616,6 +1641,10 @@ jQuery(document).ready(function($) {
email_template: $('#edit-prize-email-template').val(),
};
+ // Debug: preveri wheel_id
+ console.log('Wheel ID from form:', formData.wheel_id);
+ console.log('Form data:', formData);
+
// Validate form fields
if (!formData.name) {
alert('Prize name is required.');
@@ -1625,9 +1654,14 @@ jQuery(document).ready(function($) {
alert('Probability must be a number between 0 and 1.');
return;
}
+ if (!formData.wheel_id || formData.wheel_id == 0) {
+ alert('Wheel ID is missing. Please refresh the page and try again.');
+ return;
+ }
// AJAX call to save the prize
$.post(ajaxurl, formData, function(response) {
+ console.log('Server response:', response);
if (response.success) {
alert(response.data.message);
modal.hide();
@@ -1635,7 +1669,8 @@ jQuery(document).ready(function($) {
} else {
alert(response.data.message || 'An error occurred while saving.');
}
- }).fail(function() {
+ }).fail(function(xhr, status, error) {
+ console.error('AJAX error:', {xhr: xhr, status: status, error: error});
alert('A critical error occurred. Please try again.');
});
});
@@ -1649,7 +1684,7 @@ jQuery(document).ready(function($) {
$.post(ajaxurl, {
action: 'wheel_delete_prize',
- nonce: wheel_admin_nonce.nonce,
+ _ajax_nonce: wheel_admin_nonce._ajax_nonce,
prize_id: prizeId
}, function(response) {
if (response.success) {
@@ -1684,7 +1719,7 @@ jQuery(document).ready(function($) {
// Collect all settings from the form to test unsaved values
const data = {
action: 'wheel_test_email',
- nonce: wheel_admin_nonce,
+ _ajax_nonce: wheel_admin_nonce._ajax_nonce,
recipient_email: recipientEmail,
smtp_enabled: $('#wheel_smtp_enabled').is(':checked') ? '1' : '0',
smtp_host: $('#wheel_smtp_host').val(),
@@ -1722,6 +1757,70 @@ jQuery(document).ready(function($) {
});
});
}
+
+ // Dodajanje/brisanje produkta za spine
+ $('#add-product-button').on('click', function() {
+ const button = $(this);
+ const productId = $('#new-product-id').val();
+ const spins = $('#new-product-spins').val();
+ const wheelId = button.data('wheel-id');
+
+ if (!productId || !spins) {
+ alert('Prosim vnesite ID produkta in število spinov.');
+ return;
+ }
+
+ $.ajax({
+ url: ajaxurl,
+ method: 'POST',
+ data: {
+ action: 'ajax_update_wheel_product_spins',
+ _ajax_nonce: wheel_admin_nonce._ajax_nonce,
+ wheel_id: wheelId,
+ product_id: productId,
+ spins: spins
+ },
+ success: function(response) {
+ if(response.success) {
+ location.reload();
+ } else {
+ alert('Napaka: ' + response.data.message);
+ }
+ },
+ error: function() {
+ alert('Prišlo je do kritične napake.');
+ }
+ });
+ });
+
+ $('.delete-product-button').on('click', function() {
+ if(!confirm('Ste prepričani?')) return;
+
+ const button = $(this);
+ const productId = button.data('product-id');
+ const wheelId = button.data('wheel-id');
+
+ $.ajax({
+ url: ajaxurl,
+ method: 'POST',
+ data: {
+ action: 'ajax_delete_wheel_product',
+ _ajax_nonce: wheel_admin_nonce._ajax_nonce,
+ wheel_id: wheelId,
+ product_id: productId
+ },
+ success: function(response) {
+ if(response.success) {
+ location.reload();
+ } else {
+ alert('Napaka: ' + response.data.message);
+ }
+ },
+ error: function() {
+ alert('Prišlo je do kritične napake.');
+ }
+ });
+ });
});"""
@@ -3587,12 +3686,12 @@ $wheels = $wpdb->get_results("SELECT * FROM $wheels_table ORDER BY id ASC", ARRA
margin: 0 auto;
width: 100%;
max-width: 700px;
- filter: drop-shadow(0 0 25px rgba(0, 200, 255, 0.5));
+ filter: drop-shadow(0 0 15px rgba(0, 200, 255, 0.3));
padding-top: 80px;
transition: transform 0.05s ease-out;
}
-/* Outer ring lighting effect */
+/* Outer ring lighting effect - POENOSTAVLJENO */
.wheel-wrapper::before {
content: '';
position: absolute;
@@ -3601,9 +3700,10 @@ $wheels = $wpdb->get_results("SELECT * FROM $wheels_table ORDER BY id ASC", ARRA
width: 110%;
height: 110%;
border-radius: 50%;
+ /* Manj kompleksen gradient */
background: radial-gradient(
circle at center,
- rgba(0, 200, 255, 0.2) 0%,
+ rgba(0, 150, 200, 0.1) 0%,
rgba(0, 0, 0, 0) 70%
);
z-index: -1;
@@ -3618,28 +3718,27 @@ $wheels = $wpdb->get_results("SELECT * FROM $wheels_table ORDER BY id ASC", ARRA
transition: none; /* POMEMBNO: ne uporabljamo CSS tranzicije, saj jo upravlja JS */
display: block;
will-change: transform;
+ /* Enostavnejši shadow, ki ga podpirajo vse naprave */
filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.25));
border: 4px solid #222;
- box-shadow: 0 0 10px 2px #00dfe9, 0 2px 8px rgba(0,0,0,0.3);
+ box-shadow: 0 0 10px 2px rgba(0, 223, 233, 0.5), 0 2px 8px rgba(0,0,0,0.3);
border-radius: 50%;
background: #111;
}
-/* Wheel frame */
+/* Wheel frame - BREZ SVG FILTRA */
.wheel-frame {
fill: #0a4d6e;
stroke: #0a7bb5;
stroke-width: 8;
- filter: url(#bevel);
}
-/* LED lighting on wheel frame */
+/* LED lighting on wheel frame - BREZ SVG FILTRA */
.wheel-light-track {
fill: none;
stroke: #00c8ff;
stroke-width: 6;
stroke-dasharray: 3, 8;
- filter: url(#glow);
animation: lightTrackAnimation 5s linear infinite;
}
@@ -3662,48 +3761,33 @@ $wheels = $wpdb->get_results("SELECT * FROM $wheels_table ORDER BY id ASC", ARRA
}
}
-/* Wheel segments */
+/* Wheel segment - BREZ SVG FILTRA */
.wheel-segment {
- transform-origin: center;
- transition: all 0.3s ease;
- filter: url(#innerShadow);
+ stroke: #fff;
+ stroke-width: 1px;
+ transition: all 0.2s;
}
-/* Segment colors */
-.wheel-segment-yellow {
- /* fill: url(#gradientYellow); */
-}
+/* Simple gradients for cross-browser compatibility */
+.wheel-segment-yellow { fill: #ffdd00; }
+.wheel-segment-green { fill: #88ff00; }
+.wheel-segment-red { fill: #ff5500; }
+.wheel-segment-pink { fill: #ff44aa; }
+.wheel-segment-blue { fill: #00ccff; }
-.wheel-segment-green {
- /* fill: url(#gradientGreen); */
-}
-
-.wheel-segment-red {
- /* fill: url(#gradientRed); */
-}
-
-.wheel-segment-pink {
- /* fill: url(#gradientPink); */
-}
-
-.wheel-segment-blue {
- /* fill: url(#gradientBlue); */
-}
-
-/* Segment dividers */
+/* Divider between segments */
.wheel-divider {
- fill: #303030;
- stroke: #505050;
- stroke-width: 1;
- filter: url(#bevel);
+ stroke: rgba(255, 255, 255, 0.5);
+ stroke-width: 2px;
}
-/* Pegs at the end of dividers */
+/* Pegs on the wheel */
.wheel-peg {
fill: #e0e0e0;
- stroke: #c0c0c0;
- stroke-width: 1;
- filter: url(#pegGlow);
+ stroke: #666;
+ stroke-width: 1px;
+ /* Enostavnejši shadow namesto glow filtra */
+ filter: drop-shadow(0 1px 2px rgba(0,0,0,0.5));
}
@keyframes pegPulse {
@@ -3733,7 +3817,7 @@ $wheels = $wpdb->get_results("SELECT * FROM $wheels_table ORDER BY id ASC", ARRA
}
}
-/* Text on wheel */
+/* Text on wheel - BREZ SVG FILTRA */
.wheel-text {
font-family: 'Arial Rounded MT Bold', 'Arial', sans-serif;
font-size: 24px;
@@ -3745,67 +3829,39 @@ $wheels = $wpdb->get_results("SELECT * FROM $wheels_table ORDER BY id ASC", ARRA
letter-spacing: 1px;
pointer-events: none;
text-anchor: middle;
- filter: url(#textShadow);
+ /* Enostavnejša senca, ki deluje povsod */
+ text-shadow: 1px 1px 3px rgba(0,0,0,0.7);
text-overflow: ellipsis;
max-width: 70px;
}
-/* Center hub */
+/* Center hub - BREZ SVG FILTRA */
.wheel-hub-outer {
fill: #0a4d6e;
stroke: #0a7bb5;
stroke-width: 4;
- filter: url(#bevel);
}
.wheel-hub-inner {
- fill: url(#hubGradient);
- filter: url(#innerGlow);
+ fill: #999;
}
.wheel-hub-button {
- fill: url(#buttonGradient);
- filter: url(#buttonGlow);
+ fill: #330066;
}
+/* Hub text - BREZ SVG FILTRA */
.wheel-hub-text {
font-family: 'Arial Rounded MT Bold', 'Arial', sans-serif;
font-size: 20px;
font-weight: bold;
fill: #ff00aa;
text-anchor: middle;
- filter: url(#neonGlow);
- animation: neonPulse 2s infinite alternate;
+ /* Enostavnejša senca namesto glow filtra */
+ text-shadow: 0 0 10px #ff00aa;
}
-@keyframes neonPulse {
- from {
- filter: url(#neonGlow);
- text-shadow: 0 0 10px #ff00aa, 0 0 20px #ff00aa;
- }
- to {
- filter: url(#neonGlowBright);
- text-shadow: 0 0 15px #ff00aa, 0 0 25px #ff00aa, 0 0 30px #ff00aa;
- }
-}
-
-/* Fast neon pulse for spinning */
-@keyframes fastNeonPulse {
- 0% {
- filter: url(#neonGlow);
- text-shadow: 0 0 10px #ff00aa, 0 0 20px #ff00aa;
- }
- 50% {
- filter: url(#neonGlowBright);
- text-shadow: 0 0 20px #ff00aa, 0 0 30px #ff00aa, 0 0 40px #ff00aa;
- }
- 100% {
- filter: url(#neonGlow);
- text-shadow: 0 0 10px #ff00aa, 0 0 20px #ff00aa;
- }
-}
-
-/* Pointer */
+/* Pointer - BREZ SVG FILTRA */
.wheel-pointer {
position: absolute;
top: 60px;
@@ -3820,7 +3876,7 @@ $wheels = $wpdb->get_results("SELECT * FROM $wheels_table ORDER BY id ASC", ARRA
margin-bottom: 20px;
}
-/* Pointer active state */
+/* Pointer active state - BREZ SVG FILTRA */
.wheel-pointer.active {
filter: drop-shadow(0 0 10px rgba(255, 255, 255, 0.8));
animation: pointerPulse 1s infinite alternate;
@@ -3833,10 +3889,10 @@ $wheels = $wpdb->get_results("SELECT * FROM $wheels_table ORDER BY id ASC", ARRA
@keyframes pointerPulse {
from {
- filter: drop-shadow(0 0 10px rgba(255, 255, 255, 0.8));
+ opacity: 0.8;
}
to {
- filter: drop-shadow(0 0 15px #ff00aa) drop-shadow(0 0 25px rgba(255, 255, 255, 0.9));
+ opacity: 1;
}
}
@@ -4232,21 +4288,21 @@ jQuery(document).ready(function($) {
}
// Elementi
- const wheelContainer = $('.wheel-container');
- const wheelElement = wheelContainer.find('.wheel');
- const spinButton = wheelContainer.find('.wheel-button');
- const resultDiv = wheelContainer.find('.wheel-result');
- const spinsCounter = wheelContainer.find('.wheel-spins-counter span');
+ var wheelContainer = $('.wheel-container');
+ var wheelElement = wheelContainer.find('.wheel');
+ var spinButton = wheelContainer.find('.wheel-button');
+ var resultDiv = wheelContainer.find('.wheel-result');
+ var spinsCounter = wheelContainer.find('.wheel-spins-counter span');
// Stanje
- let isSpinning = false;
- let accumulatedRotation = 0;
- let wheelSpins = wof_data.spins_left;
- const l10n = wof_data.l10n;
+ var isSpinning = false;
+ var accumulatedRotation = 0;
+ var wheelSpins = wof_data.spins_left;
+ var l10n = wof_data.l10n;
// Nastavitve animacije
- const spinDuration = 8000;
- const baseRotations = 5;
+ var spinDuration = 8000;
+ var baseRotations = 5;
// Funkcija za animacijo
function easeOutCubic(t) {
@@ -4254,27 +4310,29 @@ jQuery(document).ready(function($) {
}
function animateWheel(startTime, startRotation, totalRotation) {
- const currentTime = Date.now();
- const elapsedTime = currentTime - startTime;
+ var currentTime = Date.now();
+ var elapsedTime = currentTime - startTime;
if (elapsedTime >= spinDuration) {
- wheelElement.css('transform', `rotate(${startRotation + totalRotation}deg)`);
+ wheelElement.css('transform', 'rotate(' + (startRotation + totalRotation) + 'deg)');
accumulatedRotation = (startRotation + totalRotation);
finishSpin();
return;
}
- const timeProgress = elapsedTime / spinDuration;
- const rotationProgress = easeOutCubic(timeProgress);
- const currentRotation = startRotation + (totalRotation * rotationProgress);
- wheelElement.css('transform', `rotate(${currentRotation}deg)`);
+ var timeProgress = elapsedTime / spinDuration;
+ var rotationProgress = easeOutCubic(timeProgress);
+ var currentRotation = startRotation + (totalRotation * rotationProgress);
+ wheelElement.css('transform', 'rotate(' + currentRotation + 'deg)');
- requestAnimationFrame(() => animateWheel(startTime, startRotation, totalRotation));
+ requestAnimationFrame(function() {
+ animateWheel(startTime, startRotation, totalRotation);
+ });
}
// Obdelava po koncu vrtenja
function finishSpin() {
- const prize = window.wof_spin_result.prize;
+ var prize = window.wof_spin_result.prize;
showPrizePopup(prize);
isSpinning = false;
@@ -4287,9 +4345,9 @@ jQuery(document).ready(function($) {
// Prikaz nagrade
function showPrizePopup(prize) {
- let html = `
${l10n.congratulations}
${l10n.you_won} ${prize.name}
`;
+ var html = '
' + l10n.congratulations + '
' + l10n.you_won + ' ' + prize.name + '
';
if (window.wof_spin_result.discount_code) {
- html += `
${l10n.discount_code_sent}
`;
+ html += '
' + l10n.discount_code_sent + '
';
}
resultDiv.html(html).addClass('win').fadeIn(300);
}
@@ -4323,25 +4381,33 @@ jQuery(document).ready(function($) {
window.wof_spin_result = response.data;
wheelSpins = response.data.remaining_spins;
updateSpinsCounter();
+
+ var targetAngle = response.data.degree;
+ var fullSpinsRotation = baseRotations * 360;
+ var currentAngle = accumulatedRotation % 360;
- const finalAngle = response.data.degree;
- const totalRotation = (360 * baseRotations) + finalAngle;
+ var rotationToTarget = targetAngle - currentAngle;
+ if (rotationToTarget < 0) {
+ rotationToTarget += 360;
+ }
- animateWheel(Date.now(), accumulatedRotation, totalRotation);
+ var totalRotationAmount = fullSpinsRotation + rotationToTarget;
+
+ animateWheel(Date.now(), accumulatedRotation, totalRotationAmount);
} else {
handleError(response.data.message || l10n.error);
}
},
error: function(xhr) {
- const errorMsg = xhr.responseJSON ? (xhr.responseJSON.message || l10n.error) : l10n.error;
+ var errorMsg = xhr.responseJSON ? (xhr.responseJSON.message || l10n.error) : l10n.error;
handleError(errorMsg);
}
});
});
function handleError(message) {
- resultDiv.html(`
${message}
`).addClass('error').fadeIn(300);
+ resultDiv.html('
' + message + '
').addClass('error').fadeIn(300);
isSpinning = false;
if(wheelSpins > 0){
spinButton.prop('disabled', false).text(l10n.spin_button);
@@ -6091,7 +6157,7 @@ class WheelOfFortune {
wp_enqueue_style('wheel-of-fortune-admin-css', WHEEL_OF_FORTUNE_PLUGIN_URL . 'assets/css/admin.css', [], WHEEL_OF_FORTUNE_VERSION);
wp_enqueue_script('wheel-of-fortune-admin-js', WHEEL_OF_FORTUNE_PLUGIN_URL . 'admin/js/admin.js', ['jquery'], WHEEL_OF_FORTUNE_VERSION, true);
- wp_localize_script('wheel-of-fortune-admin-js', 'wheel_admin_nonce', array('nonce' => wp_create_nonce('wheel_admin_nonce')));
+ wp_localize_script('wheel-of-fortune-admin-js', 'wheel_admin_nonce', array('_ajax_nonce' => wp_create_nonce('wheel_admin_nonce')));
wp_localize_script('wheel-of-fortune-admin-js', 'wheel_admin_i18n', [
'select_user' => __('Select a user', 'wheel-of-fortune'),
'select_user_and_spins' => __('Please select a user and enter the number of spins.', 'wheel-of-fortune'),
@@ -6187,7 +6253,7 @@ class WheelOfFortune {
if ($rotate > 90 && $rotate < 270) {
$rotate += 180;
}
- $text_paths .= "
{$prize['name']}";
+ $text_paths .= "
{$prize['name']}";
}
$defs .= '';
@@ -6209,7 +6275,7 @@ class WheelOfFortune {
}
public function ajax_get_prize_details() {
- check_ajax_referer('wheel_admin_nonce', 'nonce');
+ check_ajax_referer('wheel_admin_nonce', '_ajax_nonce');
if (!current_user_can('manage_options')) {
wp_send_json_error(['message' => __('You do not have permission to perform this action.', 'wheel-of-fortune')]);
@@ -6231,7 +6297,7 @@ class WheelOfFortune {
}
public function ajax_save_prize() {
- check_ajax_referer('wheel_admin_nonce', 'nonce');
+ check_ajax_referer('wheel_admin_nonce', '_ajax_nonce');
if (!current_user_can('manage_options')) {
wp_send_json_error(['message' => __('You do not have permission to perform this action.', 'wheel-of-fortune')]);
@@ -6295,7 +6361,7 @@ class WheelOfFortune {
}
public function ajax_delete_prize() {
- check_ajax_referer('wheel_admin_nonce', 'nonce');
+ check_ajax_referer('wheel_admin_nonce', '_ajax_nonce');
if (!current_user_can('manage_options')) {
wp_send_json_error(['message' => __('You do not have permission to perform this action.', 'wheel-of-fortune')]);
diff --git a/export_code.sh b/export_code.sh
old mode 100644
new mode 100755
diff --git a/wheel-of-fortune.php b/wheel-of-fortune.php
index 5036c92..4ce746e 100644
--- a/wheel-of-fortune.php
+++ b/wheel-of-fortune.php
@@ -296,6 +296,7 @@ class WheelOfFortune {
id mediumint(9) NOT NULL AUTO_INCREMENT,
name varchar(255) NOT NULL,
slug varchar(100) NOT NULL,
+ has_daily_spin tinyint(1) NOT NULL DEFAULT 0,
created_at datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
PRIMARY KEY (id),
UNIQUE KEY slug (slug)
@@ -319,6 +320,7 @@ class WheelOfFortune {
name varchar(255) NOT NULL,
description text DEFAULT '',
probability float NOT NULL,
+ daily_spin_probability float DEFAULT NULL,
is_active tinyint(1) NOT NULL DEFAULT 1,
image_url varchar(255) DEFAULT '',
email_subject varchar(255) DEFAULT '',
@@ -576,29 +578,65 @@ class WheelOfFortune {
}
$wheel_id = $request->get_param('wheel_id');
+ $spin_type = $request->get_param('spin_type') === 'daily' ? 'daily' : 'paid'; // NOVO
+
if (empty($wheel_id)) {
return new WP_Error('no_wheel_id', __('Wheel ID is missing.', 'wheel-of-fortune'), ['status' => 400]);
}
global $wpdb;
- $spins_table = $wpdb->prefix . 'wheel_spins';
- $user_spins = $wpdb->get_row($wpdb->prepare("SELECT spins_available FROM $spins_table WHERE user_id = %d AND wheel_id = %d", $user_id, $wheel_id));
- $spins = $user_spins ? intval($user_spins->spins_available) : 0;
-
- if ($spins <= 0) {
- return new WP_Error('no_spins', __('You have no spins left.', 'wheel-of-fortune'), ['status' => 403]);
+ $wheels_table = $wpdb->prefix . 'wof_wheels';
+ $wheel_data = $wpdb->get_row($wpdb->prepare("SELECT has_daily_spin FROM $wheels_table WHERE id = %d", $wheel_id), ARRAY_A);
+
+ $spins_left = 0;
+ $is_eligible_for_daily = false;
+
+ // Preverjanje za DNEVNI SPIN
+ if ($spin_type === 'daily') {
+ if (!empty($wheel_data) && $wheel_data['has_daily_spin']) {
+ $last_spin_meta_key = '_wof_last_daily_spin_' . $wheel_id;
+ $last_spin_timestamp = get_user_meta($user_id, $last_spin_meta_key, true);
+
+ if (empty($last_spin_timestamp) || strtotime('today') > $last_spin_timestamp) {
+ $is_eligible_for_daily = true;
+ }
+ }
+ if (!$is_eligible_for_daily) {
+ return new WP_Error('daily_spin_used', __('You have already used your free daily spin today.', 'wheel-of-fortune'), ['status' => 403]);
+ }
+ }
+ // Preverjanje za PLAČAN SPIN
+ else {
+ $spins_table = $wpdb->prefix . 'wheel_spins';
+ $user_spins = $wpdb->get_row($wpdb->prepare("SELECT spins_available FROM $spins_table WHERE user_id = %d AND wheel_id = %d", $user_id, $wheel_id));
+ $spins_left = $user_spins ? intval($user_spins->spins_available) : 0;
+
+ if ($spins_left <= 0) {
+ return new WP_Error('no_spins', __('You have no spins left.', 'wheel-of-fortune'), ['status' => 403]);
+ }
}
- $prizes = $this->get_wheel_prizes($wheel_id);
+ // Nadaljuj z logiko vrtenja
+ $prizes = $this->get_wheel_prizes($wheel_id, $is_eligible_for_daily);
if (empty($prizes)) {
return new WP_Error('no_prizes', __('No prizes available.', 'wheel-of-fortune'), ['status' => 500]);
}
- // Uporabi delujočo logiko za izbiro nagrade
$prize = $this->select_random_prize($prizes);
- $new_spins = $spins - 1;
- $wpdb->update($spins_table, ['spins_available' => $new_spins, 'last_spin_date' => current_time('mysql')], ['user_id' => $user_id, 'wheel_id' => $wheel_id]);
+ // Zmanjšaj spine ali zabeleži dnevni spin
+ if ($spin_type === 'daily') {
+ $last_spin_meta_key = '_wof_last_daily_spin_' . $wheel_id;
+ update_user_meta($user_id, $last_spin_meta_key, time());
+ // Pridobimo trenutno število spinov za response
+ $spins_table = $wpdb->prefix . 'wheel_spins';
+ $user_spins_obj = $wpdb->get_row($wpdb->prepare("SELECT spins_available FROM $spins_table WHERE user_id = %d AND wheel_id = %d", $user_id, $wheel_id));
+ $new_spins = $user_spins_obj ? intval($user_spins_obj->spins_available) : 0;
+ } else {
+ $new_spins = $spins_left - 1;
+ $spins_table = $wpdb->prefix . 'wheel_spins';
+ $wpdb->update($spins_table, ['spins_available' => $new_spins, 'last_spin_date' => current_time('mysql')], ['user_id' => $user_id, 'wheel_id' => $wheel_id]);
+ }
$log_table = $wpdb->prefix . 'wheel_log';
$wpdb->insert($log_table, ['user_id' => $user_id, 'wheel_id' => $wheel_id, 'prize_id' => $prize['id'], 'spin_date' => current_time('mysql'), 'redeemed' => 0]);
@@ -625,15 +663,33 @@ class WheelOfFortune {
$this->send_prize_email($user_id, $prize);
}
- $response_data = [ 'prize' => $prize, 'degree' => $degree, 'remaining_spins' => $new_spins, 'discount_code' => $redemption_code ];
+ $response_data = [
+ 'prize' => $prize,
+ 'degree' => $degree,
+ 'remaining_spins' => $new_spins,
+ 'discount_code' => $redemption_code,
+ 'spin_type' => $spin_type
+ ];
return new WP_REST_Response(['success' => true, 'data' => $response_data], 200);
}
- public function get_wheel_prizes($wheel_id = 1) {
+ public function get_wheel_prizes($wheel_id = 1, $is_daily_spin = false) {
global $wpdb;
$table_name = $wpdb->prefix . 'wheel_prizes';
- return $wpdb->get_results($wpdb->prepare("SELECT * FROM $table_name WHERE wheel_id = %d AND is_active = 1 ORDER BY id ASC", $wheel_id), ARRAY_A);
+ $prizes = $wpdb->get_results($wpdb->prepare("SELECT * FROM $table_name WHERE wheel_id = %d AND is_active = 1 ORDER BY id ASC", $wheel_id), ARRAY_A);
+
+ if ($is_daily_spin) {
+ foreach ($prizes as &$prize) {
+ // Če je daily_spin_probability nastavljena, jo uporabi. Sicer uporabi standardno.
+ if (isset($prize['daily_spin_probability']) && $prize['daily_spin_probability'] !== null) {
+ $prize['probability'] = $prize['daily_spin_probability'];
+ }
+ }
+ unset($prize); // Prekini referenco
+ }
+
+ return $prizes;
}
private function select_random_prize($prizes) {
@@ -739,11 +795,23 @@ class WheelOfFortune {
$spins_left = $wpdb->get_var($wpdb->prepare("SELECT spins_available FROM $spins_table WHERE user_id = %d AND wheel_id = %d", $user_id, $wheel_id));
$spins_left = ($spins_left === null) ? 0 : (int)$spins_left;
+ // Preveri, ali je dnevni spin na voljo
+ $daily_spin_available = false;
+ if (isset($wheel['has_daily_spin']) && $wheel['has_daily_spin']) {
+ $last_spin_meta_key = '_wof_last_daily_spin_' . $wheel_id;
+ $last_spin_timestamp = get_user_meta($user_id, $last_spin_meta_key, true);
+
+ if (empty($last_spin_timestamp) || strtotime('today') > $last_spin_timestamp) {
+ $daily_spin_available = true;
+ }
+ }
+
// Definiramo polje za prevode, da bo dostopno v PHP in JS
$l10n = [
'spin_button' => __('SPIN', 'wheel-of-fortune'),
'spinning' => __('Spinning...', 'wheel-of-fortune'),
'no_spins_left' => __('No More Spins', 'wheel-of-fortune'),
+ 'free_daily_spin' => __('FREE DAILY SPIN', 'wheel-of-fortune'),
'congratulations' => __('Congratulations!', 'wheel-of-fortune'),
'you_won' => __('You won:', 'wheel-of-fortune'),
'close' => __('Close', 'wheel-of-fortune'),
@@ -757,6 +825,7 @@ class WheelOfFortune {
'nonce' => wp_create_nonce('wp_rest'),
'wheel_id' => $wheel_id,
'spins_left' => $spins_left,
+ 'daily_spin_available' => $daily_spin_available,
'prizes' => $prizes,
'l10n' => $l10n // Uporabimo definirano polje
));
@@ -930,6 +999,7 @@ class WheelOfFortune {
$name = isset($_POST['name']) ? sanitize_text_field($_POST['name']) : '';
$description = isset($_POST['description']) ? sanitize_textarea_field($_POST['description']) : '';
$probability = isset($_POST['probability']) ? floatval($_POST['probability']) : 0;
+ $daily_spin_probability = isset($_POST['daily_spin_probability']) && $_POST['daily_spin_probability'] !== '' ? floatval($_POST['daily_spin_probability']) : null;
$is_active = isset($_POST['is_active']) ? intval($_POST['is_active']) : 0;
$redemption_code = isset($_POST['redemption_code']) ? sanitize_text_field($_POST['redemption_code']) : '';
$is_discount = isset($_POST['is_discount']) ? intval($_POST['is_discount']) : 0;
@@ -949,6 +1019,10 @@ class WheelOfFortune {
wp_send_json_error(['message' => __('Probability must be between 0 and 1.', 'wheel-of-fortune')]);
}
+ if ($daily_spin_probability !== null && ($daily_spin_probability < 0 || $daily_spin_probability > 1)) {
+ wp_send_json_error(['message' => __('Daily spin probability must be between 0 and 1.', 'wheel-of-fortune')]);
+ }
+
global $wpdb;
$table_name = $wpdb->prefix . 'wheel_prizes';
@@ -957,6 +1031,7 @@ class WheelOfFortune {
'name' => $name,
'description' => $description,
'probability' => $probability,
+ 'daily_spin_probability' => $daily_spin_probability,
'is_active' => $is_active,
'redemption_code' => $redemption_code,
'is_discount' => $is_discount,
@@ -965,7 +1040,7 @@ class WheelOfFortune {
'discount_value' => $discount_value,
];
- $format = ['%d', '%s', '%s', '%f', '%d', '%s', '%d', '%s', '%s', '%f'];
+ $format = ['%d', '%s', '%s', '%f', '%f', '%d', '%s', '%d', '%s', '%s', '%f'];
if ($prize_id > 0) {
$result = $wpdb->update($table_name, $data, ['id' => $prize_id], $format, ['%d']);