Bundle for notifications in Symfony2 - symfony

I want to include notifications, e.g. for forum threads. A user shall retrieve notifications if there are any new posts to a forum thread. Another example would be the notifications on Facebook, e.g. where you're notified of new comments on your posts or pictures.
Is there a notification bundle for Symfony2 that you can recommend for implementing such a function?
I came up with the Sonata NotificationBundle but I am unsure if this is what I really need. When I look at the usage examples it looks as if this would provide a email notification function
// retrieve the notification backend
$backend = $container->get('sonata.notification.backend');
// create and publish a message
$backend->createAndPublish('mailer', array(
'from' => array(
'email' => 'no-reply#sonata-project.org',
'name' => 'No Reply'
),
'to' => array(
'myuser#example.org' => 'My User',
'myuser1#example.org' => 'My User 1',
),
'message' => array(
'html' => '<b>hello</b>',
'text' => 'hello'
),
'subject' => 'Contact form',
));
or a logging function
$this->get('sonata.notification.backend')->createAndPublish('logger', array(
'level' => 'debug',
'message' => 'Hello world!'
));
Can you confirm/recommend the usage of that bundle? Or can you recommend any other?

Good news:
NotificationBundle from GeniusesOfSymfony
https://github.com/GeniusesOfSymfony/NotificationBundle
Proper documentation will probably be published soon.
(on-going discussion here: https://github.com/GeniusesOfSymfony/WebSocketBundle/issues/4#issuecomment-81829513)
I've already tested a similar bundle created by them (WebSocketBundle) which also provides real-time-interaction and it works really great. The documentation is also very good.
I recommend that you "star" the project on github. You can also create an issue to ask about the current status of the project.

I'm searching for the same library now, and also found https://github.com/namshi/notificator
Didn't use it yet, but it has 130 stars today, so probably will try it.

You can achieve this with sonata notification bundle.
You will need to create custom consumer class as described here
https://sonata-project.org/bundles/notification/3-x/doc/reference/usage.html#custom-consumer

You can try this Bundle: NotificationsBundle
It's a simple implementation for Pusher that provides a real time data proadcast.

Related

How to use file upload option in WooCommerce payment gateway admin options?

I am developing a plugin to integrate a payment gateway in WooCommerce. I have done one before.
But in this one, I need to upload a key file in gateway settings and that is used to hash the data before making payment request to related portal.
I have following code which allows to choose file, but I doubt this is working in the back end.
'sandbox_pvt_key' => array(
'title' => __( 'Test Private Key', 'woocommerce-custom-gateway' ),
'type' => 'file',
'desc_tip' => true,
'description' => __( 'Please upload the test private key file; this is needed in order to test payment.', 'woocommerce-custom-gateway' ),
'default' => '',
),
The output looks like the following:
Can anybody lemme know if this is supported option in the gateway settings? If not, can anybody guide me on how I can customize it via some hook/filters or any other way.
This can be achieved in the process_admin_options()
public function process_admin_options() {
$this->upload_key_files();
$saved = parent::process_admin_options();
return $saved;
}
private function upload_key_files() {
//handle uploads here
}

add to Google calendar option cut some description content off

We have coded a PHP page building the content of a calendar event. It is a mix of static and dynamic content for different parts of the email including the Description. When I receive the email in Gmail, the Add Calendar is displayed in the email header. An .ICS file is also attached. If I click on Add to calendar, the content of the description is incomplete, the length of content is OK, the problem is not coming from that point. When I open the attached ICS file in Outlook or Hotmail, the content is ok. If I'm adding the event into Google calendar importing the ICS, the content is ok too. But this method is too complicated for my end users.
Any suggestion? Is someone has already met this issue?
Regards
A solution for your issue might be to use the Google Calendar API so you can create calendar events and afterwards add them to the users' calendars.
You should follow the steps from the PHP Quickstart and here a couple of code snippets that create a calendar and then an event with Google Calendar API:
Create a calendar
$calendar = new Google_Service_Calendar_Calendar();
$calendar->setSummary('your_calendar_summary');
$calendar->setTimeZone('your_time_zone');
$createdCalendar = $service->calendars->insert($calendar);
Create an event (you can customize the parameters to your liking)
$event = new Google_Service_Calendar_Event(array(
'summary' => 'your_event_summary',
'location' => 'your_event_location',
'description' => 'your_event_description',
'start' => array(
'dateTime' => 'your_start_date',
'timeZone' => 'your_time_zone',
),
'end' => array(
'dateTime' => 'your_date_time',
'timeZone' => 'your_time_zone',
),
'recurrence' => array(
'RRULE:FREQ=DAILY;COUNT=2'
),
'attendees' => array(
array('email' => 'atendee1#example.com'),
array('email' => 'atendee2#example.com'),
),
'reminders' => array(
'useDefault' => FALSE,
'overrides' => array(
array('method' => 'email', 'minutes' => 24 * 60),
array('method' => 'popup', 'minutes' => 10),
),
),
));
$calendarId = 'primary';
$event = $service->events->insert($calendarId, $event);
printf('Event created: %s\n', $event->htmlLink);
If you want to integrate the Google Calendar service with Gmail you can check these links that might help you:
Email Markup;
Gmail API Reference;
Furthermore, you can read more about the Calendar API here:
Google Calendar PHP Quickstart;
Google Calendar Add Events.

Woocommerce REST API Update Product Categories

I'm using Wordpress 4.9.5 with Woocommerce 3.3.5. I am using the WooCommerce REST API PHP Client Library to update products on the website when they are changed in a separate product management system. That library is using v2 of the REST API.
Using the following code I am successfully updating the basic product data (title, description, sku, price etc) but I can't get the categories to update from Uncategorized. The categories are also not set when using similar code to create a product if it doesn't already exist on the site.
$client = new WC_API_Client( $domain, $consumerKey, $consumerSecret, $options );
$client->products->update( $id, array(
'sku' => $product->sku,
'title' => $product->title,
'type' => $product->type,
'status' => $product->status,
'regular_price' => $product->regular_price,
'description' => $product->description,
'categories' => array(
array(
'id' => 343
),
array(
'id' => 347
)
)
));
As I say, the other fields update as expected. I have confirmed that categories with IDs 343 and 347 definitely exist so I assume I must have a problem with the syntax. As the other fields update the authentication is definitely working.
I have read the official Woocommerce API documentation and based my code on this tutorial. Based on both of those, I'm not sure what I have done wrong.
Thanks for any help or advice.
I resolved this in the end. It was on oversight on my part.
The client library I was using was connecting to what the Woocommerce documentation calls the 'Legacy v2' version rather than the 'v2' version of the API. Categories, image alt tags, meta data etc are not supported in the legacy versions.
I switched from the using library to connecting directly to the 'v2' version using https://sitename/wp-json/wc/v2/endpoint and all is now well.

Facebook Posting using FB API phpSDK

i created my app on fb with permissions ready to publish on users behalf, the thing is, a regular post has Like and Comment links, like buttons on bottom of the post, i want to add my custom link : VOTE NOW, its a poll post
how can i do that?
someone gave an answer but for js sdk not php, n i cant find it on facebook dev documentation
some gave a close enough solution, but ddnt seem to work on php with modifications
FB.ui({
method: "feed",
link: "LINK_URL",
...
actions: [
{ name: "Read Now", link: "URL TO THE READ NOW " }
]
}, function(response) { console.log(response); });
It seems it's working with /me/feed but with my custom /me/xxxxxx:submitted_a_poll/ its not working
When you make a call with the PHP SDK, you also pass a similar set of parameters:
$attachment = array(
'link' => 'http://your-cool-site.com',
'description' => 'This is the description',
...
'actions' => array(
array(
'name' => 'Vote Now!',
'link' => 'http://your-cool-site.com/vote.php'
)
)
);
$result = $facebook->api('/me/feed/', 'post', $attachment);
All you really have to do is add the relevant action settings to your parameters.

How to add user-fields programmatically in Drupal 7

I'm trying to create a .install for a module that I'm migrating from Drupal 6. It requires two 'profile fields', which, in drupal 6, it checked for and created automatically.
To upgrade it to drupal 7 I'm trying to do this with fields! Easy enough right?
So far I have
if(!field_info_field('user_fullname')) {
$field = array(
'field_name' => 'user_fullname',
'type' => 'text',
'settings' => array(
'required' => TRUE,
),
);
field_create_field($field);
$instance = array(
'field_name' => 'user_fullname',
'entity_type' => 'user',
'label' => 'The user\'s full name',
'bundle' => 'additional_info',
'required' => true,
'widget' => array(
'type'=>'options_select',
)
);
field_create_instance($instance);
}
Which, sure enough, creates the field, but it's not visible in the user's profile?
Do I need something additional for that? If so, What?
Many Thanks.
SOLVED: It was due to the bundle (not entirely sure what a bundle is really), I changed the bundle to 'user' and it appeared!
bundle is pretty much the same as content type. But since in D7 users are entities too, but they are not content, using the term 'content type' didn't make sense. Reference: Barry Jaspan's DrupalCon Paris 2009 Session: Intro to the Field API for Module Developers.
Intro to the Field API for Module Developers
It was due to the bundle (not entirely sure what a bundle is really), I changed the bundle to 'user' and it appeared!
As I know in D7 the bundles are something like a model for an entity and it can have fields. The default drupal bundles are node, user and taxonomy but the new API provides the developer to create custom bundles too. Every field needs to belong to a bundle.
A bundle in Drupal is a subset of the entity. In this case the entity type is User and there is only one type of User so the bundle is User.
In Taxonomy: the Taxonomy is the Entity and the Vocabularies are the bundles.
In Nodes: Nodes are the Entity and Content Types are the bundles.
No field can be attached to an entity, properties are attached to the entity (published, sticky, etc). Fields are attached to the Bundles.
I don't have enough rep to comment, so here is my answer for those you find this via google. As I did.

Resources