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 |
|
|
|
9 |
|
|
use Data::Dump qw/dump/; |
10 |
|
|
|
11 |
dpavlin |
72 |
template '/' => page { |
12 |
dpavlin |
37 |
|
13 |
dpavlin |
72 |
h1 { _('Statistics') } |
14 |
|
|
|
15 |
|
|
my $orgs = A3C::Model::OrganizationCollection->new; |
16 |
|
|
$orgs->unlimit; |
17 |
|
|
|
18 |
|
|
dt { _('Number of schools in system') } |
19 |
|
|
dd { $orgs->count } |
20 |
|
|
|
21 |
|
|
my $people = A3C::Model::PersonCollection->new; |
22 |
|
|
$people->unlimit; |
23 |
|
|
|
24 |
|
|
dt { _('Number of persons in system') } |
25 |
|
|
dd { $people->count } |
26 |
|
|
|
27 |
|
|
=for later |
28 |
|
|
|
29 |
|
|
dt { _('Breakdown by towns') } |
30 |
|
|
dd { |
31 |
|
|
$orgs->redo_search; |
32 |
|
|
# select count(l),l from organizations group by l order by count desc limit 25 |
33 |
|
|
$orgs->group_by( column => 'l' ); |
34 |
|
|
$orgs->order_by( column => 'l', order => 'desc' ); |
35 |
|
|
|
36 |
|
|
warn "## SQL: ", $orgs->build_select_query; |
37 |
|
|
my $count = $orgs->column( column => 'l', function => 'count(l)' ); |
38 |
|
|
warn "## count: $count\n"; |
39 |
|
|
# $orgs->column( column => 'l' ); |
40 |
|
|
warn "## SQL: ", $orgs->build_select_query; |
41 |
|
|
|
42 |
|
|
ul { |
43 |
|
|
for ( 1 .. 1 ) { |
44 |
|
|
my $o = $orgs->next; |
45 |
|
|
warn "## ",dump( $o ); |
46 |
|
|
li { outs ( $o->l, '|', $o->__value('l'), $o->__value( $count ) ) } |
47 |
|
|
} |
48 |
|
|
} |
49 |
|
|
|
50 |
|
|
|
51 |
|
|
} |
52 |
|
|
|
53 |
|
|
=cut |
54 |
|
|
|
55 |
|
|
}; |
56 |
|
|
|
57 |
|
|
|
58 |
dpavlin |
71 |
template 'ldap' => page { |
59 |
|
|
h1 { _('LDAP data about Schools in system') }; |
60 |
dpavlin |
40 |
my $ldap = A3C::LDAP->new; |
61 |
dpavlin |
37 |
div { |
62 |
dpavlin |
40 |
$ldap->search( |
63 |
dpavlin |
37 |
base => 'dc=skole,dc=hr', |
64 |
|
|
filter => '(objectClass=hrEduOrg)', |
65 |
|
|
sizelimit => 10, |
66 |
|
|
); |
67 |
dpavlin |
41 |
while ( my $entry = $ldap->current_search->shift_entry ) { |
68 |
dpavlin |
37 |
#warn $entry->dump; |
69 |
|
|
ul { |
70 |
|
|
foreach my $attr ( $entry->attributes ) { |
71 |
|
|
li { |
72 |
|
|
tt { $attr } |
73 |
dpavlin |
39 |
span { dump( $entry->get_value( $attr ) ) } |
74 |
dpavlin |
37 |
} |
75 |
|
|
} |
76 |
|
|
} |
77 |
|
|
} |
78 |
|
|
} |
79 |
|
|
}; |
80 |
|
|
|
81 |
dpavlin |
71 |
template 'people' => page { |
82 |
|
|
|
83 |
|
|
h1 { _('Find people') } |
84 |
dpavlin |
49 |
|
85 |
|
|
my $action = new_action( |
86 |
dpavlin |
71 |
class => 'SearchPerson', |
87 |
|
|
moniker => 'search-users', |
88 |
|
|
sticky_on_success => 1, |
89 |
|
|
sticky_on_failure => 1, |
90 |
dpavlin |
49 |
); |
91 |
|
|
|
92 |
dpavlin |
71 |
|
93 |
dpavlin |
49 |
form { |
94 |
|
|
render_action( $action => [ 'uid_contains', 'cn_contains' ] ); |
95 |
|
|
form_submit( label => _('Find someone') ); |
96 |
|
|
}; |
97 |
|
|
|
98 |
|
|
# warn dump( $action->result->content ); |
99 |
|
|
|
100 |
|
|
if ( my $search = $action->result->content('search') ) { |
101 |
|
|
div { sprintf(_('Found %d results'), $search->count ) } |
102 |
|
|
ol { |
103 |
|
|
while (my $user = $search->next) { |
104 |
|
|
li { |
105 |
|
|
span { $user->cn } |
106 |
|
|
tt { $user->uid } |
107 |
|
|
} |
108 |
|
|
} |
109 |
|
|
} |
110 |
|
|
} |
111 |
|
|
|
112 |
|
|
}; |
113 |
|
|
|
114 |
dpavlin |
71 |
template 'sync' => page { |
115 |
dpavlin |
55 |
|
116 |
dpavlin |
71 |
h1 { _('Sync school from LDAP') } |
117 |
|
|
|
118 |
dpavlin |
55 |
my $action = new_action( |
119 |
|
|
class => 'SyncOrganization', |
120 |
|
|
moniker => 'sync-organization' |
121 |
|
|
); |
122 |
|
|
|
123 |
|
|
form { |
124 |
|
|
render_action( $action => [ 'cn' ] ); |
125 |
|
|
form_submit( label => _('Sync Organization') ); |
126 |
|
|
}; |
127 |
|
|
|
128 |
|
|
if ( my $users = $action->result->content('synced-users') ) { |
129 |
|
|
ol { |
130 |
|
|
while (my $user = $users->next) { |
131 |
|
|
li { |
132 |
|
|
span { $user->cn } |
133 |
dpavlin |
57 |
tt { { class is 'email' } '<' . $user->mail . '>' } |
134 |
dpavlin |
55 |
} |
135 |
|
|
} |
136 |
|
|
} |
137 |
|
|
} |
138 |
|
|
|
139 |
|
|
}; |