label.inc.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. class Label {
  3. private $id = NULL;
  4. private $name = '';
  5. public function __construct($id, $name) {
  6. $this->id = $id;
  7. $this->name = $name;
  8. }
  9. public function getId() {
  10. return $this->id;
  11. }
  12. public function getName() {
  13. return $this->name;
  14. }
  15. /**
  16. * Get all Labels
  17. *
  18. *
  19. * @return Array(Label) Array with all Labels
  20. *
  21. */
  22. public static function getAllLabels() {
  23. global $db;
  24. $return = array();
  25. $labels = $db->selectQuery("SELECT * FROM `labels`;");
  26. foreach($labels as $label) {
  27. $return[] = new Label($label->id, $label->name);
  28. }
  29. return $return;
  30. }
  31. /**
  32. * Get a Label by ID
  33. *
  34. *
  35. * @param int $labelId Label ID
  36. *
  37. * @return Label Selected Label object
  38. *
  39. */
  40. public static function getLabelById($labelId) {
  41. global $db;
  42. $return = array();
  43. $labels = $db->selectQuery("SELECT * FROM `labels` WHERE `id` = " . $labelId . ";");
  44. foreach($labels as $label) {
  45. $return[] = new Label($label->id, $label->name);
  46. }
  47. if(sizeof($return) > 1) {
  48. //TODO: Error handling!
  49. }
  50. return $return[0];
  51. }
  52. /**
  53. * Get a Label by FS-path
  54. *
  55. *
  56. * @param string $path path, relative to ~/documents-folder
  57. *
  58. * @return Label Selected Label
  59. *
  60. */
  61. public static function getLabelByPath($path) {
  62. global $db;
  63. $return = array();
  64. $labels = $db->selectQuery("SELECT * FROM `labels` WHERE `path` = '" . $path . "';");
  65. foreach($labels as $label) {
  66. $return[] = new Label($label->id, $label->name);
  67. }
  68. if(sizeof($return) > 1) {
  69. // TODO: Error handling!
  70. }
  71. return $return[0];
  72. }
  73. }
  74. ?>