--- lib/A3C/View.pm 2008/03/30 15:23:35 41 +++ lib/A3C/View.pm 2008/06/14 22:04:11 155 @@ -5,16 +5,75 @@ 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 { $ldap->search( @@ -36,3 +95,79 @@ } }; +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 => _('Search') ); + }; + +# warn dump( $action->result->content ); + + if ( my $search = $action->result->content('search') ) { + div { _('Found %1 results', $search->count ) } + table { + while (my $user = $search->next) { + row { + cell { $user->cn } + cell { tt { $user->uid } } + cell { tt { $user->hrEduPersonUniqueID } } + cell { $user->hrEduPersonHomeOrg } + } + } + } + } + +}; + +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;