EventTypeModuleCode::dump_field_unique_values_multi PHP Method

dump_field_unique_values_multi() public static method

public static dump_field_unique_values_multi ( $table, $field, $selected = false )
    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>';
            }
        }
    }

Usage Example

コード例 #1
0
 public function init()
 {
     $this->mode = @$_POST['EventTypeModuleMode'] ? 'update' : 'create';
     if (isset($_GET['ajax']) && preg_match('/^[a-zA-Z0-9_]+$/', $_GET['ajax'])) {
         if ($_GET['ajax'] == 'table_fields') {
             EventTypeModuleCode::dump_table_fields($_GET['table']);
         } else {
             if ($_GET['ajax'] == 'field_unique_values') {
                 EventTypeModuleCode::dump_field_unique_values($_GET['table'], $_GET['field']);
             } else {
                 if ($_GET['ajax'] == 'dump_field_unique_values_multi') {
                     EventTypeModuleCode::dump_field_unique_values_multi($_GET['table'], $_GET['field']);
                 } else {
                     if ($_GET['ajax'] == 'getEyedrawSize') {
                         EventTypeModuleCode::getEyedrawSize($_GET['class']);
                     } else {
                         if ($_GET['ajax'] == 'event_type_properties') {
                             EventTypeModuleCode::eventTypeProperties($_GET['event_type_id']);
                         } else {
                             if (file_exists("protected/gii/EventTypeModule/views/{$_GET['ajax']}.php")) {
                                 Yii::app()->getController()->renderPartial($_GET['ajax'], $_GET);
                             }
                         }
                     }
                 }
             }
         }
         Yii::app()->end();
     }
     if (!empty($_POST)) {
         $this->validate_form();
     }
     parent::init();
 }
All Usage Examples Of EventTypeModuleCode::dump_field_unique_values_multi