Porzadki po refaktorze
This commit is contained in:
@@ -23,13 +23,23 @@ function mystat_equipment_page() {
|
||||
|
||||
if ( ! empty( $data['name'] ) ) {
|
||||
if ( $item_id > 0 ) { // Update
|
||||
$wpdb->update( $table_equipment, $data, array( 'id' => $item_id ) );
|
||||
$result = $wpdb->update( $table_equipment, $data, array( 'id' => $item_id ) );
|
||||
if ( false !== $result ) {
|
||||
$message = 'Sprzęt zaktualizowany.';
|
||||
$notice_class = 'notice-success';
|
||||
} else {
|
||||
$message = 'Błąd podczas aktualizacji sprzętu: ' . $wpdb->last_error;
|
||||
$notice_class = 'notice-error';
|
||||
}
|
||||
} else { // Insert
|
||||
$wpdb->insert( $table_equipment, $data );
|
||||
$result = $wpdb->insert( $table_equipment, $data );
|
||||
if ( false !== $result ) {
|
||||
$message = 'Sprzęt dodany.';
|
||||
$notice_class = 'notice-success';
|
||||
} else {
|
||||
$message = 'Błąd podczas dodawania sprzętu: ' . $wpdb->last_error;
|
||||
$notice_class = 'notice-error';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$message = 'Nazwa sprzętu nie może być pusta.';
|
||||
@@ -63,28 +73,22 @@ function mystat_equipment_page() {
|
||||
}
|
||||
|
||||
$table_activities = $wpdb->prefix . 'mystat_activities';
|
||||
$equipment_list = $wpdb->get_results(
|
||||
"
|
||||
$equipment_list = $wpdb->get_results("
|
||||
SELECT
|
||||
eq.*,
|
||||
stats.total_distance,
|
||||
stats.total_seconds,
|
||||
stats.activity_count
|
||||
eq.id,
|
||||
eq.name,
|
||||
eq.type,
|
||||
eq.status,
|
||||
SUM(a.distance) as total_distance,
|
||||
COUNT(a.id) as activity_count
|
||||
FROM
|
||||
{$table_equipment} eq
|
||||
LEFT JOIN (
|
||||
SELECT
|
||||
equipment_id,
|
||||
SUM(distance) as total_distance,
|
||||
SUM(TIME_TO_SEC(duration)) as total_seconds,
|
||||
COUNT(id) as activity_count
|
||||
FROM
|
||||
{$table_activities}
|
||||
WHERE equipment_id IS NOT NULL
|
||||
LEFT JOIN
|
||||
{$table_activities} a ON eq.id = a.equipment_id
|
||||
GROUP BY
|
||||
equipment_id
|
||||
) as stats ON eq.id = stats.equipment_id
|
||||
ORDER BY eq.status ASC, eq.name ASC "
|
||||
eq.id, eq.name, eq.type, eq.status
|
||||
ORDER BY
|
||||
eq.status ASC, eq.name ASC"
|
||||
);
|
||||
?>
|
||||
<div class="wrap">
|
||||
|
||||
Reference in New Issue
Block a user