Skip to content

Instantly share code, notes, and snippets.

@donpinkster
Created April 22, 2010 08:14
Show Gist options
  • Save donpinkster/374960 to your computer and use it in GitHub Desktop.
Save donpinkster/374960 to your computer and use it in GitHub Desktop.
<?php
class sfMessageSource_Doctrine extends sfMessageSource
{
public function &loadData($variant)
{
$rows = Doctrine_Query::create()
->from('TransUnit t')
->leftJoin('t.Catalogue c')
->where('c.name=?', $variant)
->select('t.id, t.source, t.target')
->execute(null, Doctrine_Core::HYDRATE_ARRAY);
$results = array();
foreach($rows as $row)
{
$source = $row['source'];
$results[$source][] = $row['target'];
$results[$source][] = $row['id'];
}
return $results;
}
public function catalogues()
{
$catalogues = Doctrine_Query::create()
->from('Catalogue c')
->select('c.name')
->execute(null, Doctrine_Core::HYDRATE_ARRAY);
$result = array();
foreach ($catalogues as $catalogue)
{
$details = explode('.', $catalogue['name']);
if (!isset($details[1]))
{
$details[1] = null;
}
$result[] = $details;
}
return $result;
}
public function isValidSource($variant)
{
return (Doctrine_Query::create()
->from('Catalogue c')
->where('c.name=?', $variant)
->count() > 0);
}
public function getCatalogueList($catalogue)
{
$variants = explode('_', $this->culture);
$catalogues = array($catalogue);
$variant = null;
for ($i = 0, $max = count($variants); $i < $max; $i++)
{
if (strlen($variants[$i]) > 0)
{
$variant .= $variant ? '_'.$variants[$i] : $variants[$i];
$catalogues[] = $catalogue.'.'.$variant;
}
}
return array_reverse($catalogues);
}
public function getId()
{
return md5($this->source);
}
public function save($catalogue = 'messages')
{
}
public function append($message)
{
}
public function update($text, $target, $comments, $catalogue = 'messages')
{
}
public function delete($message, $catalogue = 'messages')
{
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment