Catalog
view release on metacpan or search on metacpan
lib/Catalog/tools/sqledit.pm view on Meta::CPAN
sub extract_values {
my($self, $row, $table, $hierarchy) = @_;
return undef if(!defined($hierarchy));
my($result);
my($sub_table);
foreach $sub_table ( keys(%$hierarchy) ) {
my($desc) = $self->{'relations'}->{$table}->{$sub_table};
my($linked_field) = $desc->{'field'};
my($field_to_link) = $desc->{'key'};
my($value_link) = $row->{$field_to_link};
my($info_link) = $self->db()->info_table($sub_table);
my($type_link) = $info_link->{$linked_field}->{'type'};
my($where_link) = "$linked_field ";
if($type_link eq 'char') {
my($quoted_value) = $self->db()->quote($value_link);
$where_link .= "like '$quoted_value' ";
} elsif($type_link eq 'int' || $type_link eq 'time') {
my($operator) = "=";
my($tmp) = $value_link;
if($tmp =~ /^\s*([<>])\s*(\d+)/) {
$operator = $1;
$tmp = $2;
} elsif($tmp =~ /(\d+)/) {
$tmp = $1;
} else {
$tmp = undef;
}
if(defined($tmp)) {
$where_link .= "$operator $tmp ";
}
} elsif($type_link eq 'set' || $type_link eq 'enum') {
$where_link .= "like '%$value_link%' ";
}
my($sql_link) = "select * from $sub_table where $where_link";
my($sub_rows, $sub_rows_total) = $self->db()->sexec_select($sub_table, $sql_link);
@{$result->{$sub_table}} = map {
{
'rows' => $_,
'children' => $self->extract_values($_, $sub_table, $hierarchy->{$sub_table}),
}
} @{$sub_rows};
}
return $result;
}
sub specific_link {
my($self, $table, $row, $info) = @_;
# if ( !$custom) {
# return "";
# } else {
# return '_SPECIFICLINK_' => "";
# }
}
sub margin {
my($self, $legend, $level) = @_;
my($margin);
my($margin_table);
if($level > 0) {
if(!$legend) {
$legend = " ";
} else {
$legend = "<i>$legend</i>";
}
$margin .= "<td width=\"5%\"> </td>" x ($level - 1);
$margin = "$margin<td width=\"5%\">$legend</td>";
}
return $margin;
}
sub search_display {
my($self, $template, $table, $row, $info, $index, $level) = @_;
my($assoc) = $template->{'assoc'};
if(exists($assoc->{'_DEFAULTTITLE_'})) {
$assoc->{'_DEFAULTTITLE_'} = $self->row2title($info, undef, $table);
}
if(exists($assoc->{'_DEFAULTROW_'})) {
$assoc->{'_DEFAULTROW_'} = $self->row2view($row, $table, 'short');
} else {
$self->row2assoc($table, $row, $assoc);
}
if(exists($assoc->{'_MARGIN_'})) {
$assoc->{'_MARGIN_'} = $self->margin('', $level);
}
if(exists($assoc->{'_MARGINTABLE_'})) {
$assoc->{'_MARGINTABLE_'} = $self->margin($table, $level);
}
if(exists($assoc->{'_LINKS_'})) {
my($html);
$html .= "<td colspan=20>";
my($context);
foreach $context ('edit', 'remove') {
$html .= "<a href=\"" . $self->call($table, $info, $row, 'context' => $context) . "\">" . ucfirst($context) . "</a> ";
}
my($select_call) = $self->select_call($table, $row);
if(defined($select_call)) {
$html .= "<a href=\"$select_call\">Select</a> ";
}
# $html .= $self->specific_link($custom, $table, $row, $info);
$html .= "</td>";
$assoc->{'_LINKS_'} = $html;
}
$assoc->{'_TABLE_'} = $table if(exists($assoc->{'_TABLE_'}));
$assoc->{'_RANK_'} = $index if(exists($assoc->{'_RANK_'}));
$self->search_entry_tags($assoc, $info, $row, $table);
return $self->stemplate_build($template);
}
sub layout_rows {
my($self, $template, $tables, $rows, $func) = @_;
if(@$rows <= 0) {
$template->{'skip'} = 1;
return;
}
if(!ref($tables)) {
$tables = [ $tables ];
}
if(!defined($func)) {
$func = sub {
my($template, $row) = @_;
my($assoc) = $template->{'assoc'};
( run in 1.721 second using v1.01-cache-2.11-cpan-2398b32b56e )