Why is Display Name is not Showing in Calendar Event Attendees? - google-calendar-api

I'm successfully retrieving Calendar Event Attendees using the following code gist:
require_once __DIR__ . '/vendor/autoload.php';
putenv("GOOGLE_APPLICATION_CREDENTIALS=" . __DIR__ . '/mt-service-account.json');
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$client->setApplicationName("APP NAME");
$client->setSubject("<APPROPRIATE_USER_EMAIL>");
$client->setScopes([
'https://www.googleapis.com/auth/calendar'
]);
$calendarService = new Google_Service_Calendar($client);
$optParams = array(
'singleEvents' => true,
'orderBy' => 'startTime'
);
$events = $calendarService->events->listEvents('<APPROPRIATE_CALENDAR_ID>', $optParams);
foreach ($events->getItems() as $event) {
print_r($event->getAttendees());
}
However, as can be seen in the response, no Display Name is returned.
Array
(
[0] => Google_Service_Calendar_EventAttendee Object
(
[additionalGuests] =>
[comment] =>
[displayName] =>
[email] => johnsmith#domain.com
[id] =>
[optional] =>
[organizer] =>
[resource] =>
[responseStatus] => needsAction
[self] =>
[internal_gapi_mappings:protected] => Array
(
)
[modelData:protected] => Array
(
)
[processed:protected] => Array
(
)
)
)
The attendee in question is a Contact of the event creator and the Contact's name and email appear in the type assist field when creating an event.
UPDATE NB Events are not created via API. They're created via Google Calendar (i.e. in browser). The attendees are added by typing the attendee's name in the Add Attendee field (Google type-assist found the Contact). The aim is to retrieve programmatically (i.e. with API) event details created by our G Suite Calendar users

I cant see how you are creating the event in question but my guess is that when the event was created and the attendee added their display name was not inserted as an optional parameter.
Events.insert
attendees[].displayName string The attendee's name, if available. Optional. writable
When events are creted via the Google Calendar web view you just add a users Email address. In the event that said user is a Gmail account then Google can guess the display name. In the event it is not a Gmail account then google has no way of knowing what the users name is there for you end up with a display name of null.
attendees": [
{
"email": "lme#gmail.com",
"displayName": "Linda Lawton",
"organizer": true,
"self": true,
"responseStatus": "accepted"
},
{
"email": "ll#meAtWork.com",
"responseStatus": "needsAction"
}

Related

WordPress Custom Email Trigger

I'm using Crocoblocks/JetReviews to add reviews to my site (on a custom post type).
I can see there is a setting to require admin approval for it to be published, but I want to trigger an email to one of the admins when a review is submitted, and I don't see any settings for that so I'll have to do it myself.
I think I can handle the function to send the email, but can't sort out what to hook into or trigger it against?
Using something like this:
if ( function_exists( 'notification' ) ) :
notification( [
'title' => 'Admin Notification for Review Approval', // For internal reference.
'trigger' => 'trigger_slug', // Trigger slug (can be a Triggerable object).
'carriers' => [ // An array with format: carrier_slug => data array
'email' => [
'activated' => true, // Must be true.
'enabled' => true, // Must be true.
'subject' => 'A New Review Needs Approval',
'body' => 'There is a new review awaiting your approval.',
'recipients' => [
[
'type' => 'administrator',
'recipient' => 'admin#adminemail.com',
],
],
],
],
'enabled' => true, // Must be true.
] );
endif;
But right now that's not connected to any action...and that's where I'm lost.
Any thoughts of where to look? I couldn't figure it out from their docs so hoping someone here might have an idea of where to start at least.
Thanks!
Chad

Update User Meta with spaces using REST API - WordPress

I'm trying to update the user meta with spaces registered on my website. I am using register_meta hook to register user meta. And for updating users using WordPress REST API I use wp_remote_post but the problem is when I tried to update a user meta with spaces it will add as array in response then it will add as new user meta.
For example the value of user meta is - community test
Sample Response:
[meta] => Array
(
[agent_community] => Array
(
[0] => community
[1] => test
)
)
Sample Code for registering user meta.
register_meta('user', 'agent_community', array(
"type" => "string",
"show_in_rest" => true
));
Update using wp_remote_post
$update_data = array('email'=> 'test#mail.com', 'meta[agent_community]' => 'community test');
$args = array(
'headers' => array(
'Authorization' => 'Basic ' . base64_encode( 'username:password' ),
),
'body' => array_filter($update_data));
$update_url = 'https://test-url.com/wp-json/wp/v2/users/17';
$response = wp_remote_post( $update_url, $args);
Database:
Is there a way that can merge the array on user meta?
implode() might help you. And you can change spaces with HTML entities. Or use function like urledncode() / urlendecode() or something like this.

