Can two parameters with the same name be passed to a service? - actionscript-3

I'm passing parameters to a server from a Flash Builder application. I want to search both for "teachers" and for "rooms". I can do this via an HTML page, as follows:
<input type="checkbox" name="searchFor" value="teachers" />teachers
<input type="checkbox" name="searchFor" value="rooms" />rooms
So there are two inputs, both named searchFor. When submitted, the request looks like this:
searchFor: teachers
searchFor: rooms
In other words, two parameters are passed.
I'm trying to do the same thing in Flash Builder using an object called param:
param.query = pQuery;
param.searchFor = "teachers";
param.searchFor = "rooms";
searchUsersService(param);
Flex overwrites the one with the other, as I suspected it would, so all that is submitted is "rooms". Is it possible to pass two parameters with the same name? (or do I need to ask the server guys to rename their search parameters?)
Thanks.

You can't. It will only override the previous value:
param.query = pQuery;
param.searchFor = "teachers";
param.searchFor = "rooms"; //Will obviously override the previous value
searchUsersService(param);
What you can do is:
param.searchFor = [ "teachers", "rooms" ];
Or
param.searchFor = new ArrayCollection();
param.searchFor.add( "teachers" );
param.searchFor.add( "rooms" );
And then in the server side you can get all the values from your array.

Related

laravel-translatable: converting existing text column to translatable

