oafasys / dblookup
Provides a service for looking up commonly referenced values in our dblookup table
Requires
- ext-json: *
README
This package provides an easy way to interface directly with the lookup database. It includes methods to retrieve various groups of data, including multiple different ways of massaging the data before the return.
Installation
composer require oafasys/dblookup
Config
Your .env should include:
DBLOOKUP_HOST=
DBLOOKUP_PORT=
DBLOOKUP_DATABASE=
DBLOOKUP_USERNAME=
DBLOOKUP_PASSWORD=
Please note that there is no underscore between 'DB' and 'LOOKUP'.
Usage
Extending the DbLookup model
You may discover that you need your own custom functions -- to do this, you can extend the DbLookup model and create your own methods there. If you find that several projects need the same custom methods, you may consider adding them to this package for universal access.
Available methods
There are additional methods available besides those listed here. These unlisted methods are internal methods used to obtain the result lists provided by the method below.
All the following methods have a `$for
` variable. This variable can take one of three values that determines how the results are returned:
- null: results returned as is
- 'dropdown': results returned as
`
$value => $label`
pairs - 'api': results returned as objects with
`code
and
label
` properties
getCountries($for = null, $america_first = false, $three_character_code = false)
Returns countries of the world, based on the `country
` table.
`$america_first
` determines if the United States is prioritized at the top of the list (true) or appears in alphabetical order with the rest of the countries (false).
`$three_character_code
`: If true, three-character country codes are returned; false returns two-character country codes instead.
getStates($for = null, $include_territories)
Returns states of the United States, based on the `state
` table.
`$include_territories
`: If true, extended territories (e.g., Puerto Rico, Guam) will be included in the results.
getProvinces($for = null)
Returns provinces of Canada, based on the `state
` table.
getZips($for = null)
Returns American ZIP codes, based on the `zip_county
` table.
getCounties($for = null)
Returns American counties, based on the `zip_county
` table.
This method returns distinct pairings of state and county name to determine unique counties without duplicating rows.
getCountiesByState($state_abbreviation, $for = null)
Returns counties within the given state, based on the `zip_county
` table.
getCountiesByZip($zip, $for = null)
Returns counties within the given ZIP code, based on the `zip_county
` table.
getRecruitingTerms($for = null)
Returns all recruiting terms, based on the `term
` table.
Recruiting terms here are defined by an _inquiry_displaydate in the past and an _application_display_enddate in the future.
getCurrentTerms($for = null)
Returns all current terms, based on the `term
` table.
Current terms here are defined by an _application_display_startdate in the past and an _application_display_enddate in the future.
getUpcomingTerms($for = null)
Returns all upcoming terms, based on the `term
` table.
Upcoming terms are defined by an _application_display_enddate in the future.
getMajorsForSalesforce($for = null)
Returns all majors, based on the `intended_major
` table.
To be included in the results, a row must have something in the _intendedmajor column and the _isenabled column must be true.
getMajorsForPeoplesoft($for = null)
Returns all majors, based on the `program_of_study
` table.
getSchools($for = null, $level = null)
Returns all schools within the University of Pittsburgh based on the level (e.g., undergrad) of students they admit.
`$level
`: null returns every school; other options are UGRD and UPPER
getAdmitTypes($for = null, $app_center)
Returns all admit types available to the given application center.
`$app_center
`: options are UPB, UPG, UPIT, UPJ
Available routes
The dblookup package does provide several routes that you can use to access data. This is useful particularly for Vue components that handle forms, such as the recruiting forms on PRIYA.
dblookup/provinces OR dblookup/states
These routes provide all provinces or all states in API-ready format.
dblookup/state/{abbreviation}/counties
This route will provide an API-ready list of counties within the given state.
dblookup/zip/{zip}
This route will provide an API-ready list of counties within the given ZIP.