| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- <?php
- class Label {
- private $id = NULL;
- private $name = '';
- private $path = '';
- public function __construct($id, $name, $path) {
- $this->id = $id;
- $this->name = $name;
- $this->path = $path;
- }
- public function getId() {
- return $this->id;
- }
- public function getName() {
- return $this->name;
- }
- public function getPath() {
- return $this->path;
- }
- /**
- * Get all Labels
- *
- *
- * @return Array(Label) Array with all Labels
- *
- */
- public static function getAllLabels() {
- global $db;
- $return = array();
- $labels = $db->selectQuery("SELECT * FROM `labels`;");
- foreach($labels as $label) {
- $return[] = new Label($label->id, $label->name, $label->path);
- }
- return $return;
- }
- /**
- * Get a Label by ID
- *
- *
- * @param int $labelId Label ID
- *
- * @return Label Selected Label object
- *
- */
- public static function getLabelById($labelId) {
- global $db;
- $return = array();
- $labels = $db->selectQuery("SELECT * FROM `labels` WHERE `id` = " . $labelId . ";");
- foreach($labels as $label) {
- $return[] = new Label($label->id, $label->name, $label->path);
- }
- if(sizeof($return) > 1) {
- //TODO: Error handling!
- }
- return $return[0];
- }
- /**
- * Get a Label by FS-path
- *
- *
- * @param string $path path, relative to ~/documents-folder
- *
- * @return Label Selected Label
- *
- */
- public static function getLabelByPath($path) {
- global $db;
- $return = array();
- $labels = $db->selectQuery("SELECT * FROM `labels` WHERE `path` = '" . $path . "';");
- foreach($labels as $label) {
- $return[] = new Label($label->id, $label->name, $label->path);
- }
- if(sizeof($return) > 1) {
- // TODO: Error handling!
- }
- return $return[0];
- }
- /**
- * Add new Label to DB
- *
- * @param type $name description
- *
- * @return type the integer of the set mode used. FALSE if foo
- *
- */
- public static function addLabel($name, $path) {
- global $db;
- $db->insertQuery("INSERT INTO `labels`(`name`, `path`) VALUES ('" . $name . "', '" . $path . "')");
- }
- }
- ?>
|