Unable to get result from https://www.yammer.com/api/v1/groups.json?mine=1 - yammer

I am trying get all groups of current user from Yammer, I have tried using
https://www.yammer.com/api/v1/groups.json?mine=1
https://www.yammer.com/api/v1/users/current.json?include_group_memberships=true
I am using below code
yam.platform.request ( {
url : "groups.json?mine=1",
method : "GET",
data : { },
success : function ( group ) {
alert('hi');
alert(group);
$mygroup = "";
for ( $i = 0; $i < group.length; $i++ ) {
$mygroup += '<img src="' + group [ $i ].mugshot_url + '">' + " " + group [ $i ].full_name + "," + "<br>";
}
$ ( "#current-groups" ).html ( $mygroup );
},
error : function ( group ) {
alert ( "No Go" + group.results);
}
} );
I am always getting error.
Thanks in Advance

After removing
data : { },
from my code, it started working
yam.platform.request ( {
url : "groups.json?mine=1",
method : "GET",
data : { },
success : function ( group ) {
alert('hi');
alert(group);
$mygroup = "";
for ( $i = 0; $i < group.length; $i++ ) {
$mygroup += '<img src="' + group [ $i ].mugshot_url + '">' + " " + group [ $i ].full_name + "," + "<br>";
}
$ ( "#current-groups" ).html ( $mygroup );
},
error : function ( group ) {
alert ( "No Go" + group.results);
}
} );

Related

How to make recursive calling of subitems in vuejs2?

