| | <?php |
| |
|
| | namespace Kanboard\Model; |
| |
|
| | use Kanboard\Core\Base; |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | abstract class MetadataModel extends Base |
| | { |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | abstract protected function getTable(); |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | abstract protected function getEntityKey(); |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | public function getAll($entity_id) |
| | { |
| | return $this->db |
| | ->hashtable($this->getTable()) |
| | ->eq($this->getEntityKey(), $entity_id) |
| | ->asc('name') |
| | ->getAll('name', 'value'); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | public function get($entity_id, $name, $default = '') |
| | { |
| | return $this->db |
| | ->table($this->getTable()) |
| | ->eq($this->getEntityKey(), $entity_id) |
| | ->eq('name', $name) |
| | ->findOneColumn('value') ?: $default; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | public function exists($entity_id, $name) |
| | { |
| | return $this->db |
| | ->table($this->getTable()) |
| | ->eq($this->getEntityKey(), $entity_id) |
| | ->eq('name', $name) |
| | ->exists(); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | public function save($entity_id, array $values) |
| | { |
| | $results = array(); |
| | $user_id = $this->userSession->getId(); |
| | $timestamp = time(); |
| |
|
| | $this->db->startTransaction(); |
| |
|
| | foreach ($values as $key => $value) { |
| | if ($this->exists($entity_id, $key)) { |
| | $results[] = $this->db->table($this->getTable()) |
| | ->eq($this->getEntityKey(), $entity_id) |
| | ->eq('name', $key) |
| | ->update(array( |
| | 'value' => $value, |
| | 'changed_on' => $timestamp, |
| | 'changed_by' => $user_id, |
| | )); |
| | } else { |
| | $results[] = $this->db->table($this->getTable())->insert(array( |
| | 'name' => $key, |
| | 'value' => $value, |
| | $this->getEntityKey() => $entity_id, |
| | 'changed_on' => $timestamp, |
| | 'changed_by' => $user_id, |
| | )); |
| | } |
| | } |
| |
|
| | $this->db->closeTransaction(); |
| | return ! in_array(false, $results, true); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | public function remove($entity_id, $name) |
| | { |
| | return $this->db->table($this->getTable()) |
| | ->eq($this->getEntityKey(), $entity_id) |
| | ->eq('name', $name) |
| | ->remove(); |
| | } |
| | } |
| |
|