App-Dochazka-REST
view release on metacpan or search on metacpan
lib/App/Dochazka/REST/Model/Employee.pm view on Meta::CPAN
=head2 Employees in the database
At the database level, C<App::Dochazka::REST> needs to be able to distinguish
one employee from another. This is accomplished by the EID. All the other
fields in the C<employees> table are optional.
The C<employees> database table is defined as follows:
CREATE TABLE IF NOT EXISTS employees (
eid serial PRIMARY KEY,
nick varchar(32) UNIQUE NOT NULL,
sec_id varchar(64) UNIQUE,
fullname varchar(96) UNIQUE,
email text UNIQUE,
passhash text,
salt text,
supervisor integer REFERENCES employees (eid),
remark text,
CONSTRAINT kosher_nick CHECK (nick ~* '^[[:alnum:]_][[:alnum:]_-]+$')
)
=head3 EID
The Employee ID (EID) is Dochazka's principal means of identifying an
employee. At the site, employees will be known by other means, like their
full name, their username, their user ID, etc. But these can and will
change from time to time. The EID should never, ever change.
=head3 nick
The idea behind the C<nick> field is that each employee can have an
easy-to-remember nickname - ideally something that appeals to them, personally.
The C<nick> is required and can only contain certain characters (alphanumerics,
underscore, hyphen).
=head3 sec_id
The secondary ID is an optional unique string identifying the employee.
This could be useful at sites where employees already have a nick (username)
and a numeric ID, for example. This gives administrators and supervisors the
ability to look up employees by their numeric ID as well as their username
(nick).
=head3 fullname, email
These fields are optional. If they have a value, it must be unique. value.
Dochazka does not check if the email address is valid.
Depending on how C<App::Dochazka::REST> is configured (see especially the
C<DOCHAZKA_PROFILE_EDITABLE_FIELDS> site parameter), these fields may be
read-only for employees (changeable by admins only), or the employee may be
allowed to maintain their own information.
=head3 passhash, salt
The optional passhash and salt fields are designed to hold a hashed password
and random salt. See L<App::Dochazka::REST::Guide/AUTHENTICATION AND SESSION
MANAGEMENT> for details.
=head3 supervisor
If the employee has a supervisor who will use Dochazka to monitor the
employee's attendance, and provided that supervisor has an EID, this field can
be used to set up the relationship.
=head3 remark
This field can be used by administrators for any purpose. Ordinarily, the
employee herself is not permitted to edit or even display it.
=head2 Employees in the Perl API
Individual employees are represented by "employee objects". All methods and
functions for manipulating these objects are contained in
L<App::Dochazka::REST::Model::Employee>. The most important methods are:
=over
=item * constructor (L<spawn>)
=item * basic accessors (L<eid>, L<sec_id>, L<nick>, L<fullname>, L<email>,
L<passhash>, L<salt>, L<remark>)
=item * L<priv> (privilege "accessor" - but privilege info is not stored in
the object)
=item * L<schedule> (schedule "accessor" - but schedule info is not stored
in the object)
=item * L<reset> (recycles an existing object by setting it to desired state)
=item * L<insert> (inserts object into database)
=item * L<update> (updates database to match the object)
=item * L<delete> (deletes record from database if nothing references it)
=item * L<load_by_eid> (loads a single employee into the object)
=item * L<load_by_nick> (loads a single employee into the object)
=item * L<team_nicks> (returns list of nicks of employees whose supervisor is this employee)
=back
L<App::Dochazka::REST::Model::Employee> also exports some convenience
functions:
=over
=item * L<nick_exists> (given a nick, return true/false)
( run in 0.579 second using v1.01-cache-2.11-cpan-5b529ec07f3 )