Lang.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. require_once(PATH::ENTITY . "Entity.php");
  3. /**
  4. * Language.
  5. *
  6. * Represents an object from the table 'lang'.
  7. */
  8. class Lang extends Entity{
  9. /**
  10. * Lowercase, two-letter language code.
  11. */
  12. private $code;
  13. /**
  14. * Language name, in it's own language.
  15. */
  16. private $name;
  17. /**
  18. * Indictes wether the language is offered in this language.
  19. */
  20. private $active;
  21. /**
  22. * Constructor.
  23. *
  24. * Searches the database and retrieves the information about the
  25. * object, populating it.
  26. *
  27. * @param int $id Database identifier of the language.
  28. */
  29. public function __construct($id){
  30. $statement = get_context()->get_db()->prepare(
  31. "SELECT code, name, active FROM lang WHERE code = :id"
  32. );
  33. $statement->bindValue(':id', $id, PDO::PARAM_STR);
  34. $statement->execute();
  35. $r_lang = $statement->fetch(PDO::FETCH_ASSOC);
  36. if ($r_lang !== false){
  37. $this->code = $r_lang["code"];
  38. $this->name = $r_lang["name"];
  39. $this->active = $r_lang["active"];
  40. }
  41. }
  42. /**
  43. * Retrieves the language identifier code.
  44. *
  45. * @return int Language code.
  46. */
  47. public function get_code(){
  48. return $this->code;
  49. }
  50. /**
  51. * Retrieves the language name.
  52. *
  53. * @return int Language name.
  54. */
  55. public function get_name(){
  56. return $this->name;
  57. }
  58. /**
  59. * Checks if the language is active.
  60. *
  61. * @return bool True if the language is active, false otherwise.
  62. */
  63. public function is_active(){
  64. return $this->active;
  65. }
  66. }
  67. ?>