|
- <?php
-
- namespace Biukop;
-
- class NdisPrice{
- private $html = '';
- private $ndis_table;
- private $tos =[];
- public function __construct(int $year=2019) {
- global $wpdb;
-
- if ( $year == "2019"){
- $now = new \DateTime();
- $year = (int)($now->format("Y"));
- }
-
-
- $this->ndis_table = $wpdb->prefix . 'acare_ndis_price';
- $sql = "SELECT * FROM {$this->ndis_table} WHERE year=$year"; //for this year
- $results = $wpdb->get_results($sql);
-
- $this->tos =[];
- $html = ' <select>';
- foreach($results as $r){
- $this->tos[$r->code] = $r;
-
- $html .= sprintf('<option value="%s" data-level="%d" data-year="%d" data-unit="%s" data-price="%.2f" data-ot="%s">%.2f - %s %s %s</option>',
- $r->code,
- $r->level,
- (int) $r->year,
- $r->unit,
- (float) $r->price,
- $r->ot,
- (float) $r->price,
- $r->name,
- $this->get_level((int) $r->level),
- $r->ot
- );//end of sprintf
- }
- $html .=' </select>';
- $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($ndis_code)
- {
- //return $this->tos[$ndis_code]->name;
- foreach ($this->tos as $r){
- if ($ndis_code == $r->code)
- return $r->name;
- }
- return "";
- }
-
- public function get_tos_full_str($ndis_code)
- {
- foreach ($this->tos as $r){
- if ($ndis_code == $r->code){
- 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($ndis_code)
- {
- foreach ($this->tos as $r){
- if ($ndis_code == $r->code)
- return (float) $r->price;
- }
- return 0;
- }
-
- public function get_tos_unit($ndis_code)
- {
- foreach ($this->tos as $r){
- if ($ndis_code == $r->code)
- return $r->unit;
- }
- return "";
- }
-
- public function get_tos_array()
- {
- foreach ($this->tos as $r){
- $r->tos_full_str = sprintf("%.2f - %s %s %s",
- (float) $r->price,
- $r->name,
- $this->get_level((int) $r->level),
- $r->ot);
- }
- return $this->tos;
- }
- }
|