summaryrefslogtreecommitdiff
path: root/app/Model/Metadata.php
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-05-11 18:45:54 -0400
committerFrederic Guillot <fred@kanboard.net>2016-05-11 18:45:54 -0400
commit5479e38b608cf20a7e620fa34e6f1e6850e83866 (patch)
tree5a7120e5dfd4f851ab632daf6ec27c6784c654b2 /app/Model/Metadata.php
parent3387ea3dbe1f8adb7aaece0cd29abb711d427e85 (diff)
Replace static::TABLE by a new abstract method
Diffstat (limited to 'app/Model/Metadata.php')
-rw-r--r--app/Model/Metadata.php24
1 files changed, 18 insertions, 6 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();
}
}