--- lib/A3C/View.pm 2008/03/30 02:33:01 37 +++ lib/A3C/View.pm 2008/04/11 23:23:42 79 @@ -5,29 +5,63 @@ use Jifty::View::Declare -base; use A3C::LDAP; +use A3C::SQL; use Data::Dump qw/dump/; +template '/' => page { + + h1 { _('Statistics') } + + my $orgs = A3C::Model::OrganizationCollection->new; + $orgs->unlimit; + + dt { _('Number of schools in system') } + dd { $orgs->count } + + my $people = A3C::Model::PersonCollection->new; + $people->unlimit; + + dt { _('Number of persons in system') } + dd { $people->count } + + my $sql = A3C::SQL->new({ query => qq{ + select count(uid),l + from organizations + inner join towns on towns.name = l + group by l + order by count desc + limit 25 + }}); + + dt { _('Top %1 towns by schools', $sql->count) } + dd { + ul { + while ( my $row = $sql->next ) { + li { outs_raw( $row->count, ' ', $row->l ) } + } + } + } -template '/skole' => page { - h1 { _('Schools in system') }; - show 'skole_sve'; }; -private template 'skole_sve' => sub { + +template 'ldap' => page { + h1 { _('LDAP data about Schools in system') }; + my $ldap = A3C::LDAP->new; div { - my $search = A3C::LDAP->search( + $ldap->search( base => 'dc=skole,dc=hr', filter => '(objectClass=hrEduOrg)', sizelimit => 10, ); - while ( my $entry = $search->shift_entry ) { + while ( my $entry = $ldap->current_search->shift_entry ) { #warn $entry->dump; ul { foreach my $attr ( $entry->attributes ) { li { tt { $attr } - span { dump( $entry->get_value( $attr ) } + span { dump( $entry->get_value( $attr ) ) } } } } @@ -35,3 +69,62 @@ } }; +template 'people' => page { + + h1 { _('Find people') } + + my $action = new_action( + class => 'SearchPerson', + moniker => 'search-users', + sticky_on_success => 1, + sticky_on_failure => 1, + ); + + + form { + render_action( $action => [ 'uid_contains', 'cn_contains' ] ); + form_submit( label => _('Find someone') ); + }; + +# warn dump( $action->result->content ); + + if ( my $search = $action->result->content('search') ) { + div { sprintf(_('Found %d results'), $search->count ) } + ol { + while (my $user = $search->next) { + li { + span { $user->cn } + tt { $user->uid } + } + } + } + } + +}; + +template 'sync' => page { + + h1 { _('Sync school from LDAP') } + + my $action = new_action( + class => 'SyncOrganization', + moniker => 'sync-organization' + ); + + form { + render_action( $action => [ 'cn' ] ); + form_submit( label => _('Sync Organization') ); + }; + + if ( my $users = $action->result->content('synced-users') ) { + ol { + while (my $user = $users->next) { + li { + span { $user->cn } + tt { { class is 'email' } '<' . $user->mail . '>' } + } + } + } + } + +};