/[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 73 - (hide annotations)
Fri Apr 11 15:49:50 2008 UTC (16 years ago) by dpavlin
File size: 8011 byte(s)
use direct accessors instead of __value which fixes encoding problems
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 14 use utf8;
8    
9 dpavlin 11 use A3C::Record schema {
10 dpavlin 2
11 dpavlin 16 column uid =>
12     label is ('uid'),
13     is indexed,
14     is mandatory,
15     is distinct;
16    
17     column hrEduPersonUniqueID =>
18     label is ('hrEduPersonUniqueID'),
19     is indexed,
20 dpavlin 18 is distinct,
21 dpavlin 4 is mandatory;
22    
23     column cn =>
24 dpavlin 21 label is _('Ime i prezime'),
25 dpavlin 29 is mandatory;
26 dpavlin 4
27     column sn =>
28     label is _('Prezime'),
29     is mandatory;
30    
31     column givenName =>
32     label is _('Ime'),
33     is mandatory;
34    
35 dpavlin 16 column mail =>
36 dpavlin 4 type is 'text',
37     is mandatory,
38 dpavlin 18 label is _('Email address'), default is '',
39 dpavlin 73 is indexed,
40 dpavlin 18 is immutable,
41     is distinct;
42 dpavlin 4
43     column password =>
44     is unreadable,
45     label is _('Password'),
46     type is 'varchar',
47     hints is _('Your password should be at least six characters'),
48     render_as 'password',
49     # filters are 'Jifty::DBI::Filter::SaltHash',
50     is mandatory;
51    
52     column telephoneNumber =>
53     type is 'text',
54     label is _('Telefonski broj'),
55     hint is '+385 xx yyyyyy';
56    
57     column hrEduPersonExtensionNumber =>
58     label is _('Lokalni telefonski broj');
59    
60     column mobile =>
61     label is _('Broj mobilnog telefona');
62    
63     column facsimileTelephoneNumber =>
64     label is _('Fax broj');
65    
66     column hrEduPersonUniqueNumber =>
67 dpavlin 10 # is mandatory,
68 dpavlin 35 label is _('Unique number');
69 dpavlin 4
70     column hrEduPersonDateOfBirth =>
71     type is 'date',
72 dpavlin 15 render as 'date',
73 dpavlin 16 label is _('Datum rođenja'),
74     filters are 'Jifty::DBI::Filter::Date';
75 dpavlin 4
76     column hrEduPersonGender =>
77     label is _('Spol');
78    
79     column jpegPhoto =>
80     label is _('Slika');
81    
82     column userCertificate =>
83     label is _('Ceritifikat');
84    
85     column labeledURI =>
86     label is _('URI adresa');
87    
88     column wtAdminType =>
89     label is _('Tip administratora'),
90 dpavlin 15 valid are [ '', 'AS', 'AI', 'AR', 'AHU' ];
91 dpavlin 4
92 dpavlin 42 column hrEduPersonHomeOrg =>
93     label is _('Oznaka matične ustanove'),
94     hint is 'CARNet',
95     is mandatory;
96    
97 dpavlin 4 column hrEduPersonProfessionalStatus =>
98     label is _('Stručni status'),
99 dpavlin 15 valid are [
100     '',
101     'NKV',
102     'PKV',
103     'KV',
104     'VKV',
105     'SSS',
106     'VS',
107     'VSS',
108     'VŠS',
109     'MR',
110     'DR',
111     ],
112     default is '';
113 dpavlin 4
114     column hrEduPersonAcademicStatus =>
115     label is _('Zvanje'),
116 dpavlin 15 valid are [
117     '',
118 dpavlin 4 'knjižničar',
119 dpavlin 15 'viši knjižničar',
120 dpavlin 4 'korepetitor',
121 dpavlin 15 'viši korepetitor',
122 dpavlin 4 'lektor',
123 dpavlin 15 'viši lektor',
124     'stručni suradnik',
125     'asistent visoke škole',
126     'profesor visoke škole',
127 dpavlin 4 'mlađi asistent',
128 dpavlin 15 'znanstveni novak',
129     'znanstveni asistent',
130     'znanstveni suradnik',
131 dpavlin 4 'predavač',
132 dpavlin 15 'viši predavač',
133     'asistent',
134     'asistent - predavač',
135     'viši asistent',
136     'docent',
137     'izvanredni profesor',
138 dpavlin 4 'redoviti profesor',
139 dpavlin 15 'znanstveni savjetnik',
140 dpavlin 4 'viši znanstveni suradnik',
141 dpavlin 15 ],
142     default is '';
143 dpavlin 4
144     column hrEduPersonScienceArea =>
145     label is _('Područje znanosti'),
146 dpavlin 15 valid are [
147     '',
148 dpavlin 4 'Tehničke znanosti',
149     'Prirodne znanosti',
150     'Humanističke znanosti',
151     'Društvene znanosti',
152     'Biotehničke znanosti',
153     'Biomedicina i zdravstvo',
154 dpavlin 15 ],
155     default is '';
156 dpavlin 4
157 dpavlin 45 column 'o';
158     column 'l';
159     column 'postalAddress';
160    
161 dpavlin 42 # column organization =>
162     # refers_to A3C::Model::Organization by 'id',
163     # is mandatory;
164 dpavlin 32
165 dpavlin 4 column hrEduPersonAffiliation =>
166     label is _('Povezanost s ustanovom'),
167     is mandatory,
168 dpavlin 15 valid are [
169     'učenik',
170     'student',
171 dpavlin 4 'djelatnik',
172 dpavlin 15 'vanjski suradnik',
173     'korisnik usluge',
174 dpavlin 4 'gost',
175 dpavlin 15 ],
176     default is 'korisnik usluge';
177 dpavlin 4
178     column hrEduPersonPrimaryAffiliation =>
179     label is _('Temeljna povezanost s ustanovom');
180     is mandatory,
181 dpavlin 15 valid are [
182     'učenik',
183     'student',
184 dpavlin 4 'djelatnik',
185 dpavlin 15 'vanjski suradnik',
186     'korisnik usluge',
187 dpavlin 4 'gost',
188 dpavlin 15 ],
189     default is 'korisnik usluge';
190 dpavlin 4
191     column hrEduPersonStudentCategory =>
192     label is 'Vrsta studenta',
193 dpavlin 15 valid are [
194     '',
195     'osnovnoškolac',
196     'srednjoškolac',
197     'student stručnog studija',
198     'preddiplomac',
199     'postdiplomac',
200 dpavlin 4 'dodiplomac',
201     'pauzira godinu',
202     'prekid studija',
203 dpavlin 15 ],
204     default is '';
205 dpavlin 4
206     column hrEduPersonExpireDate =>
207     label is _('Datum isteka temeljne povezanosti'),
208     type is 'date',
209 dpavlin 15 render as 'date',
210 dpavlin 4 is mandatory,
211 dpavlin 16 filters are 'Jifty::DBI::Filter::Date';
212 dpavlin 4
213     column hrEduPersonTitle =>
214     label is 'Položaj u ustanovi',
215 dpavlin 15 valid are [ # FIXME reorder
216     '',
217 dpavlin 4 'dekan',
218     'direktor',
219     'pomoćnik ravnatelja',
220     'predstojnik zavoda',
221     'pročelnik katedre',
222     'pročelnik odsjeka',
223     'pročelnik sveučilišnog odjela',
224     'prodekan',
225     'prorektor',
226     'ravnatelj',
227     'rektor',
228     'voditelj laboratorija',
229     'voditelj odjela',
230     'voditelj organizacijske jedini',
231     'voditelj projekta',
232     'zamjenik pročelnika sveučilišn',
233     'zamjenik ravnatelja',
234 dpavlin 15 ],
235     default is '';
236 dpavlin 4
237     column hrEduPersonRole =>
238     label is 'Uloga u ustanovi',
239 dpavlin 15 valid are [
240     '',
241 dpavlin 4 'administrator imenika',
242     'CARNet koordinator',
243     'CARNet sistem inženjer',
244     'ICT koordinator',
245     'ISVU koordinator',
246     'kontakt za sigurnosna pitanja',
247     'MS koordinator',
248     'MATICA operater',
249     'MATICA urednik',
250 dpavlin 15 ],
251     default is '';
252 dpavlin 4
253     column hrEduPersonStaffCategory =>
254     label is 'Vrsta posla u ustanovi',
255 dpavlin 15 valid are [
256 dpavlin 4 'administrativno osoblje',
257     'ICT podrška',
258     'istraživači',
259     'nastavno osoblje',
260     'osoblje knjižnice',
261     'tehničko osoblje',
262     ];
263    
264     column hrEduPersonGroupMember =>
265     label is 'Pripadnost grupi',
266     hint is 'skolskagodina::razred';
267    
268     column ou =>
269     label is _('Organizacijska jedinica');
270    
271     column roomNumber =>
272     label is _('Broj sobe');
273    
274     column homePostalAddress =>
275 dpavlin 12 label is _('Kućna poštanska adresa'),
276     render as 'textarea';
277 dpavlin 4
278     column homePhone =>
279     label is _('Kućni telefonski broj');
280    
281     column hrEduPersonCommURI =>
282     label is _('Desktop uređaj');
283    
284     column hrEduPersonPrivacy =>
285     label is _('Oznaka privatnosti');
286    
287 dpavlin 23 column loginShell =>
288 dpavlin 45 label is _('login shell');
289 dpavlin 23
290     column uidNumber =>
291 dpavlin 45 label is _('uid number'),
292 dpavlin 23 type is 'int';
293    
294     column gidNumber =>
295 dpavlin 45 label is _('gid number');
296 dpavlin 23 type is 'int';
297    
298     column homeDirectory =>
299 dpavlin 45 label is _('home directory');
300 dpavlin 23
301 dpavlin 2 };
302    
303 dpavlin 18 # we don't use following mixing because it wants to send notificaitons on e-mail address change
304     #use Jifty::Plugin::User::Mixin::Model::User;
305 dpavlin 4 use Jifty::Plugin::Authentication::Password::Mixin::Model::User;
306     #use Jifty::Plugin::OpenID::Mixin::Model::User;
307     use Jifty::Plugin::ActorMetadata::Mixin::Model::ActorMetadata; # created_by, created_on, updated_on
308    
309 dpavlin 2 # Your model-specific methods go here.
310    
311 dpavlin 18 =head2 before_create
312 dpavlin 16
313 dpavlin 18 Implement virtual columns, for now put mail from ldap into email row
314 dpavlin 16
315     =cut
316    
317 dpavlin 18 =for later
318    
319     sub before_create {
320     my ($self, $attr) = @_;
321     if ( ! $attr->{'email'} ) {
322     warn "push mail to email";
323     $attr->{'email'} = $attr->{'mail'};
324     }
325 dpavlin 16 }
326    
327 dpavlin 18 =cut
328    
329     =head2 email
330    
331     Accessor for compatibility with Jifty mixins
332    
333     =cut
334    
335     sub email {
336     my $self = shift;
337 dpavlin 73 return $self->mail;
338 dpavlin 18 }
339    
340     sub email_confirmed { 1 };
341    
342 dpavlin 45 =head2 name
343    
344     =cut
345    
346     sub name {
347     my $self = shift;
348 dpavlin 73 return $self->cn . ' <' . $self->mail . '>';
349 dpavlin 45 }
350    
351 dpavlin 4 =head2 validate_telephoneNumber
352    
353     =cut
354    
355     sub validate_telephoneNumber {
356     my ( $self, $value ) = @_;
357    
358     return ( 0, _('Telephone number invalid') ) if $value !~ m/^(\+?385)?[\d\s-]+$/;
359    
360     return ( 1, 'OK' );
361     }
362    
363 dpavlin 38 =head2 hrEduPersonUniqueNumber
364 dpavlin 35
365     Check if JMBG is valid
366    
367     =cut
368    
369     sub validate_hrEduPersonUniqueNumber {
370     my ( $self, $value ) = @_;
371    
372     if ( $value =~ m/^JMBG:\s+(\d+)$/ ) {
373    
374     my $jmbg = $1;
375    
376     return ( 0, _('JMBG must have 13 digits') ) unless length($jmbg) == 13;
377    
378     sub digit_at {
379     my ($jmbg,$pos) = @_;
380     return ord(substr($jmbg,$pos,1)) - ord('0');
381     }
382    
383     my $sum;
384     my $fact = 7;
385    
386     foreach my $i ( 0 .. 11 ) {
387     my $c = digit_at( $jmbg, $i );
388     $sum += $c * $fact;
389     # warn "## $c * $fact => $sum\n";
390     $fact--;
391     $fact = 7 if $fact == 1;
392     }
393    
394     my $ost = $sum % 11;
395     $ost = 11 - $ost if $ost > 1;
396    
397     return ( 0, _("JMBG is invalid") ) if $ost != digit_at( $jmbg, 12 );
398     }
399    
400     return ( 1, 'OK' );
401     }
402    
403 dpavlin 16 =head2 canonicalize_hrEduPersonExpireDate
404    
405     Support NONE as 2042-12-30
406    
407     =cut
408    
409     sub canonicalize_hrEduPersonExpireDate {
410     my ( $self, $value ) = @_;
411    
412 dpavlin 33 if ( lc($value) eq 'none' ) {
413 dpavlin 16 $self->log->warn("fixed hrEduPersonExpireDate");
414     $value = '2042-12-30';
415     }
416    
417     return $value;
418     }
419    
420 dpavlin 70 use A3C::DefaultACL;
421 dpavlin 16
422 dpavlin 2 1;
423    

  ViewVC Help
Powered by ViewVC 1.1.26