In my laravel/blade app when I need to show comments of a product with parent_id I wrote a function with recursive calling of itself, like
public function showCommentItem( $commentsList, $parent_id, $product_id, $deeps, $backend_home_url, $images_dir, $current_template )
{
$ret_html= '';
$ret_html.= '<ul class="p-b-30">';
foreach( $commentsList as $nextComment ) { // run list of comments
if ( (int)$nextComment->parent_product_comment_id == (int)$parent_id ) {
$approved_status_html= '';
$ban_user_html= '';
$rating_html= '';
$status_html= '<span class="'.($nextComment->approved_status=='N'?'text-danger':'').'">'.$viewFuncs->getProductCommentApprovedStatusLabel( $nextComment->approved_status ).'</span>';
$current_status_html= '. <span class="_tree_current_status ">Current Status</span> <b>'. $status_html . '</b>. ';
if ( $nextComment->approved_status == "N" or $nextComment->approved_status == "A" ) { // .text-center
...
}
...
$ret_html.= '<li class="'.($nextComment->subitems_count > 0 ? ' isFolder isExpanded ' : '').' p-b-10" >'.
'<small>'./*$nextComment->user_id .' '.$nextComment->user_active_status .' : '.*/$nextComment->username.$ban_user_html.'</small>'./*'<br>' . */
'<small>'.$current_status_html . $approved_status_html .
'<span class="time pull-right">'.$nextComment->created_at.''.$rating_html.'</span>'.'</small>' . '<br>' ;
...
if ( $nextComment->subitems_count > 0 ) {
$deeps++;
$ret_html.= $this->showCommentItem( $commentsList, $nextComment->id, $product_id, $deeps, $backend_home_url, $images_dir, $current_template);
}
$ret_html.= '</li>';
} // if ( $nextComment->parent_product_comment_id == $parent_id ) {
} // recursiveforeach( $commentsList as $nextComment ) { // run list of comments
$ret_html.= '</ul>';
return $ret_html;
whrere $commentsList - my comments, $parent_id - is 0 at root calling, $product_id - common for all comments
and I got string for all comments with all functionality.
I try to make similar in bootstrap-vue project, like :
<b-list-group>
// I got root items only with getAdCommentsByParentId method
<b-list-group-item v-for="(nextAdComment) in getAdCommentsByParentId(0)" :key="nextAdComment.id" class="m-1 p-0">
<div class="pre-formatted" v-html="nextAdComment.id+' ( '+nextAdComment.parent_ad_comment_id+') : '+concatStr(nextAdComment.text,50)"></div>
</b-list-group-item>
</b-list-group>
...
methods: {
getAdCommentsByParentId: function (parent_ad_comment_id) {
var retArray= []
if(!this.adComments) return []
this.adComments.map((nextAdComment) => {
if (nextAdComment.parent_ad_comment_id == parent_ad_comment_id) {
retArray[retArray.length]= nextAdComment
}
})
return retArray
},
But I do not know how to make recursive calling like I did with blade?
"bootstrap-vue": "^2.3.0",
"vue": "^2.6.11",
Thanks!
I found article
Creating a Recursive Tree Component in Vue.js
from
https://alligator.io/vuejs/recursive-components/
Just what I need !

Undefined offset:0 at HandleExceptions->handleError

I have a page which is used to search the users. If I searched an existing user, the page will redirect to my wanted page. If the user is not existing, a message must be shown. But for me the message is not showing. I know may be this is a simple error, but it's not working for me. I am using Laravel 5.8.
Error is:
Undefined offset: 0
in ClientsController.php (line 344)
at HandleExceptions->handleError.
Here is my controller:
public function getMerchantDetails() {
$user = $_GET['user'];
$mid = $_GET['mid'];
$activity = "User $user has searched this merchant";
//This is for Activity Log Capturing. Added user variable
DB::insert("INSERT INTO activitylog (mid,activity) values ('$mid','$activity')");
//Activity ends here
$mobile = $_GET['mobile'];
$email = $_GET['email'];
$m = '';
if ($mobile != '') {
$m = " AND primary_number = '" . $mobile . "' ";
}
$e = '';
if ($email != '') {
$e = " AND email = '" . $email . "' ";
}
$i = '';
if ($mid != '') {
$i = " AND mid = '" . $mid . "' ";
}
if ($m == '' && $e == '' && $i == '') {
// print_r($m);
// die();
return response()->json(array('data' => ''), 200);
} else {
$res = DB::select(DB::raw("SELECT * FROM clients WHERE 1=1 " . $m . $e . $i . " LIMIT 1"));
if (!$res) {
//$res_config = DB::select( DB::raw("SELECT * FROM configuration WHERE code = 'PERL_SEARCH_MERCHANT'") );
$perl_path = DB::select(DB::raw("SELECT * FROM configuration WHERE code = 'PERL_PATH'"));
$perl_output = exec($perl_path[0]->description . ' -merchant_id ' . $mid . ' -mobile ' . $mobile . ' -email ' . $email);
$r = json_decode($perl_output, true);
if ($r['status'] == 'success') {
if ($r['id'] != '') {
$res = DB::select(DB::raw("SELECT * FROM clients WHERE id = " . $r['id']));
} else {
$res[0]['id'] = '';
}
}
}
return response()->json(array('data' => $res[0]), 200); (line 344)
}
}
My Ajax code:
$.ajax({
"url": '{!! route('clients.fetchMerchantDetails') !!}',
async: true,
type: "GET",
data: {
mobile: mobile,
email: email,
mid: mid,
user:userid
},
success: function (response) {
var data = response.data
if(data.id!=''){
clientEditUrl = clientEditUrl.replace(':id', data.id);
window.location = clientEditUrl;
}else{
$('.searchOutputDiv').html('<h3>No merchant found!</h3>');
}
}
});

How to set key to query result?

I have the following request in Laravel:
$name = Place::where("status", "1", function ($query) use ($request) {
if (($from = $request->get("from"))) {
$query->where('name', 'like', $from . '%');
}
if (($to = $request->get("to"))) {
$query->where('name', 'like', $to . '%');
}
})->orderBy('name', 'desc')->get();
I get result like as:
{
"id": 2,
"name": "Lena"
},
{
"id": 1,
"name": "Baran"
}
How can I set keys for these two result rows? I want to do:
name_one = {
"id": 2,
"name": "Lena"
},
name_two = {
"id": 1,
"name": "Baran"
}
You can try this code
public function getCollectinos()
{
$collection = collect([
['id' => '1', 'product' => 'Chair'],
['id' => '2', 'product' => 'Desk'],
['id' => '3', 'product' => 'Bookcase'],
]);
$grouped = $collection->groupBy(function ($item, $key) {
return 'name_'.$this->number_to_word($item['id']);
});
$array = $grouped->toArray();
dd($array);
}
public function number_to_word( $num = '' )
{
$num = ( string ) ( ( int ) $num );
if( ( int ) ( $num ) && ctype_digit( $num ) )
{
$words = array( );
$num = str_replace( array( ',' , ' ' ) , '' , trim( $num ) );
$list1 = array('','one','two','three','four','five','six','seven',
'eight','nine','ten','eleven','twelve','thirteen','fourteen',
'fifteen','sixteen','seventeen','eighteen','nineteen');
$list2 = array('','ten','twenty','thirty','forty','fifty','sixty',
'seventy','eighty','ninety','hundred');
$list3 = array('','thousand','million','billion','trillion',
'quadrillion','quintillion','sextillion','septillion',
'octillion','nonillion','decillion','undecillion',
'duodecillion','tredecillion','quattuordecillion',
'quindecillion','sexdecillion','septendecillion',
'octodecillion','novemdecillion','vigintillion');
$num_length = strlen( $num );
$levels = ( int ) ( ( $num_length + 2 ) / 3 );
$max_length = $levels * 3;
$num = substr( '00'.$num , -$max_length );
$num_levels = str_split( $num , 3 );
foreach( $num_levels as $num_part )
{
$levels--;
$hundreds = ( int ) ( $num_part / 100 );
$hundreds = ( $hundreds ? ' ' . $list1[$hundreds] . ' Hundred' . ( $hundreds == 1 ? '' : 's' ) . ' ' : '' );
$tens = ( int ) ( $num_part % 100 );
$singles = '';
if( $tens < 20 )
{
$tens = ( $tens ? ' ' . $list1[$tens] . ' ' : '' );
}
else
{
$tens = ( int ) ( $tens / 10 );
$tens = ' ' . $list2[$tens] . ' ';
$singles = ( int ) ( $num_part % 10 );
$singles = ' ' . $list1[$singles] . ' ';
}
$words[] = $hundreds . $tens . $singles . ( ( $levels && ( int ) ( $num_part ) ) ? ' ' . $list3[$levels] . ' ' : '' );
}
$commas = count( $words );
if( $commas > 1 )
{
$commas = $commas - 1;
}
$words = implode( ', ' , $words );
$words = trim(str_replace( ' ,' , ',' , $this->trim_all( $words ) ) , ', ');
if( $commas )
{
$words = $this->str_replace_last( ',' , ' and' , $words );
}
return $words;
}
else if( ! ( ( int ) $num ) )
{
return 'Zero';
}
return '';
}
public function str_replace_last( $search , $replace , $str )
{
if( ( $pos = strrpos( $str , $search ) ) !== false ) {
$search_length = strlen( $search );
$str = substr_replace( $str , $replace , $pos , $search_length );
}
return $str;
}
public function trim_all( $str , $what = NULL , $with = ' ' )
{
if( $what === NULL )
{
// Character Decimal Use
// "\0" 0 Null Character
// "\t" 9 Tab
// "\n" 10 New line
// "\x0B" 11 Vertical Tab
// "\r" 13 New Line in Mac
// " " 32 Space
$what = "\\x00-\\x20"; //all white-spaces and control chars
}
return trim( preg_replace( "/[".$what."]+/" , $with , $str ) , $what );
}
Output :
you can do a keyBy('name'); after the get() function lookup keyBy example below
$collection = collect([
['product_id' => 'prod-100', 'name' => 'desk'],
['product_id' => 'prod-200', 'name' => 'chair'],
]);
$keyed = $collection->keyBy('product_id');
$keyed->all();
/*
[
'prod-100' => ['product_id' => 'prod-100', 'name' => 'Desk'],
'prod-200' => ['product_id' => 'prod-200', 'name' => 'Chair'],
]
*/

BrainTree what do I paste in Braintree.create("YourClientSideEncryptionKey");

I'm new to braintree.
I'm at first steps : https://github.com/braintree/braintree_php_guide/tree/master/1_getting_paid
in the index.php there is a part
var braintree = Braintree.create("YourClientSideEncryptionKey");
It's not clear ; I replace the "YourClientSideEncryptionKey" by what ?
Thanks
Finally I was able to create a first sandbox transaction ;)
Going AJAX instead to using index.php...
My code :
.JS Files (don't forget to include jquery.js...)
function braintreeTest ( cardNumber, CVV, ExpirMonth, ExpirYear , phpVariable_message_DivID ) {
$.ajax ({
type: 'POST',
url: '___url_of_braintree_php_file___',
dataType: 'json',
data:'cardNumber='+encodeURIComponent (cardNumber)+
'&cardCVV='+encodeURIComponent(CVV)+
'&cardExpirationMonth='+encodeURIComponent(ExpirMonth)+
'&cardExpirationYear='+encodeURIComponent(ExpirYear),
cache: false,
success: function(data){
$('#'+phpVariable_message_DivID).html(data.phpVariable_message1);
},
error: function(request, status, error){
console.log ( 'request.responseText --> ' + request.responseText + ' status --> ' + status + ' error --> ' + error );
}
});
}
PHP file
<?php
function clean ( $toClean ){
$toClean = trim ( $toClean ) ;
$toClean = addslashes ( $toClean ) ;
return $toClean;
}
$phpVariable_message1 = '' ;
$cardNumber__from_post = '' ;
$cardCVV__from_post = '' ;
$cardExpirationMonth__from_post = '' ;
$cardExpirationYear__from_post = '' ;
if ( isset($_REQUEST['cardNumber']) ) { $cardNumber__from_post = clean ( $_REQUEST['cardNumber'] ) ; } // 4111111111111111
if ( isset($_REQUEST['cardCVV']) ) { $cardCVV__from_post = clean ( $_REQUEST['cardCVV'] ) ; } // 555
if ( isset($_REQUEST['cardExpirationMonth']) ) { $cardExpirationMonth__from_post = clean ( $_REQUEST['cardExpirationMonth'] ) ; } // 02
if ( isset($_REQUEST['cardExpirationYear']) ) { $cardExpirationYear__from_post = clean ( $_REQUEST['cardExpirationYear'] ) ; } // 17
require_once '__PATH_TO_/braintree_php/lib/Braintree.php';
Braintree_Configuration::environment("sandbox");
Braintree_Configuration::merchantId('use_your_merchant_id');
Braintree_Configuration::publicKey('use_your_public_key');
Braintree_Configuration::privateKey('use_your_private_key');
$result = Braintree_Transaction::sale(array(
"amount" => "11.11",
"creditCard" => array(
"number" => $cardNumber__from_post,
"cvv" => $cardCVV__from_post,
"expirationMonth" => $cardExpirationMonth__from_post,
"expirationYear" => $cardExpirationYear__from_post
),
"options" => array(
"submitForSettlement" => true
)
));
if ($result->success) {
$phpVariable_message1 .= "Success! Transaction ID: " . $result->transaction->id;
} else if ($result->transaction) {
$phpVariable_message1 .= "Error: " . $result->message;
$phpVariable_message1 .= "<br/>";
$phpVariable_message1 .= "Code: " . $result->transaction->processorResponseCode;
} else {
$phpVariable_message1 .= "Validation errors:<br/>";
foreach (($result->errors->deepAll()) as $error) {
$phpVariable_message1 .= "- " . $error->message . "<br/>";
}
}
}
echo json_encode(array("phpVariable_message1" => $phpVariable_message1 ) );
?>

Ajax requests in a loop- refresh div after each request not working in IE8

I have a loop in which I'm making Ajax xmlhttp requests. This occurs within a function triggered by a window.onload event.
The Ajax calls are being made with async=false, because they need to occur in a specific order that relies on each step completing before the next can occur.
With each successive request in the loop, I'm updating a div with the xmlhttp.responseText.
Firefox is refreshing between calls as desired.
IE is not. When the loop begins, the div is populated with the pre-loop content. When the loop finishes, the div is populated with the first refresh that occurs outside of the loop.
Can someone please help?
Two attempted solutions:
1. Adding a random string to the end of the GET query string to ensure a unique url
2. Submitting with the POST method
No luck with either.
Thanks.
Code...
<script type="text/javascript">
function order_process() {
var err;
var queue_id = "<?= implode(':',$plans[$_REQUEST['order_queue_id']]); ?>".split(':'); // Queue ID
var queue_ax = "<?= implode(':',array_keys($plans[$_REQUEST['order_queue_id']])); ?>".split(':'); // Queue Action
i = 0;
for (step in queue_id) {
// The DIV contents that display during each loop iteration
document.getElementById("barber_pole").innerHTML='\
<center>\
<table style="align:left" border="0" cellpacing="1" cellpadding="1">\
<tr><td><B>Processing Order</B><span style="float:right;">Step ' + (i + 1) + '/' + queue_id.length + '</span></td></tr>\
<tr><td style="background-color:#FFFFFF;height:1.5px"></td></tr>\
<tr><td height="20" style="text-align:center">' + queue_ax[i] + '...</td></tr>\
<tr><td height="20"><IMG SRC="../../_include/images/barber_pole.gif" style="vertical-align: middle;"></td></tr>\
</table>\
</center>';
xmlhttp = ajax_request(); // Create request object
xmlhttp.onreadystatechange=function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
1;
}
}
var url = '../../../api/order_process.php?api_login=' + "<?=$api_login?>" + '&api_pass=' + "<?=$api_pass?>" + "&order_id=<?= $_REQUEST['order_id']?>" + '&order_action_id=' + queue_id[step] + '&timeid=' + Math.random();
xmlhttp.open("GET",url,false);
xmlhttp.send();
// If the response includes the string 'failed' exit the loop and render error error message
if (xmlhttp.responseText.split(',')[0] == 'failed') {
err = queue_ax[i] == 'Registering Domain'
? "<h1 class=\"landing-title\">" + fname + ', ' + "<?=$feedback[domain_register][title]?>" + "</h1><DIV class='landing-body'><?=$feedback[domain_register][body]?></DIV>"
: queue_ax[i] == 'Provisioning cPanel Account'
? "<h1 class=\"landing-title\">" + fname + ', ' + "<?=$feedback[cpanel_provision][title]?>" + "</h1><DIV class='landing-body'><?=$feedback[cpanel_provision][body]?></DIV>"
: queue_ax[i] == 'Credit Card Fraud Protection'
? "<h1 class=\"landing-title\">" + fname + ', ' + "<?=$feedback[maxmind_minfraud][title]?>" + "</h1><DIV class='landing-body'><?=$feedback[maxmind_minfraud][body]?>\"" + xmlhttp.responseText + '"</DIV>'
: queue_ax[i] == 'Verifying Payment'
? "<h1 class=\"landing-title\">" + fname + ', ' + "<?=$feedback[verify_payment][title]?>" + "</h1><DIV class='landing-body'><?=$feedback[verify_payment][body]?>\"" + xmlhttp.responseText + '"</DIV>'
: xmlhttp.responseText == 'failed,'
? "<h1 class=\"landing-title\">" + fname + ', ' + "<?=$feedback[gen_err][title]?>" + "</h1><DIV class='landing-body'><?=$feedback[gen_err][body]?></DIV>"
: "<h1 class=\"landing-title\">" + fname + ', ' + "<?=$feedback[gen_err][title]?>" + "</h1><DIV class='landing-body'><?=$feedback[gen_err][body]?>\"" + xmlhttp.responseText + '"</DIV>';
break;
}
i++;
}
if (err) {
document.getElementById("landing-pres").innerHTML = err;
Cufon.replace('.landing-title');
} else {
document.getElementById("barber_pole").innerHTML = "<?= $thank[$_REQUEST['order_queue_id']][1] ?>";
}
}
window.onload=order_process;
</script>
async=false is not recommended [third parameter in xmlhttp.open("GET",url,false);], and we should not write onreadystatechange function if we are using async=false [Also, you are doing nothing in that function]. Please refer http://www.w3schools.com/ajax/ajax_xmlhttprequest_send.asp
Here is the good way that collecting / preparing all HTML once and update your "barber_pole" div like this..
<script type="text/javascript">
function order_process()
{
var err;
var queue_ids = "<?php echo implode(':',$plans[$_REQUEST['order_queue_id']]); ?>"; // Queue IDs separated by ':'
var queue_axns = "<?php echo implode(':',array_keys($plans[$_REQUEST['order_queue_id']])); ?>"; // Queue Actions separated by ':'
var xmlhttp = ajax_request(); // Create request object
var url = '../../../api/order_process.php?api_login=' + "<?=$api_login?>" + '&api_pass=' + "<?=$api_pass?>" + "&order_id=<?= $_REQUEST['order_id']?>" + '&order_action_ids=' + encodeURIComponent(queue_ids) + '&order_actions=' + encodeURIComponent(queue_axns) + '&timeid=' + Math.random();
xmlhttp.onreadystatechange = function ()
{
if (xmlhttp.readyState == 4)
{
document.getElementById("barber_pole").innerHTML = xmlhttp.responseText;;
}
else
{
document.getElementById("barber_pole").innerHTML = "Processing..";
}
}
xmlhttp.open("GET", url, true);
xmlhttp.send();
}
window.onload=order_process;
</script>
in order_process.php file...
<?php
//Checking whether logged in or not blah blah..
$action_ids = $_REQUEST['order_action_ids'];
$order_actions = $_REQUEST['order_actions'];
$actions_ids_array = explode(":", $action_ids);
$order_actions_array = explode(":", $order_actions);
$strHTML = '';
for($cnt=0; $cnt < count($actions_ids_array); $cnt++ )
{
$each_action_id = $actions_ids_array[$cnt];
$each_action = $order_actions[$cnt];
//Process each action collect $fname and $status value and generate HTML
//blah blah..
$strHTML .= "<h1 class=\"landing-title\">" . $fname . $status . "</h1>";
}
echo $strHTML;
exit;

Resources