Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class IAMSCUController
- {
- // Public Properties
- public String nameSelected { get; set; }
- public String awardLevelSelected { get; set; }
- public String stateSelected { get; set; }
- public String countrySelected { get; set; }
- public String statesEnabled { get; set; }
- public String output { get; set; }
- public List<String> outputs { get; set; }
- private Integer count = 0;
- // Private Properties
- private List<Account> schools { get; set; }
- private String result = null;
- private Id schoolRecordTypeId = null;
- private Id addressRecordTypeId = null;
- private Filter filter = new Filter();
- // Public Methods
- public List<Account> getIAMSCUSChools()
- {
- count++;
- return conn.getRecords();
- }
- // instantiate the StandardSetController from a query locator
- public ApexPages.StandardSetController conn
- {
- get
- {
- if(outputs == null)
- {
- outputs = new List<String>();
- }
- filter.loadFilters(nameSelected, awardLevelSelected, stateSelected, countrySelected);
- output = 'conn is null: ' + (conn == null) + ' changed: ' + filter.changed + ' count: ' + count + ' filters: ' + filter.filterValues;
- outputs.add(output);
- if(conn == null || filter.changed)
- {
- String awardFilter = '';
- String countryStateFilter = '';
- String countryFilter = '';
- String stateFilter = '';
- String queryFilter = '{0}{1}';
- String query = '';
- // Award Level
- if(awardLevelSelected != null && awardLevelSelected != 'Any')
- {
- awardFilter = ' AND account.Institution_Type__c = ||' + awardLevelSelected + '||';
- }
- // - Country & State -
- countryStateFilter = ' AND account.Id IN (SELECT address.Organization_Name__c FROM Address__c address WHERE address.RecordTypeId = ||' + getOrgLocationRecordTypeId() + '|| {0}{1})';
- // Country
- if(countrySelected != null && countrySelected != 'Any')
- {
- countryFilter = ' AND address.Country__c = ||' + countrySelected + '|| ';
- countryStateFilter = String.format(countryStateFilter, new String[] { countryFilter });
- }
- // State
- if(stateSelected != null && stateSelected != 'Any')
- {
- stateFilter = ' AND address.State__c = ||' + stateSelected + '|| ';
- countryStateFilter = String.format(countryStateFilter, new String[] { stateFilter });
- }
- if(countryFilter.length() == 0 && stateFilter.length() == 0)
- {
- countryStateFilter = '';
- }
- else
- {
- countryStateFilter = String.format(countryStateFilter, new String[] { countryFilter, stateFilter });
- }
- queryFilter = String.format(queryFilter, new String[] { awardFilter, countryStateFilter });
- queryFilter = queryFilter.replace('||', '\'');
- // Complete Query
- query = 'SELECT account.Id, account.Name FROM Account account WHERE account.RecordTypeId = \'' + getSchoolRecordTypeId() + '\' AND account.Name LIKE \'%' + nameSelected + '%\'' + queryFilter;
- // Query Result
- conn = new ApexPages.StandardSetController(Database.getQueryLocator(query));
- conn.setPageSize(2);
- }
- return conn;
- }
- set;
- }
- public List<SelectOption> getAwardsLevels()
- {
- List<SelectOption> options = new List<SelectOption>();
- options.add(new SelectOption('Any','Any'));
- options.add(new SelectOption('Colleges/Universities','Colleges/Universities'));
- options.add(new SelectOption('Pre-Baccalaureate','Pre-Baccalaureate'));
- options.add(new SelectOption('Pre-Collegiate','Pre-Collegiate'));
- options.add(new SelectOption('Professional Schools','Professional Schools'));
- options.add(new SelectOption('Seminary/Theological','Seminary/Theological'));
- options.add(new SelectOption('Two-Year Institutions','Two-Year Institutions'));
- return options;
- }
- public List<SelectOption> getCountries()
- {
- List<SelectOption> options = new List<SelectOption>();
- // Used to created a distinct list of countries
- Set<String> countries = new Set<String>();
- // Select all countries that are actually being used.
- for(Address__c[] addresses : [SELECT address.Country__c FROM Address__c address WHERE address.Country__c != '' AND address.RecordTypeId = :getOrgLocationRecordTypeId() AND Organization_Name__c IN (SELECT account.Id FROM Account WHERE account.RecordTypeId = :getSchoolRecordTypeId() AND account.Is_Active__c = 'Yes')])
- {
- for(Address__c address : addresses)
- {
- countries.add(address.Country__c);
- }
- }
- // Create the options
- options.add(new SelectOption('Any','Any'));
- for(String country : countries)
- {
- options.add(new SelectOption(country, country));
- }
- return options;
- }
- public List<SelectOption> getStates()
- {
- List<SelectOption> options = new List<SelectOption>();
- // Used to created a distinct list of countries
- Set<String> states = new Set<String>();
- // Select all countries that are actually being used.
- for(Address__c[] addresses : [SELECT address.State__c FROM Address__c address WHERE address.State__c != '' AND address.RecordTypeId = :getOrgLocationRecordTypeId() AND Organization_Name__c IN (SELECT account.Id FROM Account WHERE account.RecordTypeId = :getSchoolRecordTypeId() AND account.Is_Active__c = 'Yes')])
- {
- for(Address__c address : addresses)
- {
- states.add(address.State__c );
- }
- }
- // Create the options
- options.add(new SelectOption('Any','Any'));
- for(String state : states)
- {
- options.add(new SelectOption(state, state));
- }
- return options;
- }
- public PageReference invokeService()
- {
- Id id = System.currentPageReference().getParameters().get('id2');
- result = [SELECT Name FROM Account WHERE Id = :id].Name;
- return null;
- }
- public PageReference invokeService2()
- {
- // Make global configuration chanegs here
- statesEnabled = (countrySelected == 'Any' || countrySelected == 'UNITED STATES OF AMERICA') ? 'true' : 'false';
- return null;
- }
- // indicates whether there are more records after the current page set.
- public Boolean hasNext {
- get {
- return conn.getHasNext();
- }
- set;
- }
- // indicates whether there are more records before the current page set.
- public Boolean hasPrevious {
- get {
- return conn.getHasPrevious();
- }
- set;
- }
- // returns the page number of the current page set
- public Integer pageNumber {
- get {
- return conn.getPageNumber();
- }
- set;
- }
- // returns the first page of records
- public void first() {
- conn.first();
- }
- // returns the last page of records
- public void last() {
- conn.last();
- }
- // returns the previous page of records
- public void previous() {
- conn.previous();
- }
- // returns the next page of records
- public void next() {
- conn.next();
- }
- // returns the PageReference of the original page, if known, or the home page.
- public void cancel() {
- conn.cancel();
- }
- // Private Methods
- private String getSchoolRecordTypeId()
- {
- // School Record Type
- if(schoolRecordTypeId == null)
- {
- return String.valueOf([SELECT Id FROM RecordType WHERE Name = 'School' AND SObjectType = 'Account'].Id);
- }
- return String.valueOf(schoolRecordTypeId);
- }
- private String getOrgLocationRecordTypeId()
- {
- if(addressRecordTypeId == null)
- {
- return String.valueOf([SELECT Id FROM RecordType WHERE Name = 'Organization Location' AND SObjectType = 'Address__c'].Id);
- }
- return String.valueOf(addressRecordTypeId);
- }
- private class Filter
- {
- public String filterValues { get; private set; }
- public Boolean changed { get; private set; }
- public void loadFilters(String name, String awardLevel, String state, String country)
- {
- setFilters(name, awardLevel, state, country);
- }
- private void setFilters(String name, String awardLevel, String state, String country)
- {
- String filterFmt = '{0}{1}{2}{3}';
- String newFilterValues = String.format(filterFmt, new String[] { name, awardLevel, state, country });
- changed = (filterValues != newFilterValues);
- filterValues = newFilterValues;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement