timesheet source code
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

64 lines
1.7KB

  1. <?php
  2. namespace Biukop;
  3. class NdisPrice{
  4. private $html = '';
  5. private $ndis_table;
  6. private $tos =[];
  7. public function __construct(int $year=2019) {
  8. global $wpdb;
  9. $this->ndis_table = $wpdb->prefix . 'acare_ndis_price';
  10. $sql = "SELECT * FROM {$this->ndis_table} WHERE year=$year"; //for this year
  11. $results = $wpdb->get_results($sql);
  12. $this->tos =[];
  13. $html = ' <select>';
  14. foreach($results as $r){
  15. $this->tos[] = $r;
  16. $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>',
  17. $r->code,
  18. $r->level,
  19. (int) $r->year,
  20. $r->unit,
  21. (float) $r->price,
  22. $r->ot,
  23. (float) $r->price,
  24. $r->name,
  25. $this->get_level((int) $r->level),
  26. $r->ot
  27. );//end of sprintf
  28. }
  29. $html .=' </select>';
  30. $this->html = $html;
  31. }
  32. private function get_level($level_number){
  33. $levelStr = array(
  34. 0 => '(standard)',
  35. -1 => '', //no level number needed
  36. 1 => '(Level 1)',
  37. 2 => '(Level 2)',
  38. 3 => '(Level 3)'
  39. );
  40. if ( array_key_exists($level_number, $levelStr) )
  41. return $levelStr[$level_number];
  42. else
  43. return '';
  44. }
  45. public function get_html()
  46. {
  47. return $this->html;
  48. }
  49. public function get_tos_str($ndis_code)
  50. {
  51. foreach ($this->tos as $r){
  52. if ($ndis_code == $r->code)
  53. return $r->name;
  54. }
  55. return "";
  56. }
  57. }