Replace static::TABLE by a new abstract method
This commit is contained in:
@@ -10,6 +10,15 @@ namespace Kanboard\Model;
|
|||||||
*/
|
*/
|
||||||
abstract class Metadata extends Base
|
abstract class Metadata extends Base
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Get the table
|
||||||
|
*
|
||||||
|
* @abstract
|
||||||
|
* @access protected
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
abstract protected function getTable();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define the entity key
|
* Define the entity key
|
||||||
*
|
*
|
||||||
@@ -29,7 +38,7 @@ abstract class Metadata extends Base
|
|||||||
public function getAll($entity_id)
|
public function getAll($entity_id)
|
||||||
{
|
{
|
||||||
return $this->db
|
return $this->db
|
||||||
->hashtable(static::TABLE)
|
->hashtable($this->getTable())
|
||||||
->eq($this->getEntityKey(), $entity_id)
|
->eq($this->getEntityKey(), $entity_id)
|
||||||
->asc('name')
|
->asc('name')
|
||||||
->getAll('name', 'value');
|
->getAll('name', 'value');
|
||||||
@@ -47,7 +56,7 @@ abstract class Metadata extends Base
|
|||||||
public function get($entity_id, $name, $default = '')
|
public function get($entity_id, $name, $default = '')
|
||||||
{
|
{
|
||||||
return $this->db
|
return $this->db
|
||||||
->table(static::TABLE)
|
->table($this->getTable())
|
||||||
->eq($this->getEntityKey(), $entity_id)
|
->eq($this->getEntityKey(), $entity_id)
|
||||||
->eq('name', $name)
|
->eq('name', $name)
|
||||||
->findOneColumn('value') ?: $default;
|
->findOneColumn('value') ?: $default;
|
||||||
@@ -64,7 +73,7 @@ abstract class Metadata extends Base
|
|||||||
public function exists($entity_id, $name)
|
public function exists($entity_id, $name)
|
||||||
{
|
{
|
||||||
return $this->db
|
return $this->db
|
||||||
->table(static::TABLE)
|
->table($this->getTable())
|
||||||
->eq($this->getEntityKey(), $entity_id)
|
->eq($this->getEntityKey(), $entity_id)
|
||||||
->eq('name', $name)
|
->eq('name', $name)
|
||||||
->exists();
|
->exists();
|
||||||
@@ -88,7 +97,7 @@ abstract class Metadata extends Base
|
|||||||
|
|
||||||
foreach ($values as $key => $value) {
|
foreach ($values as $key => $value) {
|
||||||
if ($this->exists($entity_id, $key)) {
|
if ($this->exists($entity_id, $key)) {
|
||||||
$results[] = $this->db->table(static::TABLE)
|
$results[] = $this->db->table($this->getTable())
|
||||||
->eq($this->getEntityKey(), $entity_id)
|
->eq($this->getEntityKey(), $entity_id)
|
||||||
->eq('name', $key)->update(array(
|
->eq('name', $key)->update(array(
|
||||||
'value' => $value,
|
'value' => $value,
|
||||||
@@ -96,7 +105,7 @@ abstract class Metadata extends Base
|
|||||||
'changed_by' => $user_id,
|
'changed_by' => $user_id,
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
$results[] = $this->db->table(static::TABLE)->insert(array(
|
$results[] = $this->db->table($this->getTable())->insert(array(
|
||||||
'name' => $key,
|
'name' => $key,
|
||||||
'value' => $value,
|
'value' => $value,
|
||||||
$this->getEntityKey() => $entity_id,
|
$this->getEntityKey() => $entity_id,
|
||||||
@@ -120,6 +129,9 @@ abstract class Metadata extends Base
|
|||||||
*/
|
*/
|
||||||
public function remove($entity_id, $name)
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,11 +11,16 @@ namespace Kanboard\Model;
|
|||||||
class ProjectMetadata extends Metadata
|
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
|
* Define the entity key
|
||||||
|
|||||||
@@ -11,11 +11,16 @@ namespace Kanboard\Model;
|
|||||||
class TaskMetadata extends Metadata
|
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
|
* Define the entity key
|
||||||
|
|||||||
@@ -11,11 +11,16 @@ namespace Kanboard\Model;
|
|||||||
class UserMetadata extends Metadata
|
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
|
* Define the entity key
|
||||||
|
|||||||
Reference in New Issue
Block a user