mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-04-02 06:14:51 -04:00
Address review feedback: use ternary, camelCase, remove test file
- Use ternary notation for $images assignment in getPicThumb - Refactor local variables to camelCase for PSR-12 compliance - Remove test_avatar_toggle.html from repository
This commit is contained in:
@@ -167,48 +167,45 @@ class Items extends Secure_Controller
|
||||
{
|
||||
helper('file');
|
||||
|
||||
$file_extension = pathinfo($pic_filename, PATHINFO_EXTENSION);
|
||||
$upload_path = FCPATH . 'uploads/item_pics/';
|
||||
$fileExtension = pathinfo($pic_filename, PATHINFO_EXTENSION);
|
||||
$uploadPath = FCPATH . 'uploads/item_pics/';
|
||||
|
||||
// Handle files with and without extensions
|
||||
if (empty($file_extension)) {
|
||||
$images = glob($upload_path . $pic_filename . '.*');
|
||||
} else {
|
||||
$images = glob($upload_path . $pic_filename);
|
||||
}
|
||||
$images = empty($fileExtension)
|
||||
? glob($uploadPath . $pic_filename . '.*')
|
||||
: glob($uploadPath . $pic_filename);
|
||||
|
||||
if (sizeof($images) > 0) {
|
||||
$image_path = $images[0];
|
||||
$actual_extension = pathinfo($image_path, PATHINFO_EXTENSION);
|
||||
$base_path = $upload_path . pathinfo($pic_filename, PATHINFO_FILENAME);
|
||||
$thumb_path = $base_path . "_thumb.$actual_extension";
|
||||
$imagePath = $images[0];
|
||||
$actualExtension = pathinfo($imagePath, PATHINFO_EXTENSION);
|
||||
$basePath = $uploadPath . pathinfo($pic_filename, PATHINFO_FILENAME);
|
||||
$thumbPath = $basePath . "_thumb.$actualExtension";
|
||||
|
||||
// Try to create thumbnail if it doesn't exist
|
||||
if (!file_exists($thumb_path)) {
|
||||
if (!file_exists($thumbPath)) {
|
||||
try {
|
||||
$image = Services::image('gd2');
|
||||
$image->withFile($image_path)
|
||||
$image->withFile($imagePath)
|
||||
->resize(52, 32, true, 'height')
|
||||
->save($thumb_path);
|
||||
->save($thumbPath);
|
||||
} catch (Exception $e) {
|
||||
// If thumbnail creation fails, serve original image
|
||||
log_message('error', 'Thumbnail creation failed: ' . $e->getMessage());
|
||||
$this->serveImage($image_path);
|
||||
$this->serveImage($imagePath);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Serve thumbnail if it exists, otherwise serve original
|
||||
if (file_exists($thumb_path)) {
|
||||
$this->serveImage($thumb_path);
|
||||
if (file_exists($thumbPath)) {
|
||||
$this->serveImage($thumbPath);
|
||||
} else {
|
||||
$this->serveImage($image_path);
|
||||
$this->serveImage($imagePath);
|
||||
}
|
||||
} else {
|
||||
// No image found, serve default
|
||||
$default_image = FCPATH . 'public/images/no-img.png';
|
||||
if (file_exists($default_image)) {
|
||||
$this->serveImage($default_image);
|
||||
$defaultImage = FCPATH . 'public/images/no-img.png';
|
||||
if (file_exists($defaultImage)) {
|
||||
$this->serveImage($defaultImage);
|
||||
} else {
|
||||
// Return 404 if no default image
|
||||
$this->response->setStatusCode(404);
|
||||
|
||||
@@ -464,24 +464,24 @@ function get_item_data_row(object $item): array
|
||||
|
||||
$image = '';
|
||||
if (!empty($item->pic_filename)) {
|
||||
$upload_path = FCPATH . 'uploads/item_pics/';
|
||||
$uploadPath = FCPATH . 'uploads/item_pics/';
|
||||
$ext = pathinfo($item->pic_filename, PATHINFO_EXTENSION);
|
||||
|
||||
// If no extension in filename, search for any file with that name
|
||||
if (empty($ext)) {
|
||||
$pattern = $upload_path . $item->pic_filename . '.*';
|
||||
$pattern = $uploadPath . $item->pic_filename . '.*';
|
||||
} else {
|
||||
$pattern = $upload_path . $item->pic_filename;
|
||||
$pattern = $uploadPath . $item->pic_filename;
|
||||
}
|
||||
|
||||
$images = glob($pattern);
|
||||
|
||||
if (!empty($images)) {
|
||||
$rel_path = 'uploads/item_pics/' . basename($images[0]);
|
||||
$relPath = 'uploads/item_pics/' . basename($images[0]);
|
||||
|
||||
// Use direct image path instead of getPicThumb
|
||||
$image = '<a class="rollover" href="' . base_url($rel_path) . '">
|
||||
<img src="' . base_url($rel_path) . '"
|
||||
$image = '<a class="rollover" href="' . base_url($relPath) . '">
|
||||
<img src="' . base_url($relPath) . '"
|
||||
onerror="this.src=\''.base_url('public/images/no-img.png').'\';this.onerror=null;"
|
||||
style="max-width:40px;max-height:40px; object-fit: cover;">
|
||||
</a>';
|
||||
|
||||
@@ -1,101 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Avatar Toggle Test</title>
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
|
||||
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
|
||||
crossorigin="anonymous">
|
||||
<link rel="stylesheet" href="public/css/receipt.css">
|
||||
<script src="https://code.jquery.com/jquery-3.6.0.min.js"
|
||||
integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4="
|
||||
crossorigin="anonymous"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h3>Avatar Toggle Test</h3>
|
||||
|
||||
<!-- Control buttons -->
|
||||
<div class="print_hide" id="control_buttons" style="text-align: right; margin-bottom: 20px;">
|
||||
<a href="javascript:void(0);">
|
||||
<div class="btn btn-warning btn-sm receipt-avatar-toggle-btn" id="toggle_avatar_button">
|
||||
<span class="glyphicon glyphicon-picture"> </span><span id="avatar_toggle_text">Hide Avatar</span>
|
||||
</div>
|
||||
</a>
|
||||
<a href="javascript:void(0);">
|
||||
<div class="btn btn-info btn-sm" id="show_print_button">
|
||||
<span class="glyphicon glyphicon-print"> </span>Print
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<!-- Receipt table -->
|
||||
<div id="receipt_wrapper">
|
||||
<table id="receipt_items">
|
||||
<tr>
|
||||
<th class="receipt-avatar-column" style="width: 15%;">Image</th>
|
||||
<th style="width: 40%;">Description</th>
|
||||
<th style="width: 20%;">Price</th>
|
||||
<th style="width: 20%;">Quantity</th>
|
||||
<th style="width: 20%;" class="total-value">Total</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="receipt-avatar-column">
|
||||
<img src="https://via.placeholder.com/40x40" alt="avatar" style="height:40px;max-width:40px;">
|
||||
</td>
|
||||
<td>Test Item 1</td>
|
||||
<td>$10.00</td>
|
||||
<td>2</td>
|
||||
<td class="total-value">$20.00</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="receipt-avatar-column">
|
||||
<img src="https://via.placeholder.com/40x40" alt="avatar" style="height:40px;max-width:40px;">
|
||||
</td>
|
||||
<td>Test Item 2</td>
|
||||
<td>$15.00</td>
|
||||
<td>1</td>
|
||||
<td class="total-value">$15.00</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function() {
|
||||
// Avatar toggle functionality
|
||||
const STORAGE_KEY = 'receipt_avatar_visible';
|
||||
|
||||
// Get saved state from localStorage, default to visible (true)
|
||||
let isAvatarVisible = localStorage.getItem(STORAGE_KEY) !== 'false';
|
||||
|
||||
// Apply initial state
|
||||
updateAvatarVisibility(isAvatarVisible);
|
||||
|
||||
// Handle toggle button click
|
||||
$('#toggle_avatar_button').click(function() {
|
||||
isAvatarVisible = !isAvatarVisible;
|
||||
updateAvatarVisibility(isAvatarVisible);
|
||||
localStorage.setItem(STORAGE_KEY, isAvatarVisible);
|
||||
});
|
||||
|
||||
function updateAvatarVisibility(visible) {
|
||||
const $avatarElements = $('.receipt-avatar-column');
|
||||
const $toggleButton = $('#toggle_avatar_button');
|
||||
const $toggleText = $('#avatar_toggle_text');
|
||||
|
||||
if (visible) {
|
||||
$avatarElements.removeClass('hidden');
|
||||
$toggleButton.removeClass('active');
|
||||
$toggleText.text('Hide Avatar');
|
||||
} else {
|
||||
$avatarElements.addClass('hidden');
|
||||
$toggleButton.addClass('active');
|
||||
$toggleText.text('Show Avatar');
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user