Sement by tag Onesignal - php

I try send push notifications only to users segmented by tags from my app with Onesignal by php but the notificatión is send to all users, this is my code:
$fields = array(
'app_id' => $onesignal_wp_settings['app_id'],
'headings' => array("en" => get_the_title($post->ID), "es" => get_the_title($post->ID)),
'isAnyWeb' => false,
'url' => get_permalink($post->ID),
'contents' => array("es" => max_words(array(
"max" => 40,
"id_post" => $post -> ID
)),
"es" => max_words(array(
"max" => 40,
"id_post" => $post -> ID
))),
'tags' => array(
array(
"key" => "municipio",
"relation" => "=",
"value" => (string)$id_municipio
),
array(
"operator" => "OR"
),
array(
"key" => "estado",
"relation" => "=",
"value" => (string)$id_estado
)
)
);

The contents field of your code isn't correct. It can only contain an array of languages with a string for it's contents. Your post_id should be added to data instead.
'contents' => array("en" => "English message",
"es" => "Spanish message"),
'data' => array("id_post" => $post -> ID)
Your tags field looks correct however I am not sure what your variables contain. You should print out your full JSON payload to make sure you don't have any errors in the format.

Related

PHP adding another item to a array

I would like to add new elements to the array from the html form, but I don't understand how to add new element to the main array with this structure I tried array_push, but I failed
$menu = array(
"1" => array (
"title" => 'Glowna',
"page" => 'home',
"url" => "index.php",
),
"2" => array (
"title" => "Cennik",
"page" => 'services',
"url" => "index.php"
),
"3" => array (
"title" => 'Portfolio',
"page" => 'portfolio',
"url" => "index.php"
),
"4" => array (
"title" => 'O nas',
"page" => 'about',
"url" => "index.php"
),
"5" => array (
"title" => 'Kontakt',
"page" => 'contact',
"url" => "index.php"
)
);
?>
You will need to define a key, which would most likely be "6", then supply an array as the value. Your code might look something like this:
$menu['6'] = array( 'title' => "Archives",
'page' => "archives",
'url' => "archives.php");
That's all there is to it.
Your $menu array is called an associative array as it has string values for keys.
For associative arrays you can't use array_push.
What you can do is
$menu["key"] = array("title" => 'Kontakt',"page" => 'contact',"url" => "index.php")
But looking at your array, you can have numeric indexes instead of string. If you use the following structure, you can make use of array_push
$menu = array(array ("title" => 'Glowna',
"page" => 'home',
"url" => "index.php"),
array ( "title" => "Cennik",
"page" => 'services',
"url" => "index.php"))
Notice the removal of "string keys" (ex: "1" => array()),
Now you can use array_push;
array_push($menu, array("title" => "Cennik", "page" => 'services', "url" => "index.php"))
I tried doing array_push with your example and it worked perfectly fine, what's the problem?
Regarding what others said below, it seems php still recognizes string keys if they are numerical, because array push works perfectly fine even though the arrays keys are numerical strings. What they said maybe applies to keys that are true strings or not in numerical order.
$menu = array(
"1" => array (
"title" => 'Glowna',
"page" => 'home',
"url" => "index.php",
),
"2" => array (
"title" => "Cennik",
"page" => 'services',
"url" => "index.php"
),
"3" => array (
"title" => 'Portfolio',
"page" => 'portfolio',
"url" => "index.php"
),
"4" => array (
"title" => 'O nas',
"page" => 'about',
"url" => "index.php"
),
"5" => array (
"title" => 'Kontakt',
"page" => 'contact',
"url" => "index.php"
)
);
array_push($menu, array("title" => 'number 6', "page" => 'something', "url" => "works.php"));
var_export($menu);
Results:
array (
1 =>
array (
'title' => 'Glowna',
'page' => 'home',
'url' => 'index.php',
),
2 =>
array (
'title' => 'Cennik',
'page' => 'services',
'url' => 'index.php',
),
3 =>
array (
'title' => 'Portfolio',
'page' => 'portfolio',
'url' => 'index.php',
),
4 =>
array (
'title' => 'O nas',
'page' => 'about',
'url' => 'index.php',
),
5 =>
array (
'title' => 'Kontakt',
'page' => 'contact',
'url' => 'index.php',
),
6 =>
array (
'title' => 'number 6',
'page' => 'something',
'url' => 'works.php',
),
)
Live demo: http://sandbox.onlinephpfunctions.com/code/76d5dab43255459455f2e80e37ab281486009fc4

