API refactoring

This commit is contained in:
Frederic Guillot
2015-05-23 21:44:33 -04:00
parent c9ba525bab
commit e32f26d048
24 changed files with 1519 additions and 606 deletions

View File

@@ -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;
}
/**