/[A3C]/lib/A3C/Model/Person.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/Model/Person.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 94 - (hide annotations)
Wed Apr 30 17:23:46 2008 UTC (16 years ago) by dpavlin
File size: 6620 byte(s)
use vocabulary where applicable (with fixes for known bugs)
1 dpavlin 2 use strict;
2     use warnings;
3    
4 dpavlin 66 package A3C::Model::Person;
5 dpavlin 2 use Jifty::DBI::Schema;
6    
7 dpavlin 94 use A3C::AAIEduHr;
8    
9 dpavlin 14 use utf8;
10    
11 dpavlin 11 use A3C::Record schema {
12 dpavlin 2
13 dpavlin 16 column uid =>
14 dpavlin 77 label is _('UID'),
15 dpavlin 16 is indexed,
16     is mandatory,
17     is distinct;
18    
19     column hrEduPersonUniqueID =>
20 dpavlin 77 label is _('hr Edu Person Unique ID'),
21 dpavlin 16 is indexed,
22 dpavlin 18 is distinct,
23 dpavlin 4 is mandatory;
24    
25     column cn =>
26 dpavlin 21 label is _('Ime i prezime'),
27 dpavlin 29 is mandatory;
28 dpavlin 4
29     column sn =>
30     label is _('Prezime'),
31     is mandatory;
32    
33     column givenName =>
34     label is _('Ime'),
35     is mandatory;
36    
37 dpavlin 16 column mail =>
38 dpavlin 4 type is 'text',
39     is mandatory,
40 dpavlin 18 label is _('Email address'), default is '',
41 dpavlin 73 is indexed,
42 dpavlin 18 is immutable,
43     is distinct;
44 dpavlin 4
45     column password =>
46     is unreadable,
47     label is _('Password'),
48     type is 'varchar',
49     hints is _('Your password should be at least six characters'),
50     render_as 'password',
51     # filters are 'Jifty::DBI::Filter::SaltHash',
52     is mandatory;
53    
54     column telephoneNumber =>
55     type is 'text',
56     label is _('Telefonski broj'),
57     hint is '+385 xx yyyyyy';
58    
59     column hrEduPersonExtensionNumber =>
60     label is _('Lokalni telefonski broj');
61    
62     column mobile =>
63     label is _('Broj mobilnog telefona');
64    
65     column facsimileTelephoneNumber =>
66     label is _('Fax broj');
67    
68     column hrEduPersonUniqueNumber =>
69 dpavlin 10 # is mandatory,
70 dpavlin 35 label is _('Unique number');
71 dpavlin 4
72     column hrEduPersonDateOfBirth =>
73     type is 'date',
74 dpavlin 15 render as 'date',
75 dpavlin 16 label is _('Datum rođenja'),
76     filters are 'Jifty::DBI::Filter::Date';
77 dpavlin 4
78     column hrEduPersonGender =>
79 dpavlin 94 label is _('Spol'),
80     valid are [ { display => 'Nepoznato', value => 0 }, A3C::AAIEduHr->vocabulary('hrEdu002') ];
81 dpavlin 4
82     column jpegPhoto =>
83     label is _('Slika');
84    
85     column userCertificate =>
86     label is _('Ceritifikat');
87    
88     column labeledURI =>
89     label is _('URI adresa');
90    
91     column wtAdminType =>
92     label is _('Tip administratora'),
93 dpavlin 15 valid are [ '', 'AS', 'AI', 'AR', 'AHU' ];
94 dpavlin 4
95 dpavlin 42 column hrEduPersonHomeOrg =>
96     label is _('Oznaka matične ustanove'),
97     hint is 'CARNet',
98     is mandatory;
99    
100 dpavlin 4 column hrEduPersonProfessionalStatus =>
101     label is _('Stručni status'),
102 dpavlin 94 valid are [ '', A3C::AAIEduHr->vocabulary('hrEdu001'), 'VŠS' ],
103 dpavlin 15 default is '';
104 dpavlin 4
105     column hrEduPersonAcademicStatus =>
106     label is _('Zvanje'),
107 dpavlin 94 valid are [ '', A3C::AAIEduHr->vocabulary('hrEdu002') ],
108 dpavlin 15 default is '';
109 dpavlin 4
110     column hrEduPersonScienceArea =>
111     label is _('Područje znanosti'),
112 dpavlin 94 valid are [ '', A3C::AAIEduHr->vocabulary('hrEdu007') ],
113 dpavlin 15 default is '';
114 dpavlin 4
115 dpavlin 77 column 'o' =>
116     is indexed;
117    
118 dpavlin 45 column 'l';
119     column 'postalAddress';
120 dpavlin 77 column 'postalCode';
121     column 'street';
122 dpavlin 45
123 dpavlin 42 # column organization =>
124     # refers_to A3C::Model::Organization by 'id',
125     # is mandatory;
126 dpavlin 32
127 dpavlin 4 column hrEduPersonAffiliation =>
128     label is _('Povezanost s ustanovom'),
129     is mandatory,
130 dpavlin 94 valid are A3C::AAIEduHr->vocabulary('hrEdu004'),
131 dpavlin 15 default is 'korisnik usluge';
132 dpavlin 4
133     column hrEduPersonPrimaryAffiliation =>
134     label is _('Temeljna povezanost s ustanovom');
135     is mandatory,
136 dpavlin 94 valid are A3C::AAIEduHr->vocabulary('hrEdu004'),
137 dpavlin 15 default is 'korisnik usluge';
138 dpavlin 4
139     column hrEduPersonStudentCategory =>
140     label is 'Vrsta studenta',
141 dpavlin 15 valid are [
142     '',
143 dpavlin 94 A3C::AAIEduHr->vocabulary('hrEdu010'),
144 dpavlin 15 ],
145     default is '';
146 dpavlin 4
147     column hrEduPersonExpireDate =>
148     label is _('Datum isteka temeljne povezanosti'),
149     type is 'date',
150 dpavlin 15 render as 'date',
151 dpavlin 4 is mandatory,
152 dpavlin 16 filters are 'Jifty::DBI::Filter::Date';
153 dpavlin 4
154     column hrEduPersonTitle =>
155     label is 'Položaj u ustanovi',
156 dpavlin 94 valid are [ '', A3C::AAIEduHr->vocabulary('hrEdu003') ],
157 dpavlin 15 default is '';
158 dpavlin 4
159     column hrEduPersonRole =>
160     label is 'Uloga u ustanovi',
161 dpavlin 15 valid are [
162     '',
163 dpavlin 94 A3C::AAIEduHr->vocabulary('hrEdu006'),
164 dpavlin 4 'MATICA operater',
165     'MATICA urednik',
166 dpavlin 15 ],
167     default is '';
168 dpavlin 4
169     column hrEduPersonStaffCategory =>
170     label is 'Vrsta posla u ustanovi',
171 dpavlin 94 valid are [ '', A3C::AAIEduHr->vocabulary('hrEdu005') ];
172 dpavlin 4
173     column hrEduPersonGroupMember =>
174     label is 'Pripadnost grupi',
175     hint is 'skolskagodina::razred';
176    
177     column ou =>
178     label is _('Organizacijska jedinica');
179    
180     column roomNumber =>
181     label is _('Broj sobe');
182    
183     column homePostalAddress =>
184 dpavlin 12 label is _('Kućna poštanska adresa'),
185     render as 'textarea';
186 dpavlin 4
187     column homePhone =>
188     label is _('Kućni telefonski broj');
189    
190     column hrEduPersonCommURI =>
191     label is _('Desktop uređaj');
192    
193     column hrEduPersonPrivacy =>
194     label is _('Oznaka privatnosti');
195    
196 dpavlin 23 column loginShell =>
197 dpavlin 45 label is _('login shell');
198 dpavlin 23
199     column uidNumber =>
200 dpavlin 45 label is _('uid number'),
201 dpavlin 23 type is 'int';
202    
203     column gidNumber =>
204 dpavlin 45 label is _('gid number');
205 dpavlin 23 type is 'int';
206    
207     column homeDirectory =>
208 dpavlin 45 label is _('home directory');
209 dpavlin 23
210 dpavlin 2 };
211    
212 dpavlin 18 # we don't use following mixing because it wants to send notificaitons on e-mail address change
213     #use Jifty::Plugin::User::Mixin::Model::User;
214 dpavlin 4 use Jifty::Plugin::Authentication::Password::Mixin::Model::User;
215     #use Jifty::Plugin::OpenID::Mixin::Model::User;
216     use Jifty::Plugin::ActorMetadata::Mixin::Model::ActorMetadata; # created_by, created_on, updated_on
217    
218 dpavlin 2 # Your model-specific methods go here.
219    
220 dpavlin 18 =head2 before_create
221 dpavlin 16
222 dpavlin 18 Implement virtual columns, for now put mail from ldap into email row
223 dpavlin 16
224     =cut
225    
226 dpavlin 18 =for later
227    
228     sub before_create {
229     my ($self, $attr) = @_;
230     if ( ! $attr->{'email'} ) {
231     warn "push mail to email";
232     $attr->{'email'} = $attr->{'mail'};
233     }
234 dpavlin 16 }
235    
236 dpavlin 18 =cut
237    
238     =head2 email
239    
240     Accessor for compatibility with Jifty mixins
241    
242     =cut
243    
244     sub email {
245     my $self = shift;
246 dpavlin 73 return $self->mail;
247 dpavlin 18 }
248    
249     sub email_confirmed { 1 };
250    
251 dpavlin 45 =head2 name
252    
253     =cut
254    
255     sub name {
256     my $self = shift;
257 dpavlin 73 return $self->cn . ' <' . $self->mail . '>';
258 dpavlin 45 }
259    
260 dpavlin 4 =head2 validate_telephoneNumber
261    
262     =cut
263    
264     sub validate_telephoneNumber {
265     my ( $self, $value ) = @_;
266    
267     return ( 0, _('Telephone number invalid') ) if $value !~ m/^(\+?385)?[\d\s-]+$/;
268    
269     return ( 1, 'OK' );
270     }
271    
272 dpavlin 38 =head2 hrEduPersonUniqueNumber
273 dpavlin 35
274     Check if JMBG is valid
275    
276     =cut
277    
278     sub validate_hrEduPersonUniqueNumber {
279     my ( $self, $value ) = @_;
280    
281     if ( $value =~ m/^JMBG:\s+(\d+)$/ ) {
282    
283     my $jmbg = $1;
284    
285     return ( 0, _('JMBG must have 13 digits') ) unless length($jmbg) == 13;
286    
287     sub digit_at {
288     my ($jmbg,$pos) = @_;
289     return ord(substr($jmbg,$pos,1)) - ord('0');
290     }
291    
292     my $sum;
293     my $fact = 7;
294    
295     foreach my $i ( 0 .. 11 ) {
296     my $c = digit_at( $jmbg, $i );
297     $sum += $c * $fact;
298     # warn "## $c * $fact => $sum\n";
299     $fact--;
300     $fact = 7 if $fact == 1;
301     }
302    
303     my $ost = $sum % 11;
304     $ost = 11 - $ost if $ost > 1;
305    
306     return ( 0, _("JMBG is invalid") ) if $ost != digit_at( $jmbg, 12 );
307     }
308    
309     return ( 1, 'OK' );
310     }
311    
312 dpavlin 16 =head2 canonicalize_hrEduPersonExpireDate
313    
314     Support NONE as 2042-12-30
315    
316     =cut
317    
318     sub canonicalize_hrEduPersonExpireDate {
319     my ( $self, $value ) = @_;
320    
321 dpavlin 33 if ( lc($value) eq 'none' ) {
322 dpavlin 16 $self->log->warn("fixed hrEduPersonExpireDate");
323     $value = '2042-12-30';
324     }
325    
326     return $value;
327     }
328    
329 dpavlin 70 use A3C::DefaultACL;
330 dpavlin 16
331 dpavlin 2 1;
332    

  ViewVC Help
Powered by ViewVC 1.1.26