onwsignal web notification error

actually i am tring to get data from url which i already got but i can't able to insert data into the array please check values are dummy1 dummy2
Array ( [id] => 491 [headings] => ‘సౌందర్య లహరి’ ఎలా ఉంది అంటే..? [content] => శ్రీ వాసు దర్శకత్వం లో బెల... [userPic] => 682473.jpg ) JSON sent: {"app_id":"35fi6c27-5f39-4s9f-94db-79bf123g0f9","included_segments":["All"],"data":{"foo":"bar"},"contents":{"en":"dummy1"},"headings":{"en":"dummy2"},"url":"http:\/\/www.gggg.in\/view.php?id=[id]","chrome_web_image":"http:\/\/www.ggg.in\/admin\/user_images\/[userPic]"} JSON received: {"allresponses":"{\"id\":\"f66a03a4-1b17-8tf3-93ed-f3ad6rt7cdb9\",\"recipients\":6}"}
the above data got from url
http://www.ggg.in/gistfile1.php?id=491&headings=%E2%80%98%E0%B0%B8%E0%B1%8C%E0%B0%82%E0%B0%A6%E0%B0%B0%E0%B1%8D%E0%B0%AF%20%E0%B0%B2%E0%B0%B9%E0%B0%B0%E0%B0%BF%E2%80%99%20%E0%B0%8E%E0%B0%B2%E0%B0%BE%20%E0%B0%89%E0%B0%82%E0%B0%A6%E0%B0%BF%20%E0%B0%85%E0%B0%82%E0%B0%9F%E0%B1%87..?&content=%20%E0%B0%B6%E0%B1%8D%E0%B0%B0%E0%B1%80%20%E0%B0%B5%E0%B0%BE%E0%B0%B8%E0%B1%81%20%E0%B0%A6%E0%B0%B0%E0%B1%8D%E0%B0%B6%E0%B0%95%E0%B0%A4%E0%B1%8D%E0%B0%B5%E0%B0%82%20%E0%B0%B2%E0%B1%8B%20%E0%B0%AC%E0%B1%86%E0%B0%B2...&userPic=682473.jpg
and i need to insert the values in this function
function sendMessage() {
$content = array(
"en" => 'dummy1'
);
$headings = array(
"en" => 'dummy2'
);
$hashes_array = array();
$fields = array(
'app_id' => "35fi6c27-5f39-4s9f-94db-79bf123g0f9",
'included_segments' => array(
'All'
),
'data' => array(
"foo" => "bar"
),
'contents' => $content,
'headings' => $headings,
'url' => 'http://www.gggg.in/view.php?id=[id]',
'chrome_web_image' => 'http://www.ggg.in/admin/user_images/[userPic]',
);
OneSignal does not support substituting variable data directly into API calls. However, you can achieve this with Tag and Variable Substitution: https://documentation.onesignal.com/docs/personalization
this is the solutions for this Question i asked about
actually i have a varable passing throug url and i need them to insert into function
$array = [
'id' => 498,
'value2' => 'యూట్యూబ్‌లో “భరత్ అనే నేను” అన్ కట్ సీన్లు..!',
'value1' => 'కొరటాల శివ దర్శకత్వం లో సూ...',
'value3' => '525722.jpg'
];
sendMessage($array);
function sendMessage($array) {
$content = array(
"en" => $array['value1']
);
$headings = array(
"en" => $array['value2']
);
$hashes_array = array();
$fields = array(
'app_id' => "31pe2347-5i39-4y9f-2222-79b5875f00f9",
'included_segments' => array(
'All'
),
'data' => array(
"foo" => "bar"
),
'contents' => $content,
'headings' => $headings,
'url' => 'http://w...content-available-to-author-only...9.in/view.php?id=' . $array['id'],
'chrome_web_image' => 'http://w...content-available-to-author-only...9.in/admin/user_images/' . $array['value3'],
);
print_r($fields);
}

orderby and order not working for numeric meta_query

I have a set of default arguments that I pass values in. All of them work when it comes to order and orderby except for member_count which in the database is saved as a string but needs to behave like a number. For this reason I have the type set as numeric and I suspect that the sql casting is working when you do the comparing but not working when you are doing the ordering? Just a guess.
public $default_args = array(
'post_type' => 'clans',
'post_status' => 'publish',
'posts_per_page' => -1,
"s" => '',
"post__in" => "",
"orderby" => '',
"order" => '',
"date_query" => array(
"before" => '',
"after" => '',
"inclusive" => true
),
"meta_query" => array(
"relation" => "AND",
"average_skill_level" => array(
"key" => "average_skill_level",
"compare" => "EXISTS",
),
"activity_level" => array(
"key" => "activity_level",
"compare" => "EXISTS",
),
"language" => array(
"key" => "language",
"compare" => "EXISTS",
),
"applications" => array(
"key" => "applications",
"compare" => "EXISTS",
),
"member_count" => array(
array(
"key" => "member_count",
"compare" => ">=",
"type" => "NUMERIC"
),
array(
"key" => "member_count",
"compare" => "<=",
"type" => "NUMERIC"
)
)
)
);
some of the values i put for orderby have been member_count and meta_value_num member_count and of course DESC and ASC for order
"member_count" => array(
"member_min" => array(
"key" => "member_count",
"compare" => ">=",
"type" => "NUMERIC"
),
"member_max" => array(
"key" => "member_count",
"compare" => "<=",
"type" => "NUMERIC"
)
)
I named the two arrays inside member_count and ended up sorted by those keys.

MongoDB find document in collection based on 2 IDs PHP

I was wondering how to find document in collection based on UIDa and UIDb which could be also vice versa.
So for example I want to get all documents where
value UIDa = inputA and UIDb = inputB
or value UIDa = inputB and UIDb = inputA
{
"_id" : ObjectId("5572f65dc89782b9398b4fc0"),
"sender" : "senderID",
"recipient" : "recipientID",
"message" : "messagehere",
"time" : "1433092679",
"state" : "1"
}
I have this query but it doesn't work because some of the documents are missing.
$query = $db->collection->find(array(
'$or' => array(
array(
'recipient' => $uid,
'sender' => $fuid,
'state' => '1',
'time' => array(
'$lt' => $last_update
)
),
array(
'recipient' => $fuid,
'sender' => $uid,
'state' => '1',
'time' => array(
'$lt' => $last_update
)
)
)
)
)->limit(20);
thanks in advance.
Well I think what you are looking for the $in operator.
$query = $db->collection->find(array(
'recepient' => array('$in' => array($uid, $fuid)),
'sender' => array('$in' => array($uid, $fuid)),
'state' => '1',
'time' => array('$lt' => $last_update)
)
)->limit(20);

TYPO3 suggest wizard, search in substring

I use the suggest wizard in TYPO3 backend.
The following code is in the tca:
'tx_db_colors' => array (
'exclude' => 0,
'label' => 'Farbe',
'config' => array (
"type" => "group",
"allowed" => "tx_db_colors",
"foreign_table" => "tx_db_colors",
"internal_type" => "db",
"size" => 1,
"minitems" => 0,
"maxitems" => 1,
'items' => array(array('', ''),),
'wizards' => array(
'suggest' => array(
'type' => 'suggest',
),
),
)
),
Is there a solution, to get matched records in substring of the label, not from scratch?
Example:
The records label is named 'coffee black'
When I type 'co' into the search field, the record will be shown.
'blac' won't match to any record.
Is this possible to find this record, when I type in a substring? Else I have to extend the autocompletion. TYPO3 Core, yuk! :-)
Thank you in advance!
After hours, I found the solution.
You have to write the tca like this:
'tx_db_colors' => array (
'exclude' => 0,
'label' => 'Farbe',
'config' => array (
"type" => "group",
"allowed" => "tx_db_colors",
"foreign_table" => "tx_db_colors",
"internal_type" => "db",
"size" => 1,
"minitems" => 0,
"maxitems" => 1,
'items' => array(array('', ''),),
'wizards' => array(
'suggest' => array(
'type' => 'suggest',
'default' => array(
'searchWholePhrase' => 1
),
),
),
)
),
Just add
'default' => array(
'searchWholePhrase' => 1
),
into the 'suggest' array.

Categories