How to cleanup CustomNotification sent by Page reference - custom-notification

I have developed a custom notification in Apex using a page reference to an Aura component, and it works fine (user clicks on notifications under the Bell icon top right and get forwarded to the aura component). But I cannot find a way how to cleanup old notifications, is there a way, please? The system doesn't cleanup automatically, it probably must be done programmatically.
Thanks for any help
Karel
My apex code:
Messaging.CustomNotification notification = new Messaging.CustomNotification();
notification.setTitle('...');
notification.setBody('...');
notification.setSenderId(UserInfo.getUserId());
notification.setNotificationTypeId([SELECT Id FROM CustomNotificationType WHERE DeveloperName ... LIMIT 1].Id);
User user = [SELECT Id FROM User WHERE ... LIMIT 1];
Map<String, Object> pageRef = new Map<String, Object>{
'type' => 'standard__component',
'attributes' => new Map<String, Object>{
'componentName' => 'c__...'
},
'state' => new Map<String, Object>{
'c__jobId' => ...,
'c__userId' => ...
}
notification.setTargetPageRef(JSON.serialize(pageRef));
notification.send(new Set<String>{
user.Id
});
then the Aura component: implemets="flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,lightning:isUrlAddressable">

Related

Unable to get Response Parameters in Notification and Success url SOFORT API

public function sofyAction()
{
$args = [ 'config_key' => $this->getConfigKey() ];
$sofy = new Api($args);
$helper = $this->getServiceLocator()->get('ViewHelperManager')->get('ServerUrl');
$successUrl = $helper($this->url()->fromRoute('sofort_response'));
$params = [
'amount' => 1500,
'currency_code' => 'EUR',
'reason' => 'Vouhcer Order',
'success_url' => $successUrl,
'customer_protection' => false,
'notification_url' => 'MY_PRIVATE_RESPONSE_URL',
];
$trans = $sofy->createTransaction($params);
return $this->redirect()->toUrl($trans['payment_url']);
}
How to get response and transaction ID as given it API document in Notification URL and on success URL too , please unable to find any help or guide for it ?
The easiest way is to let Payum do notification related job for you. To do so you either:
have to create manually a notification token using Payum's token factory (I am not sure it is present in the Zend module, it is quite old). Use the token as notification_url. Nothing more. Sofort will send a request to that url and Payum does the rest.
Make sure the token factory is passed to a gateway object and later is injected to capture action object. Leave the notification_url field empty and Payum will generate a new one.
use your own url as notification one and add there all the info you need (as a query string). I wouldn't recommend it since you expose sensitive data and once could try to exploit it.
I solved it this way by appending ?trx=-TRANSACTION- with success and notification url and than in response i recieved Transaction id as parameter and later loaded TransactionData with that transactionId . Payum Token way wasn't working for me ! Obiously had to use its config key to create Payum/Sofort/Api isnstance,
REQUEST:
$args = [ 'config_key' => $sofortConfigKey ];
$sofortPay = new Api($args);
// ?trx=-TRANSACTION- will append transacion ID as response param !
$params = [
'amount' => $coupon['price'],
'currency_code' => $coupon['currency'],
'reason' => $coupon['description'],
'success_url' => $successUrl.'?trx=-TRANSACTION-',
'abort_url' => $abortUrl.'?trx=-TRANSACTION-',
'customer_protection' => false,
'notification_url' => '_URL_'.'?trx=-TRANSACTION-',
];
$transactionParams = $sofortPay->createTransaction($params);
return $this->redirect()->toUrl($transactionParams['payment_url']);
RESPONSE:
$args = [ 'config_key' => $configKey ];
$sofy = new Api( $args );
$transNumber = $this->getRequest()->getQuery('trx');
$fields = $sofy->getTransactionData($transNumber);
Took help from API document. Payum documentation is worst. SOFORT API DOC

How to set Navigation menu based on User type - SOCIALENGINE

How to set Navigation based on user type/profile type logged in.
All I could do is - set auth for specific user type
if (!$this->_helper->requireAuth()->setAuthParams('<module>', null, 'create')->isValid())
return;
But with this the menu will be still available
For example - If a Candidate logs in I should be able to hide create JOB menu.
Please give some insights on this. Thanks for your time!
Please create a function in menu.php in plugin of your module.You can check user module and also add a entry 'engine4_core_menuitems'. In table find your menu add entry in plugin _Plugin_Menus. Below function will have naming convention as your your function Name.
public function onMenuInitialize_JobMenu()
{
$viewer = Engine_Api::_()->user()->getViewer();
//assuming level id 4 for candidate
if( !$viewer->level_id == '4') {
return false;
}
return array(
'label' => 'create Job',
'route' => 'job_general',
'params' => array(
'action' => 'groupsms'
)
);
}

cakephp select dropdown list

i have the following models: Student,Form,FormsStream.
the student model have foreign keys to both models. Student.form_id is a foreignKey to the form table,Student.stream_id is foreign to the FormsStream table. i already have entries for both forms and formsStreams.
to add the student Form and Stream i select both from respective drop-down list. i already created the drop-down list.
my Problem.
previously i was able to save/edit student form and stream but after making those fields foreign keys to be selected i cant save new or edit those fields. i use cakePHP 2.5.4.
however i can do that in SQL.
i cant seem to figure out the problem with the select lists.
my method to get the forms from the database
public function loadStudentForm() {
$this->loadModel('Student'); //load the associated models
$this->loadModel('Form');
$forms = $this->Form->find('list',array('fields' => 'form_name')); //get the forms from the database
$this->set('forms',$forms);
}
method to get streams from database
public function loadStreams() {
$this->loadModel('FormsStream');
$streams = $this->FormsStream->find('list',array('fields' => 'stream_name'));
$this->set('streams',$streams);
}
student add method
public function addStudent() {
if ($this->request->is('post')) {
$this->loadStudentForm();
$this->loadStreams();
$this->Student->create();
if ($this->Student->save($this->request->data)) {
$this->Session->setFlash(__('New student record added to the database.'));
return $this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The student could not be added.Please ensure all fields are correctly entered'));
}
}
}
the extract from add.ctp for selecting student form and stream
echo $this->Form->input('forms',array('label' => 'Form'));
echo $this->Form->input('streams',array('label' => 'Class stream'));
so far printing contents of validateErrors shows this:
array(
'Student' => array(
'form_id' => array(
(int) 0 => 'You must select the form'
),
'stream_id' => array(
(int) 0 => 'You must choose a stream'
)
),
'Form' => array(),
'FormsStream' => array()
)
i've even tried to intercept the request in burpsuite and i can see the form and stream id are passed.just dont get why they are empty in the above array
_method=POST&data%5BStudent%5D%5Badmission_no%5D=1002&data%5BStudent%5D%5Bfirst_name%5D=peter&data%5BStudent%5D%5Bmiddle_name%5D=per&data%5BStudent%5D%5Blast_name%5D=pee&data%5BStudent%5D%5Bgender%5D=Male&data%5BStudent%5D%5Bdate_of_birth%5D%5Bmonth%5D=11&data%5BStudent%5D%5Bdate_of_birth%5D%5Bday%5D=05&data%5BStudent%5D%5Bdate_of_birth%5D%5Byear%5D=2014&data%5BStudent%5D%5Bjoin_date%5D%5Bmonth%5D=11&data%5BStudent%5D%5Bjoin_date%5D%5Bday%5D=05&data%5BStudent%5D%5Bjoin_date%5D%5Byear%5D=2014&data%5BStudent%5D%5Bforms%5D=1&data%5BStudent%5D%5Bsstrong texttreams%5D=1
The input must be form_id and stream_id. Even if you set them with plural form cakephp recognize it in the following form.
echo $this->Form->input('form_id',array('label' => 'Form'));
echo $this->Form->input('stream_id',array('label' => 'Class stream'));

Form to make URL - Simple product chooser

I've created a products and services folders and items in SilverStripe CMS and everything is fine with it but I'd like to have a kind of product chooser.
I thought that I can make it through the form by drop-downs and when you will choose value 1 then you can pick from value 2 but what's the most important is when you click on submit I would like the form to construct a link/ url like: http://www.example.com/value1/value2 and automaticaly go there.
Simple: let's assume that I have upper section (called SAMSUNG) then inside of it I've products/ child pages (for example: Galaxy S3, Galaxy S4, Galaxy S5, etc.) and I want people to choose using this simple form: first choose manufacturer -> device type/ model/ name -> click submit (go) and it will take you directly to the right place: http://www.example.com/manufacturer/product
Is it possible to get URL like that through the form?
This would be easy enough. Basically what you want to do is have your form submit somewhere, then redirect to the desired URL using the submitted data from there.
In some controller
private static $allowed_actions = array(
'Form'
);
public function Form() {
$fields = new FieldList(
new DropdownField('Manufacturer', 'Manufacturer', array(
'Samsumg' => 'Samsumg',
'HTC' => 'HTC',
'Apple' => 'Apple'
)),
// It's necessary that first argument is Samsung as it will
// be used to fetch the device later on
new DropdownField('Samsumg', 'Samsumg', array(
'GalaxyS3' => 'Galaxy S3',
'GalaxyS4' => 'Galaxy S4',
'GalaxyS5' => 'Galaxy S5'
)),
// It's necessary that first argument is HTC as it will
// be used to fetch the device later on
new DropdownField('HTC', 'HTC', array(
'Desire' => 'Desire',
'Wildfire' => 'Wildfire',
'One' => 'One'
)),
// It's necessary that first argument is Apple as it will
// be used to fetch the device later on
new DropdownField('Apple', 'Apple', array(
'iPhne5' => 'iPhone 5',
'iPhone6' => 'iPhone 6',
'iPhone6Plus' => 'iPhone 6 Plus'
))
);
$actions = new FieldList(
new FormAction('submit', 'Search')
);
return new Form($this, 'Form', $fields, $actions);
}
public function submit($data, $form) {
// Get selected manufacturer
$manufacturer = $data['Manufacturer'];
// Get selected device by selected manufacturer
$device = $data[$manufacturer];
// Redirect to the manufacturer/device URL
return $this->redirect($manufacturer . '/' . $device);
}
Output the form by using $Form in your template.

Load a Symfony sfWidgetFormDoctrineChoice select with a limited set of results

I am developing a form in a Symfony application where a user must indicate a country, a region and an optional island using HTML select elements.
I have three models: Country, Region and Island; and Symfony has auto-generated three widgets in the form using the sfWidgetFormDoctrineChoice widget:
...
'country_id' => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Country'), 'add_empty' => false)),
'region_id' => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Region'), 'add_empty' => false)),
'island_id' => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Island'), 'add_empty' => true)),
...
Since the country list is large, and so the region list, I've been thinking on filtering the options available in Region and Island according to the value selected in Country.
Doing this after the HTML document is ready is easy with jQuery's change method and a simple AJAX request. But I wonder if there's a way of doing this directly from Symfony, perhaps in form configuration, to have a default combined selection.
Any suggestions?
Thanks!
After playing around with sfDependentSelectPlugin, I ended up assigning custom queries to initialize the HTML select elements:
$countryId = $this->getObject()->getCountry()->getTable()->getDefaultCountryId();
$regionId = $this->getObject()->getRegion()->getTable()->getDefaultRegionId($countryId);
$islandId = $this->getObject()->getIsland()->getTable()->getDefaultIslandId($regionId);
$this->widgetSchema->setDefault('country_id', $countryId);
$this->setWidget('region_id', new sfWidgetFormDoctrineChoice(array(
'model' => $this->getRelatedModelName('Region'),
'query' => $this->getObject()->getRegion()->getTable()->getRegionsQuery($countryId),
'default' => $regionId,
)));
$this->setWidget('island_id', new sfWidgetFormDoctrineChoice(array(
'model' => $this->getRelatedModelName('Island'),
'query' => $this->getObject()->getIsland()->getTable()->getIslandsQuery($regionId),
'add_empty' => '---',
'default' => $islandId,
)));
And then updating the options available with AJAX requests using jQuery. The good thing is that the actions that handle the AJAX requests use the same query methods above to return a new set of results.