API refactoring
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user