public static function dump_field_unique_values_multi($table, $field, $selected = false)
{
if (!$selected) {
$selected = array();
}
echo '<option value="">- Select default values -</option>';
if (!($_table = Yii::app()->db->getSchema()->getTable($table))) {
throw new Exception("Table not found: {$table}");
}
if (!isset($_table->columns[$field])) {
throw new Exception("{$table} has no attribute '{$field}'");
}
if (in_array($table, array('user', 'audit', 'authitem', 'authitem_type', 'authitemchild'))) {
throw new Exception('Refusing to allow retrieval of dangerous table');
}
$command = Yii::app()->db->createCommand()->selectDistinct("{$table}.id, {$table}.{$field}")->from($table)->order("{$table}.{$field}");
if ($_table->hasProperty('deleted')) {
$command->where("{$table}.deleted = 0");
}
foreach ($command->queryAll() as $row) {
if (!in_array($row['id'], $selected)) {
echo '<option value="' . $row['id'] . '">' . $row[$field] . '</option>';
}
}
}