diff --git a/html/media/addedit_metadata.html b/html/media/addedit_metadata.html
index fc56dea0..249b2755 100644
--- a/html/media/addedit_metadata.html
+++ b/html/media/addedit_metadata.html
@@ -93,4 +93,12 @@
+
+
+
\ No newline at end of file
diff --git a/html/media/metadata_addedit.html b/html/media/metadata_addedit.html
index c7f9bb4d..c50ff3e6 100644
--- a/html/media/metadata_addedit.html
+++ b/html/media/metadata_addedit.html
@@ -31,6 +31,7 @@
Tags
Media
Playlist
+ Coordinates
@@ -70,6 +71,7 @@
+
diff --git a/models/mediametadata_model.php b/models/mediametadata_model.php
index ee70a1f7..0e7517f0 100644
--- a/models/mediametadata_model.php
+++ b/models/mediametadata_model.php
@@ -161,7 +161,7 @@ public function validate($data, $id)
}
//T The field type is not valid.
- if (array_search($data['type'], ['select','bool','text','textarea','formatted','integer','date','time','datetime','tags','hidden','media','playlist']) === false) {
+ if (array_search($data['type'], ['select','bool','text','textarea','formatted','integer','date','time','datetime','tags','hidden','media','playlist','coordinates']) === false) {
return [false,'The field type is not valid.'];
}
@@ -254,6 +254,35 @@ public function save($data, $id)
} elseif ($save['type'] === 'playlist') {
$this->db->query('ALTER TABLE ' . $this->db->format_backticks('media') . ' ADD ' . $this->db->format_backticks('metadata_' . $data['name']) . ' INT UNSIGNED NULL DEFAULT NULL');
$this->db->query('ALTER TABLE ' . $this->db->format_backticks('media') . ' ADD CONSTRAINT ' . $this->db->format_backticks('fk_media_metadata_' . $data['name']) . ' FOREIGN KEY (' . $this->db->format_backticks('metadata_' . $data['name']) . ') REFERENCES ' . $this->db->format_backticks('playlists') . ' (' . $this->db->format_backticks('id') . ') ON UPDATE CASCADE ON DELETE SET NULL');
+ } elseif ($save['type'] === 'coordinates') {
+ $this->db->query('ALTER TABLE ' . $this->db->format_backticks('media') . ' ADD ' . $this->db->format_backticks('metadata_' . $data['name']) . ' POINT NULL DEFAULT NULL');
+ // TODO: Use triggers probably to make thsi actually convert to POINT(x y) format.
+ // Assumes field is named 'point' in example for testing.
+ // Need to replace before_insert_metadata_point, NEW.metadata_point, etc with actual field name.
+ /*$this->db->query("
+DELIMITER //
+
+CREATE TRIGGER before_insert_metadata_point
+BEFORE INSERT ON media
+FOR EACH ROW
+BEGIN
+ DECLARE x DECIMAL(10, 6);
+ DECLARE y DECIMAL(10, 6);
+
+ -- Split the coordinate_string into x and y
+ SET x = CAST(SUBSTRING_INDEX(NEW.metadata_point, ',', 1) AS DECIMAL(10, 6));
+ SET y = CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(NEW.metadata_point, ',', -1), ' ', -1) AS DECIMAL(10, 6));
+
+ -- Set the coordinate_point column
+ SET NEW.metadata_point = ST_GeomFromText(CONCAT('POINT(', x, ' ', y, ')'));
+END//
+
+DELIMITER ;
+ ");*/
+ if ($err = $this->db->error()) {
+ var_dump($err);
+ die();
+ }
}
return $id;
@@ -281,6 +310,10 @@ public function delete($id)
$this->db->query('ALTER TABLE ' . $this->db->format_backticks('media') . ' DROP FOREIGN KEY ' . $this->db->format_backticks('fk_media_metadata_' . $field['name']));
}
+ if ($field['type'] === 'coordinates') {
+ $this->db->query('DROP TRIGGER before_insert_metadata_' . $field['name']);
+ }
+
$this->db->query('ALTER TABLE ' . $this->db->format_backticks('media') . ' DROP COLUMN ' . $this->db->format_backticks('metadata_' . $field['name']));
return true;