/[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

Annotation of /lib/A3C/View.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 149 - (hide annotations)
Tue Jun 3 15:32:14 2008 UTC (15 years, 10 months ago) by dpavlin
File size: 3445 byte(s)
added bunch of fields and convert to table

1 dpavlin 37 package A3C::View;
2    
3     use strict;
4     use warnings;
5    
6     use Jifty::View::Declare -base;
7     use A3C::LDAP;
8 dpavlin 79 use A3C::SQL;
9 dpavlin 37
10     use Data::Dump qw/dump/;
11    
12 dpavlin 72 template '/' => page {
13 dpavlin 37
14 dpavlin 72 h1 { _('Statistics') }
15    
16 dpavlin 120 my $orgs = A3C::Model::hrEduOrgCollection->new;
17 dpavlin 72 $orgs->unlimit;
18    
19     dt { _('Number of schools in system') }
20     dd { $orgs->count }
21    
22 dpavlin 120 my $people = A3C::Model::hrEduPersonCollection->new;
23 dpavlin 72 $people->unlimit;
24    
25     dt { _('Number of persons in system') }
26     dd { $people->count }
27    
28 dpavlin 83 my $by_towns = A3C::SQL->new({ query => qq{
29 dpavlin 79 select count(uid),l
30 dpavlin 120 from hr_edu_orgs
31 dpavlin 79 inner join towns on towns.name = l
32     group by l
33     order by count desc
34     limit 25
35     }});
36 dpavlin 72
37 dpavlin 83 dt { _('Top %1 towns by schools', $by_towns->count) }
38 dpavlin 72 dd {
39     ul {
40 dpavlin 83 while ( my $row = $by_towns->next ) {
41 dpavlin 79 li { outs_raw( $row->count, ' ', $row->l ) }
42 dpavlin 72 }
43     }
44     }
45    
46 dpavlin 83 my $by_county = A3C::SQL->new({ query => qq{
47     select
48     count(uid) as schools,
49     county,
50     count(distinct municipality) as municipalities
51 dpavlin 120 from hr_edu_orgs
52 dpavlin 83 inner join towns on towns.name = l
53     group by county
54     order by schools desc
55     }});
56    
57     dt { _('Schools by counties') }
58     dd {
59     table {
60     th { _('Schools') }
61     th { _('County') }
62     th { _('Municipalities') };
63     while ( my $row = $by_county->next ) {
64     row {
65     cell { $row->schools }
66     cell { $row->county }
67     cell { $row->municipalities }
68     }
69     }
70     }
71     }
72 dpavlin 72 };
73    
74    
75 dpavlin 71 template 'ldap' => page {
76     h1 { _('LDAP data about Schools in system') };
77 dpavlin 40 my $ldap = A3C::LDAP->new;
78 dpavlin 37 div {
79 dpavlin 40 $ldap->search(
80 dpavlin 37 base => 'dc=skole,dc=hr',
81     filter => '(objectClass=hrEduOrg)',
82     sizelimit => 10,
83     );
84 dpavlin 41 while ( my $entry = $ldap->current_search->shift_entry ) {
85 dpavlin 37 #warn $entry->dump;
86     ul {
87     foreach my $attr ( $entry->attributes ) {
88     li {
89     tt { $attr }
90 dpavlin 39 span { dump( $entry->get_value( $attr ) ) }
91 dpavlin 37 }
92     }
93     }
94     }
95     }
96     };
97    
98 dpavlin 71 template 'people' => page {
99    
100     h1 { _('Find people') }
101 dpavlin 49
102     my $action = new_action(
103 dpavlin 122 class => 'SearchhrEduPerson',
104 dpavlin 71 moniker => 'search-users',
105     sticky_on_success => 1,
106     sticky_on_failure => 1,
107 dpavlin 49 );
108    
109 dpavlin 71
110 dpavlin 49 form {
111     render_action( $action => [ 'uid_contains', 'cn_contains' ] );
112     form_submit( label => _('Find someone') );
113     };
114    
115     # warn dump( $action->result->content );
116    
117     if ( my $search = $action->result->content('search') ) {
118     div { sprintf(_('Found %d results'), $search->count ) }
119 dpavlin 149 table {
120 dpavlin 49 while (my $user = $search->next) {
121 dpavlin 149 row {
122     cell { $user->cn }
123     cell { tt { $user->uid } }
124     cell { tt { $user->hrEduPersonUniqueID } }
125     cell { $user->hrEduPersonHomeOrg }
126 dpavlin 49 }
127     }
128     }
129     }
130    
131     };
132    
133 dpavlin 71 template 'sync' => page {
134 dpavlin 55
135 dpavlin 71 h1 { _('Sync school from LDAP') }
136    
137 dpavlin 55 my $action = new_action(
138     class => 'SyncOrganization',
139     moniker => 'sync-organization'
140     );
141    
142     form {
143 dpavlin 122 render_action( $action => [ 'org_uid' ] );
144 dpavlin 55 form_submit( label => _('Sync Organization') );
145     };
146    
147     if ( my $users = $action->result->content('synced-users') ) {
148     ol {
149     while (my $user = $users->next) {
150     li {
151     span { $user->cn }
152 dpavlin 57 tt { { class is 'email' } '<' . $user->mail . '>' }
153 dpavlin 55 }
154     }
155     }
156     }
157    
158     };
159 dpavlin 125
160     # mount other views
161     use A3C::View::Organization;
162    
163     # we can't really use following form because Jifty would upper case first
164     # letter of model and try to find A3C::Model::HrEduOrg which doesn't exit!
165     #Jifty::View::Declare::CRUD->mount_view('hrEduOrg', 'A3C::View::Organization', '/organizations');
166     alias A3C::View::Organization under '/organizations', {
167     object_type => 'hrEduOrg',
168     };
169    
170 dpavlin 142 use A3C::View::Strix;
171     alias A3C::View::Strix under '/strix';
172    
173 dpavlin 125 1;

  ViewVC Help
Powered by ViewVC 1.1.26