diff options
author | Frederic Guillot <fred@kanboard.net> | 2015-05-23 21:44:33 -0400 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2015-05-23 21:44:33 -0400 |
commit | e32f26d048249b84166542d6442efdf202ff44fd (patch) | |
tree | 1868c5e83cec5ea8b821ad8a2036543aa37e5adb /app/Model/Link.php | |
parent | c9ba525bab06eff76b1d5fb8701848d0e3990122 (diff) |
API refactoring
Diffstat (limited to 'app/Model/Link.php')
-rw-r--r-- | app/Model/Link.php | 46 |
1 files changed, 18 insertions, 28 deletions
diff --git a/app/Model/Link.php b/app/Model/Link.php index 42b8382c..b26a01e4 100644 --- a/app/Model/Link.php +++ b/app/Model/Link.php @@ -112,7 +112,7 @@ class Link extends Base * @access public * @param string $label * @param string $opposite_label - * @return boolean + * @return boolean|integer */ public function create($label, $opposite_label = '') { @@ -123,38 +123,28 @@ class Link extends Base return false; } + $label_id = $this->db->getConnection()->getLastId(); + if ($opposite_label !== '') { - $this->createOpposite($opposite_label); + + $this->db + ->table(self::TABLE) + ->insert(array( + 'label' => $opposite_label, + 'opposite_id' => $label_id, + )); + + $this->db + ->table(self::TABLE) + ->eq('id', $label_id) + ->update(array( + 'opposite_id' => $this->db->getConnection()->getLastId() + )); } $this->db->closeTransaction(); - return true; - } - - /** - * Create the opposite label (executed inside create() method) - * - * @access private - * @param string $label - */ - private function createOpposite($label) - { - $label_id = $this->db->getConnection()->getLastId(); - - $this->db - ->table(self::TABLE) - ->insert(array( - 'label' => $label, - 'opposite_id' => $label_id, - )); - - $this->db - ->table(self::TABLE) - ->eq('id', $label_id) - ->update(array( - 'opposite_id' => $this->db->getConnection()->getLastId() - )); + return $label_id; } /** |