HEX
Server: Apache/2.4.59 (Debian)
System: Linux keymana 4.19.0-21-cloud-amd64 #1 SMP Debian 4.19.249-2 (2022-06-30) x86_64
User: lijunjie (1003)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/uileague/wp-content/themes/uileague/helper/team_meta.php
<?php
class TeamMetaHelper
{
    public static $pb_table = "orm_team_meta";

    const KEY_P = "p";  // 完賽
    const KEY_W = "w";  // 勝
    const KEY_D = "d";  // 平
    const KEY_L = "l";  // 負
    const KEY_F = "f";  // 入球
    const KEY_A = "a";  // 失球

    public static function get_pts($team_id)
    {
        $arr = array(
            self::KEY_P => (int)self::get_value($team_id, self::KEY_P, '0'),
            self::KEY_W => (int)self::get_value($team_id, self::KEY_W, '0'),
            self::KEY_D => (int)self::get_value($team_id, self::KEY_D, '0'),
            self::KEY_L => (int)self::get_value($team_id, self::KEY_L, '0'),
            self::KEY_F => (int)self::get_value($team_id, self::KEY_F, '0'),
            self::KEY_A => (int)self::get_value($team_id, self::KEY_A, '0'),
        );
        $arr['pts'] = 3 * $arr[self::KEY_W] + $arr[self::KEY_D];
        return $arr;
    }

    public static function get($team_id, $meta_key)
    {
        global $wpdb;
        $row = $wpdb->get_row($wpdb->prepare("select * from `" . self::$pb_table . "` where team_id = %d and meta_key = %s", $team_id, $meta_key));
        return $row;
    }

    public static function get_value($team_id, $meta_key, $default_value = "")
    {
        $row = self::get($team_id, $meta_key);
        return $row == null ? $default_value : $row->meta_value;
    }

    public static function update_value($team_id, $meta_key, $meta_value)
    {
        global $wpdb;
        $row = self::get($team_id, $meta_key);
        if ($row == null) {
            $res = $wpdb->insert(
                self::$pb_table,
                array(
                    'team_id' => $team_id,
                    'meta_key' => $meta_key,
                    'meta_value' => $meta_value,
                    'created' => current_time('mysql'),
                    'updated' => current_time('mysql'),
                ),
                array('%d', '%s', '%s', '%s', '%s'),
            );
        } else {
            $res = $wpdb->update(
                self::$pb_table,
                array(
                    'meta_value' => $meta_value,
                    'updated' => current_time('mysql'),
                ),
                array('team_id' => $team_id, 'meta_key' => $meta_key),
                array('%s', '%s'),
                array('%d', '%s'),
            );
        }
        return $res !== false;
    }
}