_select_guts unselect_element search_inputs make_param_foreign
);
-our $VERSION = '.09';
-
-# 11-05-05 - added _to_link_hidden to make a link to the hidden object
-# - fixed _to_hidden when called with no args. Hides self obj.
-# 11-04-05 - _to_textfield: tries to call "deflate4edit" if column is has_a
-# 11-08-05 - Changed Version to .08
-
-
-
-# 1-10-06 -- fixed bug in to_textfiled that was stringifyingf CDBI objects
-# #
-#
-# 1-20-06 - to_select - call db_Main with has a class.
-# 1-24-06 - to_select_from_many now named _to_select_from_many . Old deprecated
-# - hasmany_class removed in favor of model's related_class method.
-# - took out do_select. That is a model action.
-# - use search_columns instead of search_fields now.
-# - use to_field('column', 'select', {args}) instead of a_select_box.
-# -- took out make_hidden_element.was my own personal hack
-# -- added _box from DH's FormView to calculate decent textarea size
-# -- Refactor to_field into _from_* method calls.
-#
-# 1-25-06 -- Added _to_checkbox and _to_radio from FView
-# 1-27-06 -- Refactored into yet more exported methods
-# 1-28-06 -- select constraints where, join order by
-
+our $VERSION = '2.11';
=head1 NAME
__PACKAGE__->has_a('beer', 'BeerDB::Beer');
package BeerDB::Drinker;
__PACKAGE__->has_many('pints', 'BeerDB::Pint');
-
+
# NEED to do mapping
my $sel = BeerDB::Drinker->to_field('pints', 'select') # multiple
my $sel = $Drunk->to_field('pints', 'select'); # Already had beers selected
- # Random uses
-
+ # Random uses
=head1 DESCRIPTION
=cut
-# TODO -- use search_columns
+# TODO -- use search_columns
+
sub search_inputs {
my ($class, $r) = @_;
warn "In model search_inputs " if $class->model_debug;
}
+=head2 a_select_box
+
+ Returns a HTML::Element representing a select box, based on the arguments
+
+=cut
+
# make a select box from args
sub a_select_box {
my ($self, $name, $vals, $selected_val, $contents) = @_;
=cut
sub _field_from_column {
- my ($self, $field, $args) = @_;
- my $class = ref $self || $self;
- # Get column type
- unless ($args->{column_type}) {
- if ($class->can('column_type')) {
- $args->{column_type} = $class->column_type($field);
- }
- else {
- # Right, have some of this
- eval "package $class; Class::DBI::Plugin::Type->import()";
- $args->{column_type} = $class->column_type($field);
- }
+ my ($self, $field, $args) = @_;
+ my $class = ref $self || $self;
+ # Get column type
+ unless ($args->{column_type}) {
+ if ($class->can('column_type')) {
+ $args->{column_type} = $class->column_type($field);
+ } else {
+ # Right, have some of this
+ eval "package $class; Class::DBI::Plugin::Type->import()";
+ $args->{column_type} = $class->column_type($field);
}
- my $type = $args->{column_type};
-
- return $self->_to_textfield($field)
- if $type and $type =~ /(VAR)?CHAR/i; #common type
- return $self->_to_textarea($field, $args)
- if $type and $type =~ /^(TEXT|BLOB)$/i;
- return $self->_to_enum_select($field, $args)
- if $type and $type =~ /^ENUM\((.*?)\)$/i;
- return $self->_to_bool_select($field, $args)
- if $type and $type =~ /^BOOL/i;
- return $self->_to_readonly($field, $args)
- if $type and $type =~ /^readonly$/i;
- return;
+ }
+ my $type = $args->{column_type};
+
+ return $self->_to_textfield($field)
+ if $type and $type =~ /(VAR)?CHAR/i; #common type
+ return $self->_to_textarea($field, $args)
+ if $type and $type =~ /^(TEXT|BLOB)$/i;
+ return $self->_to_enum_select($field, $args)
+ if $type and $type =~ /^ENUM\((.*?)\)$/i;
+ return $self->_to_bool_select($field, $args)
+ if $type and $type =~ /^BOOL/i;
+ return $self->_to_readonly($field, $args)
+ if $type and $type =~ /^readonly$/i;
+ return;
}
# Get items to select from
$args->{items} = _select_items($args);
-use Data::Dumper;
-warn "Just got items. They are " . Dumper($args->{items});
-
- # Make select HTML element
- $a = $self->_select_guts($col, $args);
+ # Make select HTML element
+ $a = $self->_select_guts($col, $args);
- # Return
+ # Return
$OLD_STYLE && return $a->as_HTML;
$a;
$sql .= " WHERE " . $args->{where} if $args->{where};
$sql .= " ORDER BY " . $args->{order_by} if $args->{order_by};
$sql .= " LIMIT " . $args->{limit} if $args->{limit};
-warn "_select_items sql is : $sql";
return $fclass->db_Main->selectall_arrayref($sql);
my $content = ($fclass and $stringify and $fclass->can($stringify)) ?
$fclass->$stringify($_) :
join('/', @{$_});
-use Data::Dumper;
-warn "Content is $content";
+
$opt->push_content( $content );
push @res, $opt;
}
my $fclass = $args->{class} || '';
my $stringify = $args->{stringify} || '';
my @res;
- for (@$items) {
- my $val = $_->{$pk};
+ for my $item (@$items) {
+ my $val = $item->{$pk};
my $opt = HTML::Element->new("option", value => $val );
$opt->attr(selected => "selected") if $selected->{$val};
- my $content = $fclass and $stringify and $fclass->can($stringify) ?
- $fclass->$stringify($_) :
- join(' ', @$_);
+ my $content = ( $fclass && $stringify && $fclass->can($stringify)) ? $fclass->$stringify($item) : join(' ', @$item);
$opt->push_content( $content );
- push @res, $opt;
+ push @res, $opt;
}
- return @res;
+ return @res;
}
#
=cut
-\r
-\r
-\r