summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/Model/Metadata.php24
-rw-r--r--app/Model/ProjectMetadata.php11
-rw-r--r--app/Model/TaskMetadata.php11
-rw-r--r--app/Model/UserMetadata.php11
4 files changed, 42 insertions, 15 deletions
diff --git a/app/Model/Metadata.php b/app/Model/Metadata.php
index 01799a40..52f6b009 100644
--- a/app/Model/Metadata.php
+++ b/app/Model/Metadata.php
@@ -11,6 +11,15 @@ namespace Kanboard\Model;
abstract class Metadata extends Base
{
/**
+ * Get the table
+ *
+ * @abstract
+ * @access protected
+ * @return string
+ */
+ abstract protected function getTable();
+
+ /**
* Define the entity key
*
* @abstract
@@ -29,7 +38,7 @@ abstract class Metadata extends Base
public function getAll($entity_id)
{
return $this->db
- ->hashtable(static::TABLE)
+ ->hashtable($this->getTable())
->eq($this->getEntityKey(), $entity_id)
->asc('name')
->getAll('name', 'value');
@@ -47,7 +56,7 @@ abstract class Metadata extends Base
public function get($entity_id, $name, $default = '')
{
return $this->db
- ->table(static::TABLE)
+ ->table($this->getTable())
->eq($this->getEntityKey(), $entity_id)
->eq('name', $name)
->findOneColumn('value') ?: $default;
@@ -64,7 +73,7 @@ abstract class Metadata extends Base
public function exists($entity_id, $name)
{
return $this->db
- ->table(static::TABLE)
+ ->table($this->getTable())
->eq($this->getEntityKey(), $entity_id)
->eq('name', $name)
->exists();
@@ -88,7 +97,7 @@ abstract class Metadata extends Base
foreach ($values as $key => $value) {
if ($this->exists($entity_id, $key)) {
- $results[] = $this->db->table(static::TABLE)
+ $results[] = $this->db->table($this->getTable())
->eq($this->getEntityKey(), $entity_id)
->eq('name', $key)->update(array(
'value' => $value,
@@ -96,7 +105,7 @@ abstract class Metadata extends Base
'changed_by' => $user_id,
));
} else {
- $results[] = $this->db->table(static::TABLE)->insert(array(
+ $results[] = $this->db->table($this->getTable())->insert(array(
'name' => $key,
'value' => $value,
$this->getEntityKey() => $entity_id,
@@ -120,6 +129,9 @@ abstract class Metadata extends Base
*/
public function remove($entity_id, $name)
{
- return $this->db->table(static::TABLE)->eq($this->getEntityKey(), $entity_id)->eq('name', $name)->remove();
+ return $this->db->table($this->getTable())
+ ->eq($this->getEntityKey(), $entity_id)
+ ->eq('name', $name)
+ ->remove();
}
}
diff --git a/app/Model/ProjectMetadata.php b/app/Model/ProjectMetadata.php
index 256f5e1f..2b3aadf5 100644
--- a/app/Model/ProjectMetadata.php
+++ b/app/Model/ProjectMetadata.php
@@ -11,11 +11,16 @@ namespace Kanboard\Model;
class ProjectMetadata extends Metadata
{
/**
- * SQL table name
+ * Get the table
*
- * @var string
+ * @abstract
+ * @access protected
+ * @return string
*/
- const TABLE = 'project_has_metadata';
+ protected function getTable()
+ {
+ return 'project_has_metadata';
+ }
/**
* Define the entity key
diff --git a/app/Model/TaskMetadata.php b/app/Model/TaskMetadata.php
index 1fd18415..d9d024bf 100644
--- a/app/Model/TaskMetadata.php
+++ b/app/Model/TaskMetadata.php
@@ -11,11 +11,16 @@ namespace Kanboard\Model;
class TaskMetadata extends Metadata
{
/**
- * SQL table name
+ * Get the table
*
- * @var string
+ * @abstract
+ * @access protected
+ * @return string
*/
- const TABLE = 'task_has_metadata';
+ protected function getTable()
+ {
+ return 'task_has_metadata';
+ }
/**
* Define the entity key
diff --git a/app/Model/UserMetadata.php b/app/Model/UserMetadata.php
index 411837bd..8b880756 100644
--- a/app/Model/UserMetadata.php
+++ b/app/Model/UserMetadata.php
@@ -11,11 +11,16 @@ namespace Kanboard\Model;
class UserMetadata extends Metadata
{
/**
- * SQL table name
+ * Get the table
*
- * @var string
+ * @abstract
+ * @access protected
+ * @return string
*/
- const TABLE = 'user_has_metadata';
+ protected function getTable()
+ {
+ return 'user_has_metadata';
+ }
/**
* Define the entity key