public function setValue($source, array $destinations)
{
if (is_numeric($source)) {
$row = $this->fetchRow($this->select(array('id' => $source)));
if (empty($row)) {
return false;
}
$sourceId = $row['id'];
} else {
$row = $this->fetchRow($this->select(array('source' => $source)));
if (!empty($row)) {
$sourceId = $row['id'];
} else {
$this->insert(array('source' => $source));
$sourceId = $this->getLastInsertId();
}
}
foreach ($destinations as $destination) {
if (empty($destination['locale']) or empty($destination['value'])) {
continue;
}
$select = new Select();
$select->from('core_translate_locale');
$select->where->equalTo('locale', $destination['locale']);
$select->where->equalTo('core_translate_id', $sourceId);
$row = $this->fetchRow($select);
if (!empty($row)) {
$destination['dst_id'] = $row['id'];
}
if (!empty($destination['dst_id'])) {
$update = new Update('core_translate_locale');
$update->set(array('destination' => $destination['value'], 'locale' => $destination['locale']));
$update->where->equalTo('id', $destination['dst_id']);
$this->execute($update);
} else {
$insert = new Insert();
$insert->into('core_translate_locale')->values(array('destination' => $destination['value'], 'locale' => $destination['locale'], 'core_translate_id' => $sourceId));
$this->execute($insert);
}
}
return true;
}