codeModel.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. class codeModel extends Staple_Model
  3. {
  4. private $db;
  5. private $id;
  6. private $name;
  7. private $multiplier;
  8. private $description;
  9. /**
  10. * @return mixed
  11. */
  12. public function getId()
  13. {
  14. return $this->id;
  15. }
  16. /**
  17. * @param mixed $id
  18. */
  19. public function setId($id)
  20. {
  21. $this->id = $id;
  22. }
  23. /**
  24. * @return mixed
  25. */
  26. public function getName()
  27. {
  28. return $this->name;
  29. }
  30. /**
  31. * @param mixed $name
  32. */
  33. public function setName($name)
  34. {
  35. $this->name = $name;
  36. }
  37. /**
  38. * @return mixed
  39. */
  40. public function getMultiplier()
  41. {
  42. return $this->multiplier;
  43. }
  44. /**
  45. * @param mixed $multiplier
  46. */
  47. public function setMultiplier($multiplier)
  48. {
  49. $this->multiplier = $multiplier;
  50. }
  51. /**
  52. * @return mixed
  53. */
  54. public function getDescription()
  55. {
  56. return $this->description;
  57. }
  58. /**
  59. * @param mixed $description
  60. */
  61. public function setDescription($description)
  62. {
  63. $this->description = $description;
  64. }
  65. function __construct()
  66. {
  67. $this->db = Staple_DB::get();
  68. }
  69. function load($id = NULL)
  70. {
  71. $sql = "SELECT * FROM timeCodes WHERE id = '" . $this->db->real_escape_string($id) . "'";
  72. if($this->db->query($sql)->fetch_row() > 0)
  73. {
  74. $query = $this->db->query($sql);
  75. $result = $query->fetch_assoc();
  76. $this->setId($result['id']);
  77. $this->setName($result['name']);
  78. $this->setMultiplier($result['multiplier']);
  79. $this->setDescription($result['description']);
  80. return true;
  81. }
  82. }
  83. function allCodes()
  84. {
  85. $auth = Staple_Auth::get();
  86. $uid = $auth->getAuthId();
  87. $user = new userModel();
  88. $user->userInfo($uid);
  89. $type = $user->getType();
  90. if($type == 'part')
  91. {
  92. $sql = "SELECT id, name FROM timeCodes WHERE type = 'part' ORDER BY listOrder ASC";
  93. }
  94. else
  95. {
  96. $sql = "SELECT id, name FROM timeCodes WHERE 1 ORDER BY listOrder ASC";
  97. }
  98. if($this->db->query($sql)->fetch_row() > 0)
  99. {
  100. $query = $this->db->query($sql);
  101. while($result = $query->fetch_assoc())
  102. {
  103. $data[$result['id']] = $result['name'];
  104. }
  105. return $data;
  106. }
  107. }
  108. function getIdFor($term = null)
  109. {
  110. if($term !== null)
  111. {
  112. $sql = "SELECT id FROM timeCodes WHERE name like '%".$this->db->real_escape_string($term)."%'";
  113. if($this->db->query($sql)->fetch_row() > 0)
  114. {
  115. $query = $this->db->query($sql);
  116. $result = $query->fetch_assoc();
  117. return $result;
  118. }
  119. }
  120. }
  121. }
  122. ?>