mgtwitterengine get friends/ids and followers/ids - mgtwitterengine

how to get users who not following me back in twitter by useing mgtwitterengine ?
how to get followers/ids and friends/ids

For Friends ID's Use : https://api.twitter.com/1/friends/ids.json?cursor=-1&screen_name=ImpressolTest&include_entities=true
For Follower ID's use : https://api.twitter.com/1/followers.json?cursor=-1&screen_name=ImpressolTest&include_entities=true
After getting this values in array just check the friends array with followers array, you can get the users how are not following you back

Related

Check whether any values in array match any values in json column

I have a problem of checking whether any values in an array match any values in json column which contains an array with a name.
suppose i have an array [25,36,45,52] and json column is {"values": [25,24,15]}.
I want to check whether any values in array match any of values in json column in xampp mysql. please provide a better solution of doing this. this image show table structure of my database
i have 4 tables.
user
profile
profile
jobs
user table (id,userid)
jobs table (id,user_id,skill_id)
skill table (id,job_id,)
profile table (id,user_id)
now i want to search all jobs that match some or at least one skills.
i have tried with this but this is giving all jobs with out skills filtered.
$jobs = Job::with(['user','profile'])->with(['skills' => function($query){
$query->whereJsonContains('skills->skills',[35]);
}])->where('jobs.is_completed',0);
please help me.
you can use where Clause easily for example you would like to get rows that match skills 35,54:
$users = DB::table('table')
-> whereJsonContains('skills->skills', [35,54])
->get();
for more details about how to querying json column check official docs :
https://laravel.com/docs/5.8/queries#json-where-clauses

Get array of friend names with friend id's from MongoDB

I'm making MEAN app for the first time. I managed to insert users into MongoDB. Each user looks like:
{
"name":"My Name",
"country":"Italy",
"friends":"5922c66b4e708e27a02b7937"
}
My first question is, how to manualy insert more than one friend (how to separate them via Postman)?
Then I have html page to show those informations about user, so I display his friends that way:
<td>{{user.userFriends}}</td>
When I will have more than one firend in database, how to display number of friends instead of their IDs?
Thanks for help!
EDIT: Solved the first part with
{
"friends":["5922c66b4e708e27a02b7937","5922c66b4e708e27a02b7938"]
}
To get Mongo to calculate the number of friends a user has, you can use the $size operator on the friends array. You need to use the aggregation pipeline to do this though. Otherwise, you can just calculate the length of the array yourself. For more details on the $size operator and the aggregation pipeline, see here: https://docs.mongodb.com/manual/reference/operator/aggregation/size/

Group and sort results by max and count in joined table using QueryBuilder

I'm making an app for selling books but I'm struggling with this part of it.
When a user wants to buy a book he can send a message to the book's seller. I have a table called conversations and another table called messages, which holds the messages for a conversation.
I have a page where a user can see a list of conversations he's involved. Conversations with the latest messages should be shown first. I solved this already but I also want to show the number of unread messages next to each conversation (messages have a "read" boolean field). I haven't been able to add the count as part of my original query; I know I could make a query for each item in the conversations collection but that would be inefficient as hell.
This is my query so far with the QueryBuilder:
$conversations = DB::table('conversations')
->select([
'books.title as bookTitle', 'conversations.id',
DB::raw('max(messages.created_at) as lastMessage'),
// DB::raw('(select count(id) from messages')
])
->where('conversations.from_user', $this->user->id)
->orWhere('conversations.to_user', $this->user->id)
->join('books', 'conversations.book_id', '=', 'books.id')
->join('messages', 'conversations.id', '=', 'messages.conversation_id')
->groupBy('messages.conversation_id')
->orderBy('lastMessage', 'DESC')
->get();
If i add the part commented out to attempt to get a field with the number of unread messages for that conversation I get a SQL syntax error. I also been thinking if maybe is not possible to add the count field since it might be exclusive to my original query: I sort the conversations taking into account all messages (read or unread) and pick the latest message for each conversation; the count field I want to add should only count unread messages.
Any ideas? Hope I explained myself.
Thanks.
It seems that instead of:
DB::raw('(select count(id) from messages')
you should simply use:
DB::raw('(select count(id) from messages) as messageCount')
You were missing here )

Restkit: Post an array of id's instead of the complete objects

I have a case where I need to post and array of numbers to the server side. E.g:
I have an order that have a list of products with one to many relation ships.
The question is how to post only array of id's for current order:
Now I have such result:
{"orders":[{"id":0,"Products":[{"productId":6},{"productId":7},{"productId":5},{"productId":3}]},{"id":1,.....]}
But I want to make it
{"orders":[{"id":0,"Products":[6,7,5,3]},{"id":1,.....]}
Any ideas ?
Update 1
I think I have found a solution
I have add method that fetch id's of my order products it's look like this
-(NSArray *)productsIds {
return [self.products.array valueForKeyPath:ProductAttributes.productId];
}
and add such a thing to my mapping code part.
[orderSerializationMapping addAttributeMappingsFromDictionary:#{#"productsIds" : #"Products"}];
And now result is
{"orders":[{"id":5,"Products":[17,13,16,11,12,19]},......]
You don't need add a method to fetch the id's. Setup your mapping like this:
[orderSerializationMapping addAttributeMappingsFromDictionary:#{#"products.productID": #"Products"}];

JSONpath fields with same name

I'm trying to get the user id's from twitter response (asking for several users)
https://dev.twitter.com/docs/api/1/get/users/lookup
But if i try
$.[*].id OR $..id
all fields with id (even nested fields) are retrieved.
How can i get the "id" field placed at first level?
I believe you would only get the first-level id's with the following query $[*].id. I believe this is what you were asking for; let me know if I misunderstood you.