label.inc.php 2.0 KB

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