public with sharing class CM_SearchOpportunity {
|
public List<Opportunity> results {get; private set;}
|
public Boolean getIsOverLimit() {
|
if (results != null && results.size() > 30) {
|
return true;
|
}
|
return false;
|
}
|
|
public CM_SearchOpportunity() {
|
this.results = new List<Opportunity>();
|
}
|
|
public void search() {
|
// 検索条件を用意
|
String query = System.currentPageReference().getParameters().get('q');
|
String visitorPlaceId = System.currentPageReference().getParameters().get('r');
|
// 全角::をreplace
|
query = query.replaceAll('::', '::');
|
if(query == null || query == '' || query.length() < 2) {
|
return;
|
}
|
this.search(query, visitorPlaceId);
|
}
|
public void search(String query, String visitorPlaceId) {
|
List<String> qwords = new List<String>();
|
List<String> qwordstmp = query.split(' ');
|
String nameCondition = '';
|
for (String qword : qwordstmp) {
|
if (String.isBlank(qword) == false) {
|
qwords.add('%' + String.escapeSingleQuotes(qword.replaceAll('%', '')) + '%');
|
nameCondition += ' Name like \'' + qwords[qwords.size() - 1] + '\' and';
|
}
|
}
|
|
String queryString = '';
|
// try{
|
queryString = ControllerUtil.getOppSearchSQOL(visitorPlaceId, nameCondition);
|
// }
|
// catch ( System.QueryException qe) {
|
// this.results = new List<Opportunity>();
|
// return;
|
// }
|
|
system.debug('queryString=' + queryString);
|
if(queryString == null || queryString == ''){
|
return;
|
}
|
this.results = (List<Opportunity>) Database.query(queryString);
|
}
|
}
|