I using https://github.com/ParsePlatform/parse-php-sdk.
I want to send notify 2 other devices.
But it's only send notify for device token is 'abcdef'.
How to send notify 2 other devices?
Thanks all,
$query = ParseInstallation::query();
$query->equalTo('deviceToken', 'xxxxx');
$query->equalTo('deviceToken', 'abcdef');
$data = [
'data' => ['alert' => 'Hello, this is a test'],
'where' => $query,
];
ParsePush::send(
$data
);
I believe your dual equalTo queries are overwriting each other. From what I understand, equalTo matches a single value. You should be able to see this behavior by inspecting a vardump of your $query after each equalTo call.
You should instead use containedIn (http://parseplatform.github.io/parse-php-sdk/classes/Parse.ParseQuery.html#method_containedIn) and pass in an array of values that you'd like the query to match. E.g., $query->containedIn('deviceToken', ['abcdef', 'xxxxx']).
Note: I don't have a parse PHP project handy so the above code isn't tested, but the general logic should work.
Related
I have been using a formula to uniquely secure id's gathered from database before they are presented to the client.
However, as my code grown complex, I've fallen into this pitfall: I have two separate cases returning json that need to use the same id. Because my securing function produces a unique hash and key at each perform, hashed ID gathered from one case cannot be encrypted in the other one that needs to use it. Therefore as a solution, I thought that sending hashed id gathered from first case back to first case again, decrypt it there and then somehow pass it to the other case without client never having chance to catch the real id.
All the codes work fine, my problem is matching the id drawn from first case that is to be used in the second case that also sends data back before case break, which is simply a client-triggered loop. I am providing codes in case you would ask it. The problem is simply matching the same id with different unique hash in two separate php cases. Sorry if I made this more complicated than it should have.
This is the first case I am using for filling a dropdown select.
case "tutorRefresh":
$tutorSelectSql = "SELECT id, tname, tsurname FROM tutors";
$tutorSelectQry = pg_query($tutorSelectSql);
while($row = pg_fetch_array($tutorSelectQry)){
$id = lockPandoraBox($row['id']);//encrypt the id
$response[] = array("id" => $id,
"tname" => $row['tname'],
"tsurname" => $row['tsurname']);
};
if(isset($response)){
echo json_encode($response);
} else {
$response = array("val" => 0);
echo json_encode($response);
}
break;
This is the function used by the second case that updates the table data, since it is too long and complex for a single issue to post it all here, I only shared relevant part of the code. I have to match the id encrypted in above code with the one encrypted here since this code fills in the table while the code above just fills in the dropdown select.
$crypted = lockPandoraBox($row["appid"]);
$tutorID = lockPandoraBox($row["tutorid"]);//encrypting id
$clientID = lockPandoraBox($row["clientid"]);//same method for another id, ignore this.
$fApp["hours"][] = array("recId" => $crypted,
"hour" => $row["hour"],
"tutor" => $tutorArr["tname"]." ".$tutorArr["tsurname"],
"tutorId" => $tutorID,// id that I need to use
"client" => $clientArr["cname"]." ".$clientArr["csurname"],
"clientId" => $clientID,
"department" => $dept,
"degree" => $deg,
"purpose" => $purposeArr["pname"],
"purposeId" => $row["purpose"],
"contact" => $clientArr["cgsm"],
"email" => $clientArr["cemail"],
"tutorAbsCheck" => $tutorAbsArray["id"],
"tutorAbsReason" => $tutorAbsArray["reason"],
"clientAbsCheck" => $clientAbsArray["id"],
"clientAbsReason" => $clientAbsArray["reason"]
);
/* */
}
return json_encode($fApp);
}
Lastly, this is the code in my main page which works in click event function that triggers the event I need. It simply changes select box's selection for the matching clicked record. It picks the id from table and tries to match it with the id in select box. Thanks in advance.
$("#tutorEdit").val(dayData["hours"][$(el.currentTarget).attr("key")].tutorId).trigger("change");
I think it will be better to change the structure a bit to combine both cases in order to achieve my goal. I wanted to know if I could get around it.
I have a datase table with a list of books. Below is my sql statement:
SELECT `Book`.`id` , `Book`.`name` , `Book`.`isbn` , `Book`.`quantity_in_stock` , `Book`.`price` , (`Book`.`quantity_in_stock` * `Book`.`price`) AS `sales`, concat(`Author`.`name`, ' ', `Author`.`surname`) AS `author`
FROM `books` AS `Book`
LEFT JOIN authors AS `Author`
ON ( `Book`.`author_id` = `Author`.`id` )
WHERE (`Book`.`quantity_in_stock` * `Book`.`price`) > 5000.00
The query works fine and the workflow works fine too. However, I am wanting to access this through an API and make the 5000.00 value configurable through a variable bar.
Question is how do I make this possible such that when I call my API with my endpoint below it works?
https://domain.flowgear.io/5000booklist/{sales_value}
What I want is to be able to re-use my workflow via an API and just pass a sales value I want to query the table against. Sales value can be 2000 or 5000 depending on what I want to achieve.
Add a variable bar and add a property to it called "salesValue"
In the workflow detail pane, provide this url: "/booklist/{salesValue}" - the value in braces must match the name of the property in the variable bar
Add a Formatter, put your SQL template including "WHERE (Book.quantity_in_stock * Book.price) > {salesValue}" in the Expression property then add a custom field called salesValue and pin that from the variable bar salesValue property. Set Escaping to SQL.
Take the output of the Formatter and plug that into the SQL Query property of a SQL Query Connector.
Add another variable bar, and add the special properties FgResponseBody and FgResponseContentType
Pin the SQL result to FgResponseBody and set FgResponseContentType to 'text/xml'
If you want to return JSON, convert the result from the SQL Query to JSON using JSON Convert and then pin that to FgResponseBody and set FgResponseContentType to 'application/json'
#sanjay I will try to give you an overview of what I did back then when I was experimenting with Flowgear through PHP following instructions from here.
I am not sure if you are also invoking the Flowgear REST API through PHP or any other language but regardless I presume logic should remain the same.
What I did was to wrap the PHP CURL sample code in a class so that I can be able to reuse it. Below is a code I wrote for a simple select query:
<?php
//Require the FlowgearConnect class
require_once '/path/to/flowgear_class_with_api_call.php';
try{
$workflow = new FlowgearConnect(return include 'endpoints.php');
$serial = $_POST['serial'];
$clientId = $_POST['client_id'];
//Get the results
$sql = '';
if(empty($serial)){
$conditions = sprintf(' `a`.`client_id` = %s AND `a`.`serial` > -1 ORDER BY `a`.`serial` ASC', $clientId);
}else{
$conditions = ' `a`.`serial` = ' . $serial;
}
/**
In your workflow you will most probably have a VARIABLE BAR that holds your request parameters which is what $conditions speaks to.
*/
$conditions = array('conditions' => $conditions);
$results = $workflow->getResults('orders', 'orders', $conditions);
}catch(catch any exceptions thrown by the API here){
//Log the exceptions here or do whatever
}
The listing above should be self explanatory. Below I will show you the functions I have made use of from my FlowgearConnect class. This is not a standard way as you may configure your code differently to suite your needs.
//FlowgearConnect constructor
class FlowgearConnect
{
protetced $endpoints = [];
protected $domain = "https://your-domain.flowgear.io";
public function __construct(array $endpoints)
{
$this->endpoints = $endpoints;
}
public function getResults($model, $workflow, $options= array())
{
$endpoint = $this->getEndpoint($model, $workflow);
$results = array();
if(!empty($endpoint)){
$results = FlowgearInvoke::run($authOpts, $endpoint, $options, array('timeout' => 30));
}
return $results;
}
....
}
The enpoints.php file, as mentioned before, just returns an array of configured endpoints and/or worflow names from within flowgear console. Below is a excerpt of how mine looked like:
return array(
'orders' => array(
'shipped_orders' => '/shipped_orders',
//etc
),
'items' => array(
'your_model' => '/workflow_name_from_flowgear_console',
),
);
This is just a basic select query with Flowgear's REST API using PHP. If you are lucky you should get your records the way you have configured your response body for your workflow.
Below is a typical testing of a workflow and what you should get back in your API.
I advice you to first create your workflows on your flowgear console and make sure that the produce the desired output and the extract the parts that you want changed no your query, move them to a variable bar for your request and have them injected at run-time based on what you looking to achieve. This explanation can be substituted for other operations such as update and/or delete. Best thing is to understand flowgear first and make sure that you can have everything working there before attempting to create a restful interactive application.
Caution: It's over a year that I have since worked with this platform so you might find errors in this but I am hoping that it will lead you to finding a solution for your problem. If not then perhaps you can create a repo and have me check it out to see how you are configuring everything.
I'm able to query my dynamodb tables, but I only want to retrieve the actual value. I don't want the formatting output. This same question has been answered here for Java, but I'm looking for the PHP solution:
Retrieving just the item value from a dynamodb table?
Here is my getitem query:
$response = $dynamodb->getItem(array(
"TableName" => $tableName,
"ConsistentRead" => true,
"Key" => array(
"userguid" => array(Type::STRING => $userguid)
),
"AttributesToGet" => array("token")
));
print_r($response["Item"]["token"]);
Here is the output:
Array
(
[S] => 9d194513
)
All I want to get back is:
9d194513
I assumed the logical answer would be to change the last line to:
print_r($response["Item"]["token"]["S"]);
But then my code doesn't return anything at all. Obviously still learning PHP here, and any help would be appreciated.
Don't use print_r function, just either echo your variables
echo $response["Item"]["token"]["S"];
or store in a variable for later use
$res_token = $response["Item"]["token"]["S"];
You can also use the getPath convenience method built into the Model object that the SDK returns for operations.
echo $response->getPath('Item/token/S');
For more information about working with responses in the SDK, see the Response Models page in the AWS SDK for PHP User Guide.
Though it's an old question but for anyone coming to this page for seeking answer, this is how I have done it.
getItem returns a Resultobject. You can call the get() function of the SDK, which will give you an array containing the exact value.
$params = [
"TableName" => "EpgApiAccessCount",
"Key" => $this->marshalJson('
{
"ApiUserKey": "' . $apiUserkey . '"
}
')
];
$result = $this->client->getitem($params);
if (!$result instanceof ResultInterface) {
return 0;
}
$item = $this->unmarshalItem($result->get("Item"));
return $item["AccessCount"];
Of course your value and table name will be different, and you can print or do anything else with the value.
Using the Mailchimp API PHP example, I'm trying to pass a specific list group based on a drop-down menu value. I keep getting an error that $groupsval isn't a valid Interest Group. Eventually I'd set this up with some elseif statements for the other group options, but can't get this basic conditional working. Any insight would be greatly appreciated!
$groups = $_POST['listgroup']; //get listgroup form value, set as $groups var.
if($groups == "broccoli") { // if it's broccoli, declare it a vegetable
$groupsval = "vegetables";
}
$merge_vars = Array(
'EMAIL' => $_GET['email'],
'FNAME' => $_GET['fname'],
'LNAME' => $_GET['lname'],
'GROUPINGS'=>array(
array('name'=>'Food', 'groups'=>'$groupsval'),
)
);
You need to remove the single quotes on the right side of the => from 'groups'=>'$groupsval' to just be 'groups' => $groupsval
PHP does not process variables inside of single quotes.
Hope this helps
This is really old but just in case somebody needs it, there are 2 things to fix here:
1- As jeff pointed out you need to delete the quotation marks around $groupsval
2- $groupsval actually needs to be an array $groupsval = array("vegetables"). That's just in case you want them in more then 1 group
I have created a form in which i embed another form. My question is about this embedded form - I'm using a sfWidgetFormDoctrineChoice widget with option multiple set to true. The code for this embedded form's configure method:
public function configure()
{
unset($this['prerequisite_id']);
$this->setWidget('prerequisite_id', new sfWidgetFormDoctrineChoice(array(
'model' => 'Stage',
'query' => Doctrine_Query::create()->select('s.id, s.name')->from('Stage s')->where('s.workflow_id = ?', $this->getOption('workflow_id') ),
'multiple' => true
)));
$this->setValidator('prerequisite_id', new sfValidatorDoctrineChoice(array(
'model' => 'Stage',
'multiple' => true,
'query' => Doctrine_Query::create()->select('s.id, s.name')->from('Stage s')->where('s.workflow_id = ?', $this->getOption('workflow_id') ),
'column' => 'id'
)));
}
I unset the prerequisite_id field because it is included in the base form, but I want it to be a multiple select.
Now, when I added the validator, everything seems to work (it passes the validation), but it seems like it has problems saving the records if there is more than one selection sent.
I get this PHP warning after submitting the form:
Warning: strlen() expects parameter 1 to be string, array given in
D:\Development\www\flow_dms\lib\vendor\symfony\lib\plugins\sfDoctrinePlugin\lib\database\sfDoctrineConnectionProfiler.class.php
on line 198
and more - I know, why - in symfony's debug mode I can see the following in the stack trace:
at Doctrine_Connection->exec('INSERT INTO stage_has_prerequisites
(prerequisite_id, stage_id) VALUES (?, ?)', array(array('12', '79'),
'103'))
So, what Symfony does is send to Doctrine an array of choices - and as I see in the debug sql query, Doctrine cannot render the query correctly.
Any ideas how to fix that? I would need to have two queries generated for two choices:
INSERT INTO stage_has_prerequisites (prerequisite_id, stage_id) VALUES (12, 103);
INSERT INTO stage_has_prerequisites (prerequisite_id, stage_id) VALUES (79, 103);
stage_id is always the same (I mean, it's set outside this form by the form in which it is embedded).
I have spend 4 hours on the problem already, so maybe someone is able to provide some help.
Well, I seem to have found a solution (albeit not the best one, I guess). Hopefully it'll be helpful to somebody.
Finally, after much thinking, I have concluded that if the problem comes from the Doctrine_Record not being able to save the record if it encounters an array instead of a single value, then the easiest solution would be to overwrite the save() method of the Doctrine_Record. And that's what I did:
class StageHasPrerequisites extends BaseStageHasPrerequisites
{
public function save(Doctrine_Connection $conn = null)
{
if( is_array( $this->getPrerequisiteId() ) )
{
foreach( $this->getPrerequisiteId() as $prerequisite_id )
{
$obj = new StageHasPrerequisites();
$obj->setPrerequisiteId( $prerequisite_id );
$obj->setStageId( $this->getStageId() );
$obj->save();
}
}
else
{
parent::save($conn);
}
}
(...)
}
So now if it encounters an array instead of a single value, it just creates a temporary object and saves it for each of this array's values.
Not an elegant solution, definitely, but it works (keep in mind that it is written for the specific structure of the data and it's just the effect of my methodology, namely See What's Wrong In The Debug Mode And Then Try To Correct It Any Way Possible).