Listing 13.21. Metoda insertIfNotExists() klasy matryca
public static function insertIfNotExists($str)
{
    $q = Doctrine_Query::create()
        ->from('Matryca m')
        ->where('m.nazwa = ?', $str);
    $obj = $q->fetchOne();
    if (!$obj) {
        $obj = new Matryca();
        $obj['nazwa'] = $str;
        $obj['slug'] = string2slug($str);
        $obj->save();
    }
    return $obj;
}
