コード例 #1
0
$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);
$t->is($column->getForeignClassName(), 'Test');
$t->is($column->getForeignTable()->getOption('name'), 'Test');
$t->is($column->getTable()->getOption('name'), 'TestRelation');
// Array access
$t->is($column['type'], 'integer');
コード例 #2
0
 /**
  * Returns a PHP string representing options to pass to a widget for a given column.
  *
  * @param  sfDoctrineColumn $column
  * @return string    The options to pass to the widget as a PHP string
  */
 public function getWidgetOptionsForColumn($column)
 {
     $options = array();
     $withEmpty = sprintf('\'with_empty\' => %s', $column->isNotNull() ? 'false' : 'true');
     switch ($column->getDoctrineType()) {
         case 'boolean':
             $options[] = "'choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no')";
             break;
         case 'date':
         case 'datetime':
         case 'timestamp':
             $options[] = "'from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate()";
             $options[] = $withEmpty;
             break;
         case 'enum':
             $values = array('' => '');
             $values = array_merge($values, $column['values']);
             $values = array_combine($values, $values);
             $options[] = "'choices' => " . str_replace("\n", '', $this->arrayExport($values));
             break;
     }
     if ($column->isForeignKey()) {
         $options[] = sprintf('\'model\' => \'%s\', \'add_empty\' => true', $column->getForeignTable()->getOption('name'));
     }
     return count($options) ? sprintf('array(%s)', implode(', ', $options)) : '';
 }
コード例 #3
0
 /**
  * Returns a PHP string representing options to pass to a widget for a given column.
  *
  * @param  sfDoctrineColumn $column
  * @return string    The options to pass to the widget as a PHP string
  */
 public function getWidgetOptionsForColumn($column)
 {
     $options = array();
     $withEmpty = $column->isNotNull() && !$column->isForeignKey() ? array("'with_empty' => false") : array();
     switch ($column->getDoctrineType()) {
         case 'boolean':
             $options[] = "'choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no')";
             break;
         case 'date':
         case 'datetime':
         case 'timestamp':
             $options[] = "'from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate()";
             $options = array_merge($options, $withEmpty);
             break;
         case 'enum':
             $values = array('' => '');
             $values = array_merge($values, $column['values']);
             $values = array_combine($values, $values);
             $options[] = "'choices' => " . $this->arrayExport($values);
             break;
         default:
             $options = array_merge($options, $withEmpty);
     }
     if ($column->isForeignKey()) {
         $options[] = sprintf('\'model\' => $this->getRelatedModelName(\'%s\'), \'add_empty\' => true', $column->getRelationKey('alias'));
     }
     return count($options) ? sprintf('array(%s)', implode(', ', $options)) : '';
 }
コード例 #4
0
 /**
  * Returns a PHP string representing options to pass to a validator for a given column.
  *
  * @param sfDoctrineColumn $column
  * @return string    The options to pass to the validator as a PHP string
  */
 public function getValidatorOptionsForColumn($column)
 {
     $options = array();
     if ($column->isForeignKey()) {
         $options[] = sprintf('\'model\' => $this->getRelatedModelName(\'%s\')', $column->getRelationKey('alias'));
     } else {
         if ($column->isPrimaryKey()) {
             $options[] = sprintf('\'choices\' => array($this->getObject()->get(\'%s\')), \'empty_value\' => $this->getObject()->get(\'%1$s\')', $column->getFieldName());
         } else {
             switch ($column->getDoctrineType()) {
                 case 'string':
                     if ($column['length']) {
                         $options[] = sprintf('\'max_length\' => %s', $column['length']);
                     }
                     if (isset($column['minlength'])) {
                         $options[] = sprintf('\'min_length\' => %s', $column['minlength']);
                     }
                     if (isset($column['regexp'])) {
                         $options[] = sprintf('\'pattern\' => \'%s\'', $column['regexp']);
                     }
                     break;
                 case 'enum':
                     $options[] = '\'choices\' => ' . $this->arrayExport($column['values']);
                     break;
             }
         }
     }
     // If notnull = false, is a primary or the column has a default value then
     // make the widget not required
     if (!$column->isNotNull() || $column->isPrimaryKey() || $column->hasDefinitionKey('default')) {
         $options[] = '\'required\' => false';
     }
     return count($options) ? sprintf('array(%s)', implode(', ', $options)) : '';
 }
