build query in array for cakephp 3 - cakephp

I am writing an application with search functionalities. There are many filters to be applied so I want to build the filter query outside the find() function in CakePHP 3.4 Application
This is what I want to achieve
$start_year = $this->request->getQuery('start_year');
$end_year = $this->request->getQuery('end_year');
$keyword = $this->request->getQuery('keyword');
$make = $this->request->getQuery('make');
$query_builder = [];
if (!empty($keyword)) {
$query_builder['keyword'] = $keyword;
}
if (!empty($make)) {
$query_builder['make'] = $make;
}
if (!empty($start_year) && empty($end_year))
{
$query_builder['year >'] = $start_year;
}
if (empty($start_year) && !empty($end_year)) {
$query_builder['year <'] = $end_year;
}
if (!empty($start_year) && !empty($end_year)) {
// how to written in BETWEEN query here on year column
}
$results = $this->Model->find()
->where($query_builder);
How to build query in array for IN BETWEEN query ?

if (!empty($start_year) && !empty($end_year)) {
$query_builder['year >='] = $start_year;
$query_builder['year <='] = $end_year;
}

Related

Solr 11 on typo3 10.4 not sorting

I'm indexing a table where I have a date attribute and I want to sort the result by this date value by default using this typoscript file.
This sortBy property of solr in typo3 is not working on my typoscript file but it does on the solr plugin.
https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/Configuration/Reference/TxSolrSearch.html#query-sortby
plugin.tx_solr {
search {
query.sortBy = date_intS desc
#This will not sort my index result but the same property on the solr plugin configuration will
initializeWithEmptyQuery = 1
showResultsOfInitialEmptyQuery = 1
faceting = 1
faceting {
facets {
Year {
label = Year
field = dod_intS
}
}
}
}
index.queue {
obituary = 1
obituary {
table = tx_myext_domain_model_obituary
additionalWhereClause = deleted = 0 AND hidden = 0
fields {
title = COA
title {
432 = TEXT
432.field = person
}
image_intS = SOLR_RELATION
image_intS {
localField = image
}
dod_intS = TEXT
dod_intS {
field = dod
data = date:U
strftime = %Y
}
date_intS = TEXT
date_intS {
field = dod
}
condolences_intS = TEXT
condolences_intS {
field = condolences
}
candles_intS = TEXT
candles_intS {
field = candles
}
url = TEXT
url {
typolink.parameter = {$pages.PIDs.myext.detailPid}
typolink.additionalParams = some_parameters
}
}
}
}
}
But this will work. Don't know what's my problem here.

Setting multiple values from a for loop, using an array in app script

I'm trying to make my code more compact. What I have now works, but it's slow and I don't think it's a best practice. I have a set of array data from Google Sheets, and I want to update a set of page_break values on Google form. I've managed to use a for loop to list all of the page_break ID's, and now I'd like to update them using my array data from Google sheets. I've managed to do this using if statements that filter each page_break ID based on it's title. However, is there a way to make this more slick? Is there a way to turn my page_break ID's into an array and update one with the other?
Thanks for your help. My current code is below.
//Trigger
function updateregentspark() {
var fApp = FormApp;
var formId = fApp.openById('1l5OQflzO3R5nW0ZPTHSGqcog47ADLfcnm7m2_82WokU').getId();
var form = fApp.openById('1l5OQflzO3R5nW0ZPTHSGqcog47ADLfcnm7m2_82WokU');
var formItems = form.getItems();
//Get Spreadsheet Location Tasks
var sApp = SpreadsheetApp;
var spreadsheet = sApp.openById('1iGWSUhaGxGtsxwOUZpcJBD-kXwubcenN0Q0H6lKAyFQ');
var locationSheet = spreadsheet.getSheetByName('Classic Scavenger Hunt Tasks');
var locationTasks = locationSheet.getRange('A2:A41').getValues();
Logger.log(locationTasks);
//Get Form Page Break Sections and Questions
var i, L=0, thisItem, thisItemType, myCheckBoxItem;
L = formItems.length;
for (i=0;i<L;i++) {
thisItem = formItems[i];
thisItemIndex = thisItem.getIndex();
thisItemType = thisItem.getType();
thisItemTitle = thisItem.getTitle();
//Update Page Break Values
if (thisItemIndex>6 && thisItemIndex<16 && thisItemType===fApp.ItemType.PAGE_BREAK) {
var sectionHeadersID = thisItem.getId();
if (thisItemTitle.indexOf('1.') > -1) {
form.getItemById(sectionHeadersID).asPageBreakItem().setTitle(locationTasks[0]);
}
if (thisItemTitle.indexOf('2.') > -1) {
form.getItemById(sectionHeadersID).asPageBreakItem().setTitle(locationTasks[1]);
}
if (thisItemTitle.indexOf('3.') > -1) {
form.getItemById(sectionHeadersID).asPageBreakItem().setTitle(locationTasks[2]);
}
if (thisItemTitle.indexOf('4.') > -1) {
form.getItemById(sectionHeadersID).asPageBreakItem().setTitle(locationTasks[3]);
}
if (thisItemTitle.indexOf('5.') > -1) {
form.getItemById(sectionHeadersID).asPageBreakItem().setTitle(locationTasks[4]);
}
if (thisItemTitle.indexOf('6.') > -1) {
form.getItemById(sectionHeadersID).asPageBreakItem().setTitle(locationTasks[5]);
}
}
};
}
I have no idea what your code is doing and how it could be speed up.
But you can make it a little shorter if you replace these lines:
if (thisItemTitle.indexOf('1.') > -1) {
form.getItemById(sectionHeadersID).asPageBreakItem().setTitle(locationTasks[0]);
}
if (thisItemTitle.indexOf('2.') > -1) {
form.getItemById(sectionHeadersID).asPageBreakItem().setTitle(locationTasks[1]);
}
if (thisItemTitle.indexOf('3.') > -1) {
form.getItemById(sectionHeadersID).asPageBreakItem().setTitle(locationTasks[2]);
}
if (thisItemTitle.indexOf('4.') > -1) {
form.getItemById(sectionHeadersID).asPageBreakItem().setTitle(locationTasks[3]);
}
if (thisItemTitle.indexOf('5.') > -1) {
form.getItemById(sectionHeadersID).asPageBreakItem().setTitle(locationTasks[4]);
}
if (thisItemTitle.indexOf('6.') > -1) {
form.getItemById(sectionHeadersID).asPageBreakItem().setTitle(locationTasks[5]);
}
with this:
for (var j=0; j<6; j++)
if (thisItemTitle.indexOf( (j+1) + '.') > -1)
form.getItemById(sectionHeadersID).asPageBreakItem().setTitle(locationTasks[j]);

