Пример #1
0
    {
        $this->hasOne('Test', array('local' => 'test_id', 'foreign' => 'id'));
    }
}
$column = new sfDoctrineColumn('name', Doctrine::getTable('Test'));
$t->is($column->getName(), 'name');
$t->is($column->getFieldName(), 'name');
$t->is($column->getPhpName(), 'name');
$t->is($column->isNotNull(), true);
$column = new sfDoctrineColumn('test', Doctrine::getTable('Test'));
$t->is($column->getName(), 'test');
$t->is($column->getFieldName(), 'TEST');
$t->is($column->getPhpName(), 'TEST');
$t->is($column->getDoctrineType(), 'string');
$t->is($column->getType(), 'VARCHAR');
$t->is($column->getLength(), 255);
$t->is($column->getSize(), 255);
$t->is($column->hasDefinitionKey('length'), true);
$t->is($column->getDefinitionKey('type'), 'string');
$t->is($column->isNotNull(), false);
// Is not null and has definition key
$column = new sfDoctrineColumn('email', Doctrine::getTable('Test'));
$t->is($column->isNotNull(), true);
$t->is($column->hasDefinitionKey('email'), true);
$t->is($column->getDefinitionKey('email'), true);
// Is primary key
$column = new sfDoctrineColumn('id', Doctrine::getTable('Test'));
$t->is($column->isPrimaryKey(), true);
// Relation/foreign key functions
$column = new sfDoctrineColumn('test_id', Doctrine::getTable('TestRelation'));
$t->is($column->isForeignKey(), true);
 /**
  * Returns a sfWidgetForm class name for a given column.
  *
  * @param  sfDoctrineColumn $column
  * @return string    The name of a subclass of sfWidgetForm
  */
 public function getWidgetClassForColumn($column)
 {
     switch ($column->getDoctrineType()) {
         case 'string':
             $widgetSubclass = null === $column->getLength() || $column->getLength() > 255 ? 'Textarea' : 'InputText';
             break;
         case 'boolean':
             $widgetSubclass = 'InputCheckbox';
             break;
         case 'blob':
         case 'clob':
             $widgetSubclass = 'Textarea';
             break;
         case 'date':
             $widgetSubclass = 'Date';
             break;
         case 'time':
             $widgetSubclass = 'Time';
             break;
         case 'timestamp':
             $widgetSubclass = 'DateTime';
             break;
         case 'enum':
             $widgetSubclass = 'Choice';
             break;
         default:
             $widgetSubclass = 'InputText';
     }
     if ($column->isPrimaryKey()) {
         $widgetSubclass = 'InputHidden';
     } else {
         if ($column->isForeignKey()) {
             $widgetSubclass = 'DoctrineChoice';
         }
     }
     return sprintf('sfWidgetForm%s', $widgetSubclass);
 }
Пример #3
0
 /**
  * Returns a sfWidgetForm class name for a given column.
  *
  * @param  sfDoctrineColumn $column
  * @return string    The name of a subclass of sfWidgetForm
  */
 public function getWidgetClassForColumn($column)
 {
     if ($column instanceof sfDoctrineColumn) {
         switch ($column->getDoctrineType()) {
             case 'string':
                 $widgetSubclass = null === $column->getLength() || $column->getLength() > 255 ? 'Textarea' : 'InputText';
                 break;
             case 'boolean':
                 $widgetSubclass = 'InputCheckbox';
                 break;
             case 'blob':
             case 'clob':
                 $widgetSubclass = 'Textarea';
                 break;
             case 'date':
                 $widgetSubclass = 'DmDate';
                 break;
             case 'time':
                 $widgetSubclass = 'Time';
                 break;
             case 'timestamp':
                 $widgetSubclass = 'DateTime';
                 break;
             case 'enum':
                 $widgetSubclass = 'Choice';
                 break;
             default:
                 $widgetSubclass = 'InputText';
         }
     }
     if ($column instanceof sfDoctrineColumn && $column->isPrimaryKey()) {
         $widgetSubclass = 'InputHidden';
     } else {
         if ($column instanceof sfDoctrineColumn && $column->isForeignKey() || $column instanceof Doctrine_Relation_LocalKey) {
             if ($this->table->isPaginatedColumn($column instanceof sfDoctrineColumn ? $column->getName() : $column['local'])) {
                 $widgetSubclass = 'DmPaginatedDoctrineChoice';
             } else {
                 $widgetSubclass = 'DmDoctrineChoice';
             }
         }
     }
     //listeners are expecting an sfDoctrineColumn instance
     //thanks to Yoann BRIEUX
     if ($column instanceof Doctrine_Relation_LocalKey) {
         $column = new sfDoctrineColumn($column['local'], $this->table);
     }
     $widgetSubclass = $this->getGeneratorManager()->getConfiguration()->getEventDispatcher()->filter(new sfEvent($this, 'dm.form_generator.widget_subclass', array('column' => $column)), $widgetSubclass)->getReturnValue();
     return sprintf('sfWidgetForm%s', $widgetSubclass);
 }
 /**
  * Returns a sfWidgetForm class name for a given column.
  *
  * @param  sfDoctrineColumn $column
  * @return string    The name of a subclass of sfWidgetForm
  */
 public function getWidgetClassForColumn($column)
 {
     switch ($column->getDoctrineType()) {
         case 'string':
             $widgetSubclass = null === $column->getLength() || $column->getLength() > 255 ? 'Textarea' : 'InputText';
             break;
         case 'boolean':
             $widgetSubclass = 'InputCheckbox';
             break;
         case 'blob':
         case 'clob':
             $widgetSubclass = 'Textarea';
             break;
         case 'date':
             $widgetSubclass = 'DmDate';
             break;
         case 'time':
             $widgetSubclass = 'Time';
             break;
         case 'timestamp':
             $widgetSubclass = 'DateTime';
             break;
         case 'enum':
             $widgetSubclass = 'Choice';
             break;
         default:
             $widgetSubclass = 'InputText';
     }
     if ($column->isPrimaryKey()) {
         $widgetSubclass = 'InputHidden';
     } else {
         if ($column->isForeignKey()) {
             $widgetSubclass = 'DoctrineChoice';
         }
     }
     $widgetSubclass = $this->getGeneratorManager()->getConfiguration()->getEventDispatcher()->filter(new sfEvent($this, 'dm.form_generator.widget_subclass', array('column' => $column)), $widgetSubclass)->getReturnValue();
     return sprintf('sfWidgetForm%s', $widgetSubclass);
 }
 /**
  * Get widget class for column
  * 
  * @param   sfDoctrineColumn    $column
  * @return  string  Name of widget class
  */
 public function getWidgetClassForColumn($column)
 {
     $type = $column->getDoctrineType();
     $default = isset($this->widgetClasses[$type]) ? $this->widgetClasses[$type] : 'sfWidgetFormInputText';
     if ($type == 'string' && (is_null($column->getLength()) || $column->getLength() > 255)) {
         $default = 'sfWidgetFormTextarea';
     }
     $name = $this->config->getFormWidgetClass($this->modelName, $column->getName(), $type, $default);
     if ($column->isPrimaryKey()) {
         $name = 'sfWidgetFormInputHidden';
     } else {
         if ($column->isForeignKey()) {
             $name = 'sfWidgetFormDoctrineChoice';
         }
     }
     $name = $this->config->getFormWidgetClass($this->modelName, $column->getName(), $type, $name, true);
     return $name;
 }