Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- In a library system you want to check circulation rules. As inputs you have a user object, an item object, and some basic circ information. As outputs you want duration and fine information.
- Thus, lets go with the following basics:
- Users have a permission group and home library. Both are references to trees, and we want to include when these values are descendants of the selected value. Users also have an optional date of birth, from which we can get their age, if it is set.
- Items have an owning library, a circ modifier, and we can get the item's age based on our own criteria.
- The circulation information includes where the item is circulating and if it is a renewal.
- Our current method of accomplishing this is to use a table with a number of "check" and "result" columns. Simplified for the above:
- Check columns:
- user_home_library FK
- user_permission_group FK
- user_age_min INTERVAL
- user_age_max INTERVAL
- item_owning_library FK
- item_circ_modifier FK
- item_age_max INTERVAL
- circ_library FK
- is_renewal BOOL
- Result columns:
- duration_rule FK
- fine_rule FK
- All of the check columns can be null to represent "no data" - This serves as a wildcard. Only non-null check columns contribute to our ordering of rows, however. To avoid two rows with the same checks but different results we have a unique index across all check columns, coalesced to non-null values. The actual result is returned by a plpgsql stored procedure that takes the basic data in and returns the final result.
- When all check columns are null the duration and fine rules would be the "default" rules, for when no more specific rules exist. Otherwise we filter and order based on the non-null check columns in any given row.
- Because this is a user configurable area we allow users to set (or not set) any combination of check columns. They may decide that they only care about the item_circ_modifier, or perhaps they care about the combination of the user_permission_group and item_circ_modifier.
- I have been told that the use of nulls in this situation may be a horrible idea, and as I am planning on working on this area of our system in the near future I will be in a position to do this in a more "correct" manner. I just need to know what that manner is so that I can weigh the pros and cons compared to how things are currently implemented.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement