From cd5ab2b8b61a66b32d37f3755526a88bf13f1cf9 Mon Sep 17 00:00:00 2001 From: Jacek Pyziak Date: Mon, 26 Jan 2026 23:40:20 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20Dodaj=20funkcjonalno=C5=9B=C4=87=20usuw?= =?UTF-8?q?ania=20komentarzy=20oraz=20wy=C5=9Bwietlanie=20ich=20w=20histor?= =?UTF-8?q?ii=20produkt=C3=B3w?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- autoload/controls/class.Products.php | 23 ++++++++ autoload/factory/class.Products.php | 14 ++++- templates/products/product_history.php | 72 ++++++++++++++++++++++++-- 3 files changed, 104 insertions(+), 5 deletions(-) diff --git a/autoload/controls/class.Products.php b/autoload/controls/class.Products.php index 3ca467e..06eb92d 100644 --- a/autoload/controls/class.Products.php +++ b/autoload/controls/class.Products.php @@ -51,6 +51,19 @@ class Products exit; } + static public function comment_delete() + { + $comment_id = \S::get( 'comment_id' ); + + if ( \factory\Products::delete_product_comment( $comment_id ) ) + { + echo json_encode( [ 'status' => 'ok' ] ); + } + else + echo json_encode( [ 'status' => 'error' ] ); + exit; + } + static public function get_product_data() { $product_id = \S::get( 'product_id' ); @@ -255,6 +268,15 @@ class Products $roas_value = ( $row['cost'] > 0) ? ( $row['conversions_value'] / $row['cost'] ) * 100 : 0; $roas = number_format( $roas_value, 0, '.', '' ) . '%'; + $comment_data = \factory\Products::get_product_comment_by_date( $product_id, $row['date_add'] ); + $comment_html = ''; + if ( $comment_data ) + { + $comment_html = '
+ ' . htmlspecialchars( $comment_data['comment'] ) . ' + Usuń +
'; + } $data['data'][] = [ $row['id'], @@ -266,6 +288,7 @@ class Products \S::number_display( $row['conversions_value'] ), $roas, $row['date_add'], + $comment_html, ]; } diff --git a/autoload/factory/class.Products.php b/autoload/factory/class.Products.php index 267ecaa..7e46e44 100644 --- a/autoload/factory/class.Products.php +++ b/autoload/factory/class.Products.php @@ -11,7 +11,19 @@ class Products static public function get_product_comments( $product_id ) { global $mdb; - return $mdb -> query( 'SELECT comment, date_add FROM products_comments WHERE product_id = \'' . $product_id . '\' ORDER BY date_add DESC' ) -> fetchAll( \PDO::FETCH_ASSOC ); + return $mdb -> query( 'SELECT id, comment, date_add FROM products_comments WHERE product_id = \'' . $product_id . '\' ORDER BY date_add DESC' ) -> fetchAll( \PDO::FETCH_ASSOC ); + } + + static public function delete_product_comment( $comment_id ) + { + global $mdb; + return $mdb -> delete( 'products_comments', [ 'id' => $comment_id ] ); + } + + static public function get_product_comment_by_date( $product_id, $date ) + { + global $mdb; + return $mdb -> get( 'products_comments', [ 'id', 'comment' ], [ 'AND' => [ 'product_id' => $product_id, 'date_add' => $date ] ] ); } static public function get_min_roas( $product_id ) diff --git a/templates/products/product_history.php b/templates/products/product_history.php index 8cedc79..11266a8 100644 --- a/templates/products/product_history.php +++ b/templates/products/product_history.php @@ -42,6 +42,7 @@ Wartość konwersji ROAS Data + Komentarz @@ -90,6 +91,7 @@ { width: '175px', name: 'conversions_value', className: "dt-type-numeric" }, { width: '100px', name: 'roas', className: "dt-type-numeric", orderable: false }, { width: '100px', name: 'date_add' }, + { width: '250px', name: 'comment', orderable: false }, ], order: [[0, false],[8, 'desc']] }); @@ -157,10 +159,10 @@ }) }, false); - // 2) Dodaj „niewidzialne” markery do hovera + // 2) Dodaj „niewidzialne" markery do hovera var points = (parsedData.comments || []).map(function(c) { var idx = parsedData.dates.indexOf((c.date_add || '').split(' ')[0]); - return { x: idx, y: 0, comment: c.comment }; + return { x: idx, y: 0, comment: c.comment, comment_id: c.id }; }); chart.addSeries({ @@ -177,12 +179,43 @@ enabled: true, radius: 4, lineWidth: 0, - fillOpacity: 0 // marker „niewidoczny” + fillOpacity: 0 // marker „niewidoczny" }, states: { hover: { enabled: true, halo: { size: 5 } } }, - enableMouseTracking: true + enableMouseTracking: true, + cursor: 'pointer', + point: { + events: { + click: function () { + var commentId = this.comment_id; + var commentText = this.comment; + + if (confirm('Czy na pewno chcesz usunąć komentarz: "' + commentText + '"?')) { + $.ajax({ + url: '/products/comment_delete/', + method: 'POST', + data: { + comment_id: commentId + }, + success: function(res) { + res = JSON.parse(res); + if (res.status === 'ok') { + location.reload(); + } else { + alert('Nie udało się usunąć komentarza. Spróbuj ponownie.'); + } + }, + error: function(jqXHR, textStatus, errorThrown) { + console.error('Błąd usuwania komentarza:', textStatus, errorThrown); + alert('Nie udało się usunąć komentarza. Spróbuj ponownie.'); + } + }); + } + } + } + } }, false); chart.redraw(); @@ -282,5 +315,36 @@ } }); }); + + // OBSŁUGA USUWANIA KOMENTARZA Z TABELI + $(document).on('click', '.delete-comment', function(e) { + e.preventDefault(); + + var comment_id = $(this).data('comment-id'); + + if (!confirm('Czy na pewno chcesz usunąć ten komentarz?')) { + return; + } + + $.ajax({ + url: '/products/comment_delete/', + method: 'POST', + data: { + comment_id: comment_id + }, + success: function(res) { + res = JSON.parse(res); + if (res.status === 'ok') { + location.reload(); + } else { + alert('Nie udało się usunąć komentarza. Spróbuj ponownie.'); + } + }, + error: function(jqXHR, textStatus, errorThrown) { + console.error('Błąd usuwania komentarza:', textStatus, errorThrown); + alert('Nie udało się usunąć komentarza. Spróbuj ponownie.'); + } + }); + }); });