/[A3C]/lib/A3C/View.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /lib/A3C/View.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 79 - (show annotations)
Fri Apr 11 23:23:42 2008 UTC (16 years ago) by dpavlin
File size: 2337 byte(s)
example SQL query using new class
1 package A3C::View;
2
3 use strict;
4 use warnings;
5
6 use Jifty::View::Declare -base;
7 use A3C::LDAP;
8 use A3C::SQL;
9
10 use Data::Dump qw/dump/;
11
12 template '/' => page {
13
14 h1 { _('Statistics') }
15
16 my $orgs = A3C::Model::OrganizationCollection->new;
17 $orgs->unlimit;
18
19 dt { _('Number of schools in system') }
20 dd { $orgs->count }
21
22 my $people = A3C::Model::PersonCollection->new;
23 $people->unlimit;
24
25 dt { _('Number of persons in system') }
26 dd { $people->count }
27
28 my $sql = A3C::SQL->new({ query => qq{
29 select count(uid),l
30 from organizations
31 inner join towns on towns.name = l
32 group by l
33 order by count desc
34 limit 25
35 }});
36
37 dt { _('Top %1 towns by schools', $sql->count) }
38 dd {
39 ul {
40 while ( my $row = $sql->next ) {
41 li { outs_raw( $row->count, ' ', $row->l ) }
42 }
43 }
44 }
45
46 };
47
48
49 template 'ldap' => page {
50 h1 { _('LDAP data about Schools in system') };
51 my $ldap = A3C::LDAP->new;
52 div {
53 $ldap->search(
54 base => 'dc=skole,dc=hr',
55 filter => '(objectClass=hrEduOrg)',
56 sizelimit => 10,
57 );
58 while ( my $entry = $ldap->current_search->shift_entry ) {
59 #warn $entry->dump;
60 ul {
61 foreach my $attr ( $entry->attributes ) {
62 li {
63 tt { $attr }
64 span { dump( $entry->get_value( $attr ) ) }
65 }
66 }
67 }
68 }
69 }
70 };
71
72 template 'people' => page {
73
74 h1 { _('Find people') }
75
76 my $action = new_action(
77 class => 'SearchPerson',
78 moniker => 'search-users',
79 sticky_on_success => 1,
80 sticky_on_failure => 1,
81 );
82
83
84 form {
85 render_action( $action => [ 'uid_contains', 'cn_contains' ] );
86 form_submit( label => _('Find someone') );
87 };
88
89 # warn dump( $action->result->content );
90
91 if ( my $search = $action->result->content('search') ) {
92 div { sprintf(_('Found %d results'), $search->count ) }
93 ol {
94 while (my $user = $search->next) {
95 li {
96 span { $user->cn }
97 tt { $user->uid }
98 }
99 }
100 }
101 }
102
103 };
104
105 template 'sync' => page {
106
107 h1 { _('Sync school from LDAP') }
108
109 my $action = new_action(
110 class => 'SyncOrganization',
111 moniker => 'sync-organization'
112 );
113
114 form {
115 render_action( $action => [ 'cn' ] );
116 form_submit( label => _('Sync Organization') );
117 };
118
119 if ( my $users = $action->result->content('synced-users') ) {
120 ol {
121 while (my $user = $users->next) {
122 li {
123 span { $user->cn }
124 tt { { class is 'email' } '<' . $user->mail . '>' }
125 }
126 }
127 }
128 }
129
130 };

  ViewVC Help
Powered by ViewVC 1.1.26