/**
  * Returns a PHP string representing options to pass to a widget for a given column.
  *
  * @param  ColumnMap $column  A ColumnMap object
  *
  * @return string    The options to pass to the widget as a PHP string
  */
 public function getWidgetOptionsForColumn(ColumnMap $column)
 {
     $options = array();
     $withEmpty = $column->isNotNull() && !$column->isForeignKey() ? array("'with_empty' => false") : array();
     switch ($column->getType()) {
         case PropelColumnTypes::BOOLEAN:
         case PropelColumnTypes::BOOLEAN_EMU:
             $options[] = "'choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no')";
             break;
         case PropelColumnTypes::DATE:
         case PropelColumnTypes::TIME:
         case PropelColumnTypes::TIMESTAMP:
             $options[] = "'from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate()";
             $options = array_merge($options, $withEmpty);
             break;
         case PropelColumnTypes::ENUM:
             $valueSet = $column->getValueSet();
             $choices = array_merge(array('' => 'all'), $valueSet);
             $options[] = sprintf("'choices' => %s", preg_replace('/\\s+/', '', var_export($choices, true)));
             break;
         default:
             $options = array_merge($options, $withEmpty);
     }
     if ($column->isForeignKey()) {
         $options[] = sprintf('\'model\' => \'%s\', \'add_empty\' => true', $this->getForeignTable($column)->getClassname());
         $refColumn = $this->getForeignTable($column)->getColumn($column->getRelatedColumnName());
         if (!$refColumn->isPrimaryKey()) {
             $options[] = sprintf('\'key_method\' => \'get%s\'', $refColumn->getPhpName());
         }
     }
     return count($options) ? sprintf('array(%s)', implode(', ', $options)) : '';
 }
Esempio n. 2
0
 protected static function _getColumnRawValue(ColumnMap $column, $value)
 {
     if ($value === null) {
         return null;
     }
     switch ($column->getType()) {
         case PropelColumnTypes::ENUM:
             $valueSet = $column->getValueSet();
             return array_search($value, $valueSet);
         case PropelColumnTypes::PHP_ARRAY:
             return '| ' . implode(' | ', $value) . ' |';
         case PropelColumnTypes::OBJECT:
             return serialize($value);
     }
     return $value;
 }