public function execute(&$value, &$error) { $className = $this->getParameter('class'); $columnName = $className . '.' . $this->getParameter('column'); $primaryKeys = sfDoctrine::getTable($className)->getPrimaryKeys(); foreach ($primaryKeys as $primaryKey) { if (is_null($primaryKeyValue = $this->getContext()->getRequest()->getParameter($primaryKey))) { } break; } $query = new Doctrine_Query(); $query->from($className); $value = strtolower($value); if ($primaryKeyValue === null) { $query->where($columnName . ' = ?'); $res = $query->execute(array($value)); } else { $query->where($columnName . ' = ? AND ' . $primaryKey . ' != ?'); $res = $query->execute(array($value, $primaryKeyValue)); } if (sizeof($res)) { $error = $this->getParameterHolder()->get('unique_error'); return false; } return true; }
public static function retrieveObjects($class, $peer_method = 'findAll') { if (!$peer_method) { $peer_method = 'findAll'; } $table = sfDoctrine::getTable($class); return call_user_func(array($table, $peer_method)); }
public static function doSave($msg, $culture) { $obj = sfDoctrine::getTable('Message')->find($culture); if ($obj) { $obj->set('message', $msg); try { $obj->save(); return true; } catch (Exception $e) { return false; } } else { return false; } }
public static function find($id) { return sfDoctrine::getTable('RouteI18nArchive')->find($id); }
public static function find($id) { return sfDoctrine::getTable('PortalArchive')->find($id); }
/** * dumpData * * @param mixed $directory_or_file * @param string $tables * @param string $connectionName * @access public * @return void */ public function dumpData($directory_or_file = null, $tables = 'all', $connectionName = 'propel') { $sameFile = true; if (is_dir($directory_or_file)) { // multi files $sameFile = false; } else { // same file // delete file } $manager = Doctrine_Manager::getInstance(); $con = $manager->getCurrentConnection(); // get tables if ('all' === $tables || null === $tables) { $modelDirectories = array(); $modelDirectories[] = sfConfig::get('sf_model_lib_dir') . '/doctrine'; $directories = sfFinder::type('dir')->maxdepth(0)->in(sfConfig::get('sf_model_lib_dir') . '/doctrine'); foreach ($directories as $directory) { if (strstr($directory, 'generated')) { continue; } $modelDirectories[] = $directory; } $tables = array(); foreach ($modelDirectories as $directory) { $dirTables = sfFinder::type('file')->name('/(?<!Table)\\.class.php$/')->maxdepth(0)->in($directory); foreach ($dirTables as $key => $table) { $table = basename($table, '.class.php'); $tables[] = $table; } } } else { if (!is_array($tables)) { $tables = array($tables); } } $dumpData = array(); foreach ($tables as $modelName) { $table = sfDoctrine::getTable($modelName, $this->connectionName); // get table name $tableName = $table->getTableName(); $relations = $table->getRelations(); // get columns $columns = $con->fetchAll('DESCRIBE ' . $tableName); // get records //$records = $con->fetchAll('SELECT * FROM '.$tableName); $query = new Doctrine_Query(); $query->from($modelName); $records = $query->execute(); $dumpData[$modelName] = array(); foreach ($records as $record) { $pk = $modelName; $values = array(); foreach ($columns as $column) { $col = strtolower($column['Field']); try { $initialValue = $record[$col]; } catch (Exception $e) { continue; } if (!$initialValue) { continue; } if ($column['Key'] == 'PRI') { $pk .= '_' . $initialValue; } else { $isForeignKey = false; foreach ($relations as $relation) { if ($relation->getLocal() == $col) { $isForeignKey = true; break; } } if ($isForeignKey) { $array = $relation->toArray(); $values[$relation->getAlias()] = $array['class'] . '_' . $initialValue; } else { $value = $initialValue; // Needed to maintain bool values if (is_bool($value)) { $value = $value ? 1 : 0; } $values[$col] = $value; } } } $dumpData[$modelName][$pk] = $values; } } // save to file(s) if ($sameFile) { $yaml = Spyc::YAMLDump($dumpData); file_put_contents($directory_or_file, $yaml); } else { foreach ($dumpData as $table => $data) { $yaml = Spyc::YAMLDump($data); file_put_contents($directory_or_file . "/{$table}.yml", $yaml); } } }
/** * Save prefered language list in user session and bdd * * @param array ordered language list * @author Mickael Kurmann **/ public function savePreferedLanguageList($language_list) { // save in session $this->saveLanguageListInSession($language_list); // save it too in database if user connected if ($this->isConnected()) { $user_private_data = sfDoctrine::getTable('UserPrivateData')->find($this->getId()); $user_private_data->setPreferedLanguageList($language_list); $user_private_data->save(); } }
public static function findIn($model, $ids, $fields = null) { if (!is_array($ids)) { $ids = array($ids); } if (is_array($fields)) { $select_string = 'd.' . implode(', d.', $fields); return Doctrine_Query::create()->select($select_string)->from($model . ' d')->where('id IN (' . implode(',', $ids) . ')')->execute(); } else { return sfDoctrine::getTable($model)->findByDql('id IN (' . implode(',', $ids) . ')'); } }
public static function find($id) { return sfDoctrine::getTable('HistoryMetadata')->find($id); }
public static function find($id) { return sfDoctrine::getTable('UserPrivateData')->find($id); }