コード例 #5
0
 /**
  * Returns a PHP string representing options to pass to a validator for a given column.
  *
  * @param sfDoctrineColumn $column
  * @return string    The options to pass to the validator as a PHP string
  */
 public function getValidatorOptionsForColumn($column)
 {
     $options = array();
     $isForeignKey = $column->isForeignKey();
     $requiresEm = $isForeignKey || $column->isPrimaryKey();
     if ($isForeignKey) {
         $options[] = sprintf('\'model\' => \'%s\'', $column->getForeignMetadata()->name);
     } else {
         if ($column->isPrimaryKey()) {
             $options[] = sprintf('\'model\' => \'%s\', \'column\' => \'%s\'', $this->modelName, $column->getName());
         } else {
             switch ($column->getDoctrineType()) {
                 case 'string':
                     if ($column['length']) {
                         $options[] = sprintf('\'max_length\' => %s', $column['length']);
                     }
                     if (isset($column['minlength'])) {
                         $options[] = sprintf('\'min_length\' => %s', $column['minlength']);
                     }
                     if (isset($column['regexp'])) {
                         $options[] = sprintf('\'pattern\' => \'%s\'', $column['regexp']);
                     }
                     break;
                 case 'enum':
                     $values = array_combine($column['values'], $column['values']);
                     $options[] = "'choices' => " . str_replace("\n", '', $this->arrayExport($values));
                     break;
             }
         }
     }
     // If notnull = false, is a primary or the column has a default value then
     // make the widget not required
     if (!$column->isNotNull() || $column->isPrimaryKey() || $column->hasDefinitionKey('default')) {
         $options[] = '\'required\' => false';
     }
     return ($requiresEm ? '$this->em, ' : '') . (count($options) ? sprintf('array(%s)', implode(', ', $options)) : '');
 }
コード例 #6
0
 /**
  * Returns a PHP string representing options to pass to a widget for a given column.
  *
  * @param sfDoctrineColumn $column
  *
  * @return string The options to pass to the widget as a PHP string
  */
 public function getWidgetOptionsForColumn($column)
 {
     $options = array();
     if ($column->isForeignKey()) {
         $options[] = sprintf('\'model\' => $this->getRelatedModelName(\'%s\'), \'add_empty\' => %s', $column->getRelationKey('alias'), $column->isNotNull() ? 'false' : 'true');
     } else {
         if ('enum' == $column->getDoctrineType() && is_subclass_of($this->getWidgetClassForColumn($column), 'sfWidgetFormChoiceBase')) {
             $options[] = '\'choices\' => ' . $this->arrayExport(array_combine($column['values'], $column['values']));
         }
     }
     return count($options) ? sprintf('array(%s)', implode(', ', $options)) : '';
 }
 /**
  * Returns a PHP string representing options to pass to a widget for a given column
  * 
  * @param   sfDoctrineColumn    $column
  * @param   integer             $indent Indentation value [optional]
  * @return  string  The options to pass to the widget as a PHP string
  */
 public function getWidgetOptionsForColumn($column, $indent = 0)
 {
     $type = $column->getDoctrineType();
     $default = isset($this->widgetOptions[$type]) ? $this->widgetOptions[$type] : array();
     $options = $column->isNotNull() && !$column->isForeignKey() && !in_array($type, array('boolean', 'enum')) ? array('with_empty' => 'false') : array();
     if (!$options && !$column->isForeignKey() && !in_array($type, array('boolean', 'enum'))) {
         $options['empty_label'] = "'labels.isEmpty'";
         $options['template'] = "'%input% <div class=\"sf-filter-empty\">%empty_checkbox% %empty_label%</div>'";
     }
     if ($type == 'enum') {
         $values = array_merge(array('' => ''), $column['values']);
         $values = array_combine($values, $values);
         $options['choices'] = $this->arrayExport($values);
     }
     $camName = sfInflector::camelize($column->getName());
     $options['label'] = "'formLabels." . strtolower(substr($camName, 0, 1)) . substr($camName, 1) . "'";
     $options = array_merge($options, $this->config->getFilterWidgetOptions($this->modelName, $column->getName(), $type, $default));
     if ($column->isForeignKey()) {
         $options['model'] = '$this->getRelatedModelName( \'' . $column->getRelationKey('alias') . "' )";
         $options['add_empty'] = 'true';
         $options['min'] = null;
         $options['max'] = null;
     }
     $out = array();
     $ni = str_repeat(' ', $indent);
     foreach ($options as $k => $v) {
         if (!is_null($v)) {
             $out[] = $ni . "    '" . $k . "' => " . $v;
         }
     }
     return count($out) ? " array(\n" . implode(",\n", $out) . "\n" . $ni . ") " : '';
 }