Return Symfony Form submitted data as string, not array

I use Symfony 2.7.
Is it possible to get submitted data as string, not as array?
I have a custom form type for searching through records and I want it to have specific output. I want to use GET method on the form, so submitted data could be displayed and used in the querystring right away, without additional redirect:
Form is named search and has fields like
- firstName (text)
- lastName (text)
...
And if submit the form, I want the result NOT to be
search => array(
firstName => 'John',
lastName => 'Doe',
)
But I need it to look like
search => 'firstName:John lastName:Doe'
I tried to use data transformers for this, but no luck so far. Is it possible and how?
form build I am using right now:
$builder
->add('firstname')
->add('lastname')
->add('submit', 'submit')
;
$builder->addModelTransformer(new CallbackTransformer(
function($origData){
return $origData; //no need to set form fields for me
},
function($submitData){
$q = QueryResolver::buildQuery($submitData);
return $q;
}
));
The 'q' variable in second callback then really is
'firstname:john lastname:doe'
but the Request 'search' value is still an array:
'search' =>
'firstname' => 'john'
'lastname' => 'doe'
...
'submit' => ''
'_token' => 'S9k9ZBPaUVz13nNGXn8UoRarxa37IHNWU_AJZGt00H8'

On form submit check user logged in or not drupal 7

I need your help.
I have drupal 7 cck form which is viewable for anonymous user but when anonymous user fill the form and click on submit i want to show user login form and without page refresh after login cck form will automatically submit and show thank you message.
I searched a lot for this but i did not get any solution.
Please help me i don't understand how to do this.
You could write a custom module which uses the form_alter hook. Then for your CCK form, you can check to see if the user is logged in or not and if not, add a username/password fields to the form for the user to fill out. then add a custom validation function to the form, so that when the form is submitted your validation function attempts to programatically login the user. If login fails then display a form error, else set the global user to the logged in user. so by the time the form hits its submit function the user should be logged in.
So something like this for your custom module:
<?php
function mymodule_form_alter(&$form,&$form_state,$form_id){
global $user;
//only for the form we are looking for, and if the user is anonymous
if (($form_id == 'my_form_id') && ($user->uid==0)){
$form['login'] = array(
'#type' => 'fieldset',
'#title' => 'Login',
);
$form['login']['username'] = array(
'#type' => 'textfield',
'#title' => 'Username',
'#required' => true,
);
$form['login']['password'] = array(
'#type' => 'password',
'#title' => 'Password',
'#required' => true,
);
$form['#validate'][] = 'mymodule_my_form_validate';
}
}
function mymodule_my_form_validate(&$form,&$form_state){
global $user;
//stop from re-login if there were other validation errors
if ($user->uid == 0){
$username = $form_state['values']['username'];
$password = $form_state['values']['password'];
//authenticate the user (attempt to login)
if ($uid = user_authenticate($username,$password)){
$user = user_load($uid);
//finalize login
user_login_finalize(array('name'=>$username,'pass'=>$password));
}else{
form_set_error('username','Invalid username or password');
}
}
}

Drupal Notifications module - how to obtain a subscription id (SID)?

I want to show a subscribe/unsubscribe link on a forum topic list page, along with each of the topics in the list. I have all the info for the subscribe link in the $topic variable in mytheme_preprocess_forum_topic_list():
foreach ($variables['topics'] as $id => $topic) {
Assuming that I want to call notifications_get_link() to get the unsubscribe link, how can I obtain the subscription id (SID) for any existing subscription for the topic node?
I suppose I ought to call notifications_user_get_subscriptions(), but the documentation is a bit thin. An example would be great.
My solution finds exactly one subscription for the current node if one exists and composes either a susbcribe or unsubscribe link that is made available to the template:
// find subscription
$subs = notifications_user_get_subscriptions(
$user->uid,
'node',
$topic->nid,
$topic,
FALSE);
// compose link
$destination = "?destination=forum/idea-exchange";
if ($subs) {
foreach ($subs as $key => $sub) {
$link = notifications_get_link('unsubscribe', array(
'sid' => $sub->sid,
'confirm' => FALSE));
$variables['topics'][$id]->subscribe_link =
'<a class="unsubscribe" href="/'.$link['href'].
$destination.'">'.t('Stop tracking this topic').'</a>';
break;
}
}
else {
$link = notifications_get_link(
'subscribe',
array('uid' => $user->uid,
'type' => 'thread',
'fields' => array('nid' => $topic->nid),
'confirm' => FALSE));
$variables['topics'][$id]->subscribe_link =
'<a class="subscribe" href="/'.
$link['href'].$destination.'">'.t('Track this topic').'</a>';
}
I ended up using a CCK Computed Field for this so that I can include it in a View. See this for more context.

Resources