Hi I am trying to build a Dashboard that show summary of what happens in a Planner Plan, Calendar events and SharePoint files etc. I want to show users' task in different tables. I have managed to authorize and get the user list and get the all tasks from a plan by following the documentation. But the tasks I get returns something like this. I can see the task is assigned to "9d2e533d-6e8e-xxx-8959-846xxxbe192ab" but how do I get/print this? I can get the task title by using getTitle() method. But how do I getthe assignee? Or is there a better way to get tasks based on users?
{
"#odata.etag": "W/\"JzEtVGFzayxxBAxAQxxxEBAWCc=\"",
"planId": "UeRhlCyHxxxxxk3CpgABpFg",
"bucketId": "GWqGxxxxak-YzYxxx0-bm-5xxxxzZ9",
"title": "Arge 2",
"orderHint": "85xxx467xxxx41871P|",
"assigneePriority": "",
"percentComplete": 50,
"startDateTime": null,
"createdDateTime": "2020-06-14T12:54:41.8747394Z",
"dueDateTime": null,
"hasDescription": false,
"previewType": "automatic",
"completedDateTime": null,
"completedBy": null,
"referenceCount": 0,
"checklistItemCount": 0,
"activeChecklistItemCount": 0,
"conversationThreadId": null,
"id": "8BxxxtlHQxxxGPR0xxxgAMfWV",
"createdBy": {
"user": {
"displayName": null,
"id": "75c90cdf-a9fc-4f55-860a-87076b9a31ef"
}
},
"appliedCategories": {},
"assignments": {
"9d2e533d-6e8e-xxx-8959-846xxxbe192ab": {
"#odata.type": "#microsoft.graph.plannerAssignment",
"assignedDateTime": "2020-06-14T13:02:07.0513638Z",
"orderHint": "858609xxxxx8441xxx388P#",
"assignedBy": {
"user": {
"displayName": null,
"id": "75cx0cdf-a9fc-4xxx-860a-87xxxx9a31ef"
}
}
}
}
},
That is the user id of the assignee, you can get information about the user through Get User request. More efficiently, you can get the group members, and match the id of the user to Group membership which includes basic user info. It is possible to have assignees that are not members of the group, so you should use membership when available and fallback to user info otherwise to get the complete data efficiently.
Related
I have a web application where the user shall be able to change MariaDB records via a GUI inside the browser.
In this GUI, the user sees a list of the records visible for him. Whatever he can see, he has permission to delete or change as well.
To change a DB record, he simply has to click the fields he wants to change inside the list and then press the "send" button.
In his HTTP request, the id associated with the record will be transmitted so the backend can identify the respective record inside the DB and apply the changes.
Now, Im rather new to Laravel/Lumen. To fetch the list the user can apply changes to in the first place, I have the following code:
$join = coretable::with($permittedTables)->get();
The $permittedTables is an array of tablenames, so any number or combination of tables might be joined to coretable.
For example, a fetch can look like this:
[{
"Internal_key": "TESTKEY_1",
"extensiontable_itc": {
"description": "EXTENSION_iTC_1"
},
"extensiontable_sysops": {
"description": "EXTENSION_SYSOPS_1"
}
}, {
"Internal_key": "TESTKEY_2",
"extensiontable_itc": {
"description": "EXTENSION_ITC_2"
},
"extensiontable_sysops": {
"description": "EXTENSION_SYSOPS_2"
}
}, {
"Internal_key": "TESTKEY_3",
"extensiontable_itc": {
"description": "EXTENSION_ITC_3"
},
"extensiontable_sysops": {
"description": "EXTENSION_SYSOPS_3"
}
}, {
"Internal_key": "TESTKEY_4",
"extensiontable_itc": {
"description": "EXTENSION_ITC_4"
},
"extensiontable_sysops": {
"description": "EXTENSION_SYSOPS_4"
}
}, {
"Internal_key": "TESTKEY_5",
"extensiontable_itc": {
"description": "EXTENSION_ITC_5"
},
"extensiontable_sysops": {
"description": "EXTENSION_SYSOPS_5"
}
}]
Now, I wondered if I could just reuse the code I've created to fetch the data for setting the data.
So I used the above shown $join and tried to determine the datarecords I want to change.
The attempt looks like this:
$join = $join->find("TESTKEY_1");
The find however doesnt return anything.
Considering the structure of the results I'm querying here, is this approach even feasible? Or should I build some new code, fetching the results in a different structure, better suited to have changes applied to it?
Still, is there a way to search these fetchresults for a subset of data and then apply changes to this subset (and persist those changes to the DB, of course)?
$join = $join->find("TESTKEY_1");
find method works only for ids.
e.g. $join = $join->find(1); //1 is id (primary_key) in here.
if you want to find the record by TESTKEY_1
$join = $join->where("Internal_key","TESTKEY_1")->get();
// will return array of all records having Internal_key TESTKEY_1
if you want only the first record to be fetched
$join = $join->where("Internal_key","TESTKEY_1")->first();
// will return only first having Internal_key TESTKEY_1 as an array.
I am just confused on how this thing is working .
I have a M-M relationship between by Users and Roles. If I retrieve my user like the following :-
$user = Auth::User();//->with('roles')->get();
$roleName = $user->roles[0]->name;
return $this->sendResponse('User retrieved successfully',$user);
I get the following response :
{
"success": true,
"message": "User retrieved successfully",
"data": {
"id": 2,
"name": "dummy",
"email": "dummy#dummy.com",
"created_at": "2017-05-06 09:49:50",
"updated_at": "2017-05-06 09:49:50",
"tenant_id": 2,
"roles": [
{
"id": 1,
"created_at": "2017-05-06 06:26:55",
"updated_at": "2017-05-06 06:26:55",
"name": "Admin",
"permissions": null,
"pivot": {
"user_id": 2,
"role_id": 1
}
}
]
}
}
But, if I retrieve my user as :-
$user = Auth::User();//->with('roles')->get();
return $this->sendResponse('User retrieved successfully',$user);
I get the following resut :-
{
"success": true,
"message": "User retrieved successfully",
"data": {
"id": 2,
"name": "Ali",
"email": "ali#and-or.com",
"created_at": "2017-05-06 09:49:50",
"updated_at": "2017-05-06 09:49:50",
"tenant_id": 2
}
}
Why is this happening ? I expected the "first" posted result to the latter query.
Secondly, I did not modify the $user after the query in the first "method" how did it get its Roles attachment ?
I am sure there is an explanation, but I couldn't put my finger on it.
When retrieving a model, the User in this instance, relationships are not automatically also retrieved (Since on the database side this would require a second query while you might not even need the roles in a certain situation).
In your first example, by accessing the roles through $roleName = $user->roles[0]->name;, Laravel does the roles() query automatically, and also adds the roles object to the User (So it can be accessed again at a later point without needing to redo the query). This explains why the roles are 'magically' attached to your User model in the first example.
In your second example this query is not done automatically, so you do not get the roles relation in your response.
If you want to have access to the Users roles, then you could use the with() method like in your comment to eager load the relationship, but keep in mind that this implies doing the second query in order to get this data from the database.
Another option, if you always want the User model to have its Roles attached, would be to add roles to the $appends array of the model:
protected $appends = ['roles'];
This tells Laravel that the roles attribute is one which you always want available on your model, and it then does what is necessary to make this happen (In this case, query the relationship).
I am currently building a website for my guild (on a video game).
The video game (Guild wars 2) provide us a feed of everything being done inside the guild in a json file (user joining, withdraw of money, deposit of items, kick, etc...).
Since I have this feed, auto-updated, I would like to setup a lottery, working on the following :
- guild member (user) buy a ticket => deposit golds in our bank (displayed as deposit)
- display this information on the website => user "x" has bought a ticket at H:M:DD:MM:Y (for example)
- at the end of the month, script to random a winner from this list of users (this random must include only tickets bought between date A & B)
I have managed to write a little code, and it is working, only to display a list of users and their actions :
<?php
$apikey = '(My API key)';
$guildkey = '(My guild key)';
$jsontest =file_get_contents ('https://api.guildwars2.com/v2/guild/'.$guildkey.'/log?access_token='. $apikey);
$json = json_decode($jsontest,true);
foreach($json as $member)
{
if ($member['coins'] > 1)
print "Guild member "."".$member['user'].""." has bought a ticket for ".$member['coins']." golds"." ";
}
?>
Here a little example of how the guild wars 2 api output is :
{
"type": "upgrade",
"item_id": 77729,
"count": 1,
"action": "completed",
"id": 896815,
"time": "2017-02-23T14:26:29.000Z",
"user": "Lehi.5091",
"upgrade_id": 668
},
{
"id": 896814,
"time": "2017-02-23T14:26:29.000Z",
"type": "upgrade",
"upgrade_id": 668,
"action": "queued"
},
{
"type": "upgrade",
"item_id": 77729,
"count": 1,
"action": "completed",
"id": 896810,
"time": "2017-02-23T14:26:28.000Z",
"user": "Lehi.5091",
"upgrade_id": 668
As intended, it does display what I want, here the working code
If you have tips or anything about how to this, I'll gladly take them.
Thanks for your help,
When i create an event with the graph api i need to specify the venue and i would like also to show the map.
I do
$fb_event['name'] = "THis is to test latitude";
$fb_event['description'] = "And longitude!!!!";
$fb_event['start_time'] = date( "c", Ai1ec_Facebook_Event::get_facebook_start_time($event->start));
$fb_event['location'] = "Where you want";
$fb_event['street'] = "Via andrea del sarto 9";
$fb_event['city'] = "Milan";
$fb_event['latitude'] = 45.444975793404;
$fb_event['longitude'] = 9.2119209654715;
$facebook = $this->facebook_instance_factory();
try {
$result = $facebook->api( "/me/events", "POST", $fb_event );
} catch (FacebookApiException $e) {
fb($e);
}
This produce this event which show the correct street and city, but no map. If i edit the event and save, the map "Magically" appears using the street and city correctly.
In any case latitude and longitude are ignored.
What am i doing wrong?
If you compare your two test events in the Graph API explorer you'll see that Event ID 239298922846828 does not have its latitude and longitude populated, while 245655182207213 does. I'm assuming 245655182207213 is an event you've edited.
Looking at your code, you seem to be doing everything as described in the documentation. However, I've found that what is described does not always work.
What I've been seeing is that events populated from within Facebook that occur at a known venue are no longer allowing you to specify an address. Instead all they save is a venue id within Facebook which you can then drill into to get the address, etc.
Take a look at one of my events. For this event, there is no way to edit the details of this location from within Facebook, nor does the event venue details get returned with an API call. I'm using the API to pull the event details to an external website. This change caused me days of frustration.
I started seeing this behavior in late April. I haven't found any official documentation announcing this change.
When some documentation appears, what I expect the new event venue workflow will be is something like:
Query the area where your event will take place to see if a venue exists already.
If yes, get save its id.
If not, create a new community page for your venue and save its id.
Use this ID to populate the event venue.
In the end this is a known facebook bug
https://developers.facebook.com/bugs/173095916131752
Two different formats when create using the same parameters.
When create event through gql
{
"id": "xxxxxxxxxxxxxx",
"owner": {
"name": "xxxxxxxxxx",
"id": "xxxxxxxxx"
},
"name": "W1112",
"start_time": "2013-10-22",
"is_date_only": true,
"location": "Tulsa, OK, United States",
"venue": {
"latitude": 36.131388888889,
"longitude": -95.937222222222,
"street": "",
"zip": "",
"id": "109436565740998"
},
"privacy": "SECRET",
"updated_time": "2013-09-19T12:23:26+0000"
}
When create event through fb
{
"id": "xxxxxxxxxxxxxx",
"owner": {
"name": "xxxxxx",
"id": "xxxxxxxx"
},
"name": "1234",
"start_time": "2013-10-09T21:26:00+1100",
"end_time": "2013-10-25T00:26:00+1100",
"timezone": "Australia/Sydney",
"is_date_only": false,
"location": "Maroubra Junction",
"venue": {
"latitude": -33.940804216453,
"longitude": 151.23876752992,
"city": "Maroubra",
"state": "NSW",
"country": "Australia",
"id": "153993547968514",
"street": "832 anzac Parade ",
"zip": "2035"
},
"privacy": "SECRET",
"updated_time": "2013-09-19T10:50:14+0000"
}
I've been recently working with facebook graph api , when I'm pulling user's recents status messages using https://graph.facebook.com/me/statuses?access_token=... all I get is a long list which contains details about the status content, and I want to pull the names of people who liked the status.
The current solution I've been thinking about is using preg match,
I'd like to know if you guys have any other suggestions,
Thanks in advance
I'm not sure what path you're using, but you can fetch the list of users who like a particular status update by requesting the likes connection on an update.
For example, requesting https://graph.facebook.com/10150710880081168/likes yields something like the following for me:
{
"data": [
{
"id": "276700623",
"name": "Vikki Carter"
},
{
"id": "1514365200",
"name": "Darren Bean"
},
{
"id": "539760281",
"name": "Ian Sidaway"
}
],
"paging": {
"next": "https://graph.facebook.com/10150710880081168/likes?format=json&limit=25&offset=25&__after_id=539760281"
}
}
You'll need the ID of the status update, but also the user_status permission from the logged-in user.
EDIT: Iterating over the returned data and assigned users into an array:
<?php
$result = $facebook->api('[status_id]/likes');
$names = array();
foreach ($result['data'] as $user) {
$names[] = $user['name'];
}
You should now have an array of names of users who liked the status in question.