コード例 #8
0
 /**
  * Returns a PHP string representing options to pass to a validator for a given column.
  *
  * @param sfDoctrineColumn $column
  * @return string    The options to pass to the validator as a PHP string
  */
 public function getValidatorOptionsForColumn($column)
 {
     $options = array();
     if ($column->isForeignKey()) {
         $options[] = sprintf('\'model\' => \'%s\'', $column->getForeignTable()->getOption('name'));
     } else {
         if ($column->isPrimaryKey()) {
             $options[] = sprintf('\'model\' => \'%s\', \'column\' => \'%s\'', $this->modelName, $column->getName());
         } else {
             switch ($column->getDoctrineType()) {
                 case 'string':
                     if ($column['length']) {
                         $options[] = sprintf('\'max_length\' => %s', $column['length']);
                     }
                     if (isset($column['minlength'])) {
                         $options[] = sprintf('\'min_length\' => %s', $column['minlength']);
                     }
                     if (isset($column['regexp'])) {
                         $options[] = sprintf('\'pattern\' => \'%s\'', $column['regexp']);
                     }
                     break;
                 case 'enum':
                     $values = array_combine($column['values'], $column['values']);
                     $options[] = "'choices' => " . str_replace("\n", '', $this->arrayExport($values));
                     break;
             }
         }
     }
     if (!$column->isNotNull() || $column->isPrimaryKey()) {
         $options[] = '\'required\' => false';
     }
     return count($options) ? sprintf('array(%s)', implode(', ', $options)) : '';
 }
コード例 #9
0
 /**
  * Get validator options for column
  * 
  * @param   sfDoctrineColumn    $column
  * @param   integer             $indent Indentation value [optional]
  * @return  string  The options to pass to the validator as a PHP string
  */
 public function getValidatorOptionsForColumn($column, $indent = 0)
 {
     $type = $column->getDoctrineType();
     $options = array();
     if ($column->isForeignKey()) {
         $options['model'] = "\$this->getRelatedModelName( '" . $column->getRelationKey('alias') . "' )";
     } else {
         if ($column->isPrimaryKey()) {
             $options['choices'] = "array( \$this->getObject()->get( '" . $column->getFieldName() . "' ) )";
             $options['empty_value'] = "\$this->getObject()->get( '" . $column->getFieldName() . "' )";
         } else {
             if ($type == 'string') {
                 if ($column['length']) {
                     $options['max_length'] = $column['length'];
                 }
                 if (isset($column['minlength'])) {
                     $options['min_length'] = $column['minlength'];
                 }
                 if (isset($column['regexp'])) {
                     $options['pattern'] = "'" . $column['regexp'] . "'";
                 }
             } else {
                 if ($type == 'enum') {
                     $options['choices'] = $this->arrayExport($column['values']);
                 }
             }
         }
     }
     if (!$column->isNotNull() || $column->isPrimaryKey() || $column->hasDefinitionKey('default')) {
         $options['required'] = 'false';
         if (!$column->isNotNull() && !$column->isPrimaryKey()) {
             $options['empty_value'] = 'null';
         }
     }
     $options = array_merge($options, $this->config->getFormValidatorOptions($this->modelName, $column->getName(), $type, array()));
     $out = array();
     $ni = str_repeat(' ', $indent);
     foreach ($options as $k => $v) {
         if (!is_null($v)) {
             $out[] = $ni . "    '" . $k . "' => " . $v;
         }
     }
     return count($out) ? " array(\n" . implode(",\n", $out) . "\n" . $ni . ") " : '';
 }