ndis_table = $wpdb->prefix . 'acare_ndis_price'; $sql = "SELECT * FROM {$this->ndis_table} order by year desc"; //for this year $results = $wpdb->get_results($sql); $this->tos =[]; $html = ' '; $this->html = $html; } private function get_level($level_number){ $levelStr = array( 0 => '(standard)', -1 => '', //no level number needed 1 => '(Level 1)', 2 => '(Level 2)', 3 => '(Level 3)' ); if ( array_key_exists($level_number, $levelStr) ) return $levelStr[$level_number]; else return ''; } public function get_html() { return $this->html; } public function get_tos_str($tos_id) { //return $this->tos[$tos_id]->name; foreach ($this->tos as $r){ if ($tos_id == $r->id) return $r->name; } return ""; } public function get_tos_full_str($tos_id) { foreach ($this->tos as $r){ if ($tos_id == $r->id){ return sprintf("%.2f - %s %s %s", (float) $r->price, $r->name, $this->get_level((int) $r->level), $r->ot); } } return ""; } public function get_tos_price($tos_id) { foreach ($this->tos as $r){ if ($tos_id == $r->id) return (float) $r->price; } return 0; } public function get_tos_unit($tos_id) { foreach ($this->tos as $r){ if ($tos_id == $r->id) return $r->unit; } return ""; } public function get_tos_ndis_code($tos_id) { foreach ($this->tos as $r){ if ($tos_id == $r->id) return $r->code; } return ""; } public function get_tos_array() { foreach ($this->tos as $r){ $r->tos_full_str = sprintf("%.2f - %d - %s %s %s", (float) $r->price, $r->year, $r->name, $this->get_level((int) $r->level), $r->ot); } return $this->tos; } public function get_id_by_tos($ndis_code , int $year=2019) { foreach ($this->tos as $r){ if ($ndis_code == $r->code && $year == $r->year) return $r->id; } return 0; //0 = not found } }