label.inc.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. * Get a Label by Name
  80. *
  81. *
  82. * @param string $labelName Name of wanted Label
  83. *
  84. * @return Label Selected Label
  85. *
  86. */
  87. public static function getLabelByName($labelName) {
  88. global $db;
  89. $return = array();
  90. $labels = $db->selectQuery("SELECT * FROM `labels` WHERE `name` = '" . $labelName . "';");
  91. foreach($labels as $label) {
  92. $return[] = new Label($label->id, $label->name, $label->path);
  93. }
  94. if(sizeof($return) > 1) {
  95. // TODO: Error handling!
  96. }
  97. return $return[0];
  98. }
  99. /**
  100. * Add new Label to DB
  101. *
  102. * @param string $name Name of Label
  103. * @param string $path FS-Path of Label
  104. *
  105. * @return void
  106. *
  107. */
  108. public static function addLabel($name, $path) {
  109. global $db;
  110. $db->insertQuery("INSERT INTO `labels`(`name`, `path`) VALUES ('" . $name . "', '" . $path . "')");
  111. }
  112. /**
  113. * Remove a Label by Label-ID
  114. *
  115. * @param int $labelId ID of Label
  116. *
  117. * @return void
  118. *
  119. */
  120. public static function removeLabel($labelId) {
  121. global $db;
  122. $db->removeQuery("DELETE FROM `labels` WHERE `id` = " . $labelId . ";");
  123. }
  124. }
  125. ?>