--- lib/A3C/View.pm 2008/03/30 13:32:29 39 +++ lib/A3C/View.pm 2008/05/30 23:47:29 142 @@ -5,23 +5,83 @@ use Jifty::View::Declare -base; use A3C::LDAP; +use A3C::SQL; use Data::Dump qw/dump/; +template '/' => page { -template '/skole' => page { - h1 { _('Schools in system') }; - show 'skole_sve'; + h1 { _('Statistics') } + + my $orgs = A3C::Model::hrEduOrgCollection->new; + $orgs->unlimit; + + dt { _('Number of schools in system') } + dd { $orgs->count } + + my $people = A3C::Model::hrEduPersonCollection->new; + $people->unlimit; + + dt { _('Number of persons in system') } + dd { $people->count } + + my $by_towns = A3C::SQL->new({ query => qq{ + select count(uid),l + from hr_edu_orgs + inner join towns on towns.name = l + group by l + order by count desc + limit 25 + }}); + + dt { _('Top %1 towns by schools', $by_towns->count) } + dd { + ul { + while ( my $row = $by_towns->next ) { + li { outs_raw( $row->count, ' ', $row->l ) } + } + } + } + + my $by_county = A3C::SQL->new({ query => qq{ + select + count(uid) as schools, + county, + count(distinct municipality) as municipalities + from hr_edu_orgs + inner join towns on towns.name = l + group by county + order by schools desc + }}); + + dt { _('Schools by counties') } + dd { + table { + th { _('Schools') } + th { _('County') } + th { _('Municipalities') }; + while ( my $row = $by_county->next ) { + row { + cell { $row->schools } + cell { $row->county } + cell { $row->municipalities } + } + } + } + } }; -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 ) { @@ -35,3 +95,77 @@ } }; +template 'people' => page { + + h1 { _('Find people') } + + my $action = new_action( + class => 'SearchhrEduPerson', + 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 => [ 'org_uid' ] ); + 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 . '>' } + } + } + } + } + +}; + +# mount other views +use A3C::View::Organization; + +# we can't really use following form because Jifty would upper case first +# letter of model and try to find A3C::Model::HrEduOrg which doesn't exit! +#Jifty::View::Declare::CRUD->mount_view('hrEduOrg', 'A3C::View::Organization', '/organizations'); +alias A3C::View::Organization under '/organizations', { + object_type => 'hrEduOrg', +}; + +use A3C::View::Strix; +alias A3C::View::Strix under '/strix'; + +1;