i'm trying to convert and existing text column to translatable. I find that when i add the column name to the the protected translatable array i am no longer able to access it as i did before ($model->key)
I assume that this is because its looked for a translation but can't find one. Is there a way for me to return to contents of the column? I want to retrieve the text and and replace it with a json
when I log $this i can see my object and the correct key: value pairs. Any attempt to access it or convert it to array causes the value to disappear completely
$array = json_decode(json_encode($this), true);
$object = json_decode(json_encode($this), false);
error_log('$this '.print_r($this,true)); // includes the key 'myKey' with correct value
error_log('$array '.print_r($array['mykey'],true)); // empty
error_log('$object '.print_r($object->mykey,true)); // empty
You can use this method if you want to get all translated values of a particular column as an array.
public function update(ModelName $modelItem)
{
return $modelItem->getTranslations('column_name');
}
//result
[
'en' => 'test',
'tr' => 'deneme',
]
Resource:
https://github.com/spatie/laravel-translatable#getting-all-translations-in-one-go
if you want to get the content that still not store as json translation, you can use this eloquent method.
$model->getRawOriginal('your translation's column name');
it will get your column value.

Implement CSV download using current filters and sort

I need to implement a download feature. It will read the data in the react-data-grid (adazzle), respecting the current columns, filters and sort, and create an array json (or comma separated strings) I can then pass to the react-csv module.
I have a data structure populated from the backend but it is not filtered nor sorted. I need to be able to ask the grid for it's data on a row-by-row basis. Can anyone point me in the right direction?
Without code or some context, I can't answer with certainty...
You supply the rowGetter prop with the collection to display, or the method to get the rows to display...I'm thinking if you filtering, then most likely you've got some sort of mechanism supporting that... Either way, you can use this property's value somehow to get exactly what you see in the grid.
If you literally want to interrogate the grid, you could try adding a reference to the grid, and then see if you can ask it for the row data. I can't remember with certainty that I saw a rows prop in the grids available props via the ref, but I imagine you should be able to (**,)
...
handleExport = async => {
const exportRows = rows;
// const exportRows = getRows(initialRows, filters);
// const exportRows = this.state.gridref.CurrentRows DISCLAIMER:CurrentRows is just for giving the idea... check out the ref yourself to see if it's possible to get the rows via the grid refs props.
downloadCSV( exportRows )
}
...
<ReactDataGrid
ref={input => {this.state.gridref = input}}
columns={columns}
rowGetter={i => rows[i]} // or maybe rowGetter={i => getRows(initialRows, filters)[i]}
rowsCount={rows.length}
onGridSort={(sortColumn, sortDirection) =>
setRows(sortRows(initialRows, sortColumn, sortDirection))
}
/>
I've only ever [set / initialised] the this.state.gridRef prop in my constructor, but I guess you could also [set / initialise] it in your componentDidMount as well...
initialise like this:
this.state.gridRef = React.createRef()

Updating Data within a unique randomly generated ID/KEY in firebase using HTML

function updateFirebase(){
const fb=firebase.database().ref()
//get field values
author = document.getElementById('uname').value
user_email = document.getElementById('umail').value
data = {author, user_email}
//update database
fb.child('Article/').update(data);
}
</script>
I have problem with my code. I want to update the data inside a table named "Article". Article has generated items with a unique key/id and each key has its own content. Lets say I want to be able to edit the "author" or change the "title", the problem is they each have a randomly generated key/id that I cant access. for example that "-LS39kReBHrKGqNj7h_". I can only save the data inside the "Article" tree but I cant change the "author" or the "title". How do i get a workaround this so I can change those properties?
Here is how my firebase looks like
It depends whether you have the record reference on the frontend before update or not (whether you have fetched it before you are trying to update it).
But generally, you have two options
You can store the key reference as an "id" field on the object.
To achieve that, you need two step process when creating the record at the first place
// Creates a new record in DB and returns it to you. Now you can get the "key"
const newRecord = firebase.database().ref('TABLE_NAME_REF').push();
newRecord.set({
id: newRecord.key
...
});
This is great if you fetch the list of records on the frontend and then you want to update one of them. Then you can just build the ref path like this
fb.child('Article/' + record.id ).update(data); // where record is the prefetched thing
You need to find the element based on its fields first. And once you have it, you can update it right away.
To achieve this, you can simply do something like:
firebase.database()
.ref('TABLE_NAME_REF') // let's say 'Article'
.orderByChild('RECORD_KEY') // Let's say 'author'
.equalTo('KEY_VALUE') // let's say 'zoranm'
.limitToFirst(1)
.once("value")
.then(res => {
// You need to loop, it always returns an array
res.forEach(record => {
console.log(record.key); // Here you get access to the "key"
fb.child('Article/' + record.key ).update(data); // This is your code pasted here
})
})

Validaing Multiple, Specific Form Fields with errors()

I am building a multi-step form input (a "wizard") where the user input parts of an entity over multiple form input views. At each step, I want to validate only the input data (not the entire entity).
My question is how to use error() with an array of field names.
The model has 12 fields with validation rules. I want to validate 3 of those in one controller action.
So, in this controller action, I get three inputs
$thedata = $this->request->data;
This results in:
['number' => '102','color' => 'blue','size' => 'large']
I then make an array of field names:
$thearray = array_keys($thedata);
This results in:
[
(int) 0 => 'number',
(int) 1 => 'color',
(int) 2 => 'size']
Now I would like to check these three fields for errors.
$errors = $this->Items->newEntity($this->request->data)->errors($thearray);
This results in checking ALL 12 fields with validation defined, not just the three in the array, and it fails validation (it picks up all the errors in the entity).
If I define only ONE field to check it works:
$errors = $this->Items->newEntity($this->request->data)->errors('number');
This correctly validates only the field 'number' and produces the desired result.
However, passing an array of fields instead of a string with a single field name validates ALL fields requiring validation.
Also, I tried hard-coding an array as a parameter of errors():
$errors = $this->Items->newEntity($this->request->data)->errors(['number','color']);
That also checks all 12 fields in the table definition, not just these two.
So the question is, how do you prepare the array and pass it to the errors() method if you want to check only two or three specific fields?
Thanks in advance for any advice!
D
Thanks in
According to the docs errors can take a $field argument, but not an array. If you want to validate multiple fields without validating all of them, you could loop over $thearray.
$item = $this->Items->newEntity($this->request->data);
foreach ($thearray as $error) {
$errors[] = $item->errors($error);
}

Inserting 2 lists into a URL

I have 2 lists like this:
Type = ['Homeless+Shelter','Food+Pantry','Seniors']
Where = ['55410','55414','54669']
And I would like to add them to a URL to create a search to use an API. Here is what I have:
for elem in Type:
url = 'https://api.citygridmedia.com/content/places/v2/search/where?type=%s&where=55410&format=json&publisher='PUBLISHER_KEY'&rpp=50' % (elem)
urllib.urlretreieve(url, 'CityGrid_Search.json)
The URL is going to an API then saving the data as a JSON file. I am inputting the Type list into the url where 'type=%s'
I would like to input the list of zipcodes that correspond to the word in the Type list where . This code works for iterating through Type, but I have to manually change the zipcode in the URL to the corresponding word. Is it possible to put list items in two different spots?
Try this code,
Type = ['Homeless+Shelter','Food+Pantry','Seniors']
Where = ['55410','55414','54669']
PUBLISHER_KEY = ""
for typeObj, whereObj in zip(Type, Where):
url = 'https://api.citygridmedia.com/content/places/v2/search/where?type=%s&where=%s&format=json&publisher=%s&rpp=50' % (typeObj, whereObj, PUBLISHER_KEY)
print url
I think, it'll help you out.