summaryrefslogtreecommitdiff
path: root/app/Model/Link.php
diff options
context:
space:
mode:
Diffstat (limited to 'app/Model/Link.php')
-rw-r--r--app/Model/Link.php46
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;
}
/**