How to filter array angular

I have an array containing guidelines. Using a query I want to filter this array using only the guidelines that contains (part of) the query. I have the following code.
filterguideline() {
const query = this.recommendationForm.get('guideline').value;
if (query !== "") {
this.filteredguidelineList = this.Guidelines.filter(function (el) {
return el.toLowerCase().indexOf(this.query.toLowerCase()) > -1;
}.bind(this));
} else {
this.filteredguidelineList = [];
}
}
This does not really work. It does not filter the array, but simply shows all the values in the Guidelines array (irrespective of what the query contains).
Does anybody know the solution?
You need to use arrow function or like below,
if (query !== "") {
this.filteredguidelineList = this.Guidelines.filter(t=>t.toLowerCase().indexOf(this.query.toLowerCase()) > -1);
} else {
this.filteredguidelineList = [];
}
return this.filteredguidelineList;
Using arrow function,
this.filteredguidelineList = this.Guidelines.filter((el) => {
return el.toLowerCase().indexOf(this.query.toLowerCase()) > -1;
});

Sencha Architect - Modify a plugin

i am currently working with Sencha Touch, Sencha Architect 3,
builded a simple list using a pluing called Pullrefresh:
https://github.com/p5hema2/Sencha-PullRefresh-RefreshFn
I am only able to update records if they are new, but updated and deleted records are on my store, but not updated with my view. So i need to modify my plugin. In Sencha Architect i don't know how to solve that.
Is anyone experienced with that? Modifying plugins
Ext.define('TP.extend.override.PullRefresh', { override: 'Ext.plugin.PullRefresh',
onLatestFetched: function(operation) {
var store = this.getList().getStore(),
oldRecords = store.getData(),
old_length = oldRecords.length,
newRecords = operation.getRecords(),
length = newRecords.length,
toInsert = [],
newRecordIds = [],
oldRecordsArr = [],
toRemove = [],
newRecord, newRecordIndex, oldRecord, i;
for (i = 0; i < length; i++) {
newRecord = newRecords[i];
oldRecord = oldRecords.getByKey(newRecord.getId());
newRecordIds.push(newRecord.getId());
if (oldRecord) {
oldRecord.set(newRecord.getData());
} else {
toInsert.push(newRecord);
}
oldRecord = undefined;
}
store.insert(0, toInsert);
oldRecordsArr = store.getRange();
for (i = 0; i < old_length; i++) {
oldRecord = oldRecordsArr[i];
newRecordIndex = newRecordIds.indexOf(oldRecord.getId());
if (newRecordIndex == undefined || newRecordIndex == -1) {
toRemove.push(oldRecord);
}
oldRecord = undefined;
}
store.remove(toRemove);
}
});
Above example is to update deleted records also.

How to check uniquness while pushing values into array using Angular JS?

$scope.displayyears = [];
$scope.Joinyear = function(display) {
$scope.yeardisplay = display;
$scope.yeardisp = $scope.displayyears.push($scope.yeardisplay);
$scope.displayyearss = uniq($scope.yeardisp)
}
it throws error like "uniq is undefined"..How we check uniqueness??
Try checking if the yeardisplay is already in the array before you add it
$scope.displayyears = [];
$scope.Joinyear=function(display){
$scope.yeardisplay=display;
if ($scope.displayyears.indexOf(display) == -1) {
$scope.displayyears.push(display);
}
}

Resources