App-Office-Contacts

 view release on metacpan or  search on metacpan

lib/App/Office/Contacts/View/Role/Report.pm  view on Meta::CPAN

package App::Office::Contacts::View::Role::Report;

use strict;
use utf8;
use warnings;
use warnings  qw(FATAL utf8); # Fatalize encoding glitches.

use Moo::Role;

use Text::Xslate 'mark_raw';

our $VERSION = '2.04';

# -----------------------------------------------

sub build_report_html
{
	my($self) = @_;

	$self -> db -> logger -> log(debug => 'View::Role::Report.build_report_html()');

	my($report);

	if ($self -> db -> library -> count_reports == 1)
	{
		$report = 'Records';
	}
	else
	{
		$report = mark_raw($self -> build_menu('report_id', , $self -> get_menu_data('reports') ) );
	}

	my($param) =
	{
		communication_types => mark_raw($self -> build_menu('report_communication_type_id', $self -> get_menu_data('communication_types') ) ),
		genders             => mark_raw($self -> build_menu('report_gender_id', $self -> get_menu_data('genders') ) ),
		report_entities     => mark_raw($self -> build_menu('report_entity_id', $self -> get_menu_data('report_entities') ) ),
		reports             => $report,
		roles               => mark_raw($self -> build_menu('report_role_id', $self -> get_menu_data('roles') ) ),
		sid                 => $self -> db -> session -> id,
		visibilities        => mark_raw($self -> build_menu('report_visibility_id', $self -> get_menu_data('visibilities') ) ),
	};

	# Make browser happy by turning the HTML into 1 long line.
	# Also, the embedded single quotes need to be escaped, because in
	# Initialize.build_head_init(), the output of this sub is inserted
	# into this Javascript:
	# content: '$report_html'.

	my($html) = $self -> db -> templater -> render
				(
					'report.tx',
					$param
				);
	$html =~ s/\n//g;
	$html =~ s/'/\\'/g;

	return $html;

} # End of build_report_html.

# -----------------------------------------------

sub format_record_report
{
	my($self, $result) = @_;

	$self -> db -> logger -> log(debug => 'View::Role::Report.format_record_report(...)');

	my($html) = <<EOS;
<table class="display" id="result_table" cellpadding="0" cellspacing="0" border="0" width="100%">
<thead>
<tr>
	<th>Count</th>
	<th>Name</th>
	<th>Entity type</th>
	<th>Contact via</th>
	<th>Role</th>
	<th>Visibility</th>
</tr>
</thead>
<tbody>
EOS

	my($count) = 0;

	my($class);

	for my $row (@$result)
	{
		$class = (++$count % 2 == 1) ? 'odd gradeC' : 'even gradeC';
		$html  .= <<EOS;
<tr class="$class">
	<td>$count</td>
	<td>$$row{data}{name}</td>
	<td>$$row{type}</td>
	<td>$$row{data}{communication_type_name}</td>
	<td>$$row{data}{role_name}</td>
	<td>$$row{data}{visibility_name}</td>
</tr>
EOS
	}

	$html .= <<EOS;
</tbody>



( run in 3.235 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )