update another collection from a custom hook Directus - php

Good afternoon colleagues ...
I need to be able to update another collection from a custom hook,
The following happens that if I use ItemsService or TableGatewayFactory it uses the acl of the container ... in this case the user will be from a customer role, but this does not have the permission to edit orders, I would like to keep it that way ...
It doesn't matter if I have to update the item with another user using their token, or any other alternative ...
Thanks in advance....
'item.update.transactionlog' => function ($data) { <br>
$container = Application::getInstance()->getContainer(); <br>
$itemsService = new \Directus\Services\ItemsService($container);<br>
$acl = $container->get('acl');<br>
$params = [];<br>
$orden = ['status' => 'paid'];<br>
$orderUpdate = $itemsService->update('orders', $data['orderid'], $orden, $params);<br>
}

Related

Updating and Invoicing Stripe Subscription Quantity with Invoice description laravel cashier

Good Day,
I'm working on a project involving Laravel Cashier. I want to give user's the ability to update their subscription quantity and get charged immediately (which I have been able to achieve, using the code below)
$user = Auth::user()
$user->subscription('main')->incrementAndInvoice(10000);
As much as the above works as expected, the invoice returned doesn't include a description indicating the changes instead the invoice description is blank. But when I checked the Event Data on stripe the two descriptions are there [see below image]
The above images shows a user who was currently on a subscription plan with 5000 quantities but increased to 15000 quantities. Is there a way to include these descriptions in the invoice generated.
After i checked the incrementAndInvoice() method , it only accepts two parameter (1. count, 2. Plan) as seen below;
no option to include description like we have for the charge() method. Is there any workaround to this? Any ideas or pointers in the right direction would be really appreciated.
Thanks for your help in advance.
At the time being there is no implementation to include the description in incrementAndInvoice().
So we have to implement it and before we do that please checkout Update an invoice.
First change this line: $user->subscription('main')->incrementAndInvoice(10000); to $subscription = $user->subscription('main')->incrementAndInvoice(10000); (we are assigning it to $subscription variable)
then get the invoice as below:
$new_invoice = $user->invoices()->filter(function($invoice) use ($subscription) {
return $invoice->subscription === $subscription->stripe_id;
});
After updating the subscription quantity we will add the following:
$client = new \GuzzleHttp\Client();
$request = $client->post('https://api.stripe.com/v1/invoices/' . $invoice_id, [
'auth' => [$secret_key, null]
'json' => ['description' => 'your description']
]);
$response = json_decode($request->getBody());
Or the following:
$stripe = new \Stripe\StripeClient(
$secret_key
);
$stripe->invoices->update(
$invoice_id,
['description' => 'your description']
);
Please note that:
the $invoice_id is the id of the invoice.
the $secret_key is the API key.

Retrieve All User Lists using Aweber API

I am adding AWeber as an autoresponder in a web application. Using AWeber API, I am able to add a new subscriber to list with a known name which is in this case is firstlist:
$app = new MyApp();
$app->findSubscriber('whtever#aol.com');
$list = $app->findList('firstlist');
$subscriber = array(
'email' => 'someemail#gmail.com',
'name' => 'Name here'
);
$app->addSubscriber($subscriber, $list);
Function definition for findList() is:
function findList($listName) {
try {
$foundLists = $this->account->lists->find(array('name' => $listName));
return $foundLists[0];
}
catch(Exception $exc) {
print $exc;
}
}
As I am developing a public application, so I need to provide users an option to select from their available lists.
Please guide me how I can retrieve all the lists name.
You are returning $foundLists[0] so it will return single list. Try to return foundLists and check what it returns.
This may help you: https://labs.aweber.com/snippets/lists
In short, I pulled the lists by first finding the Aweber User Id so that I could use it in the URL https://api.aweber.com/1.0/accounts/<id>/lists
To find the User ID, I first got the account.
$this->aweber->getAccount($token['access'], $token['secret']);
Then, I retrieve the user's information.
$aweber_user = $this->aweber->loadFromUrl('https://api.aweber.com/1.0/accounts');
From that, I grabbed the user ID with...
$id = $aweber_user->data['entries'][0]['id'];
Once I had the user ID, I could then retrieve their lists with...
$lists = $this->aweber->loadFromUrl('https://api.aweber.com/1.0/accounts/'.$id.'/lists');
This example is more of a procedural approach, of course, I recommend utilizing classes.

Yiiframework First time login

I'm currently busy with a project that needs users to go to a specific page to create a profile when they log in for the first time (and haven't created one yet). Honestly, I don't know where to start. I would like to do it in a good way.
So in short:
User signs up -> logs in -> needs to fill in form before anything else is allowed -> continue to rest of application
Question: What is a neat way to do this? A solution that isn't going to give me problems in the future development of the application.
I suggest you to use filters. In every controller where the completed profile is neeeded add this code:
public function filters() {
return array(
'completedProfile + method1, method2, method3', // Replace your actions here
);
}
In your base controller (if you don't use base controller, in any controllers) you need to create the filter named completedProfile with the simular code:
public function filterCompletedProfile($filterChain) {
$criteria = new CDBCriteria(array(
'condition' => 'id = :id AND firstname IS NOT NULL AND lastname IS NOT NULL',
'params' => array(':id' => Yii::app()->user->getId())
));
$count = User::model()->count($criteria);
if ($count == 1) {
$filterChain->run();
} else {
$this->redirect(array('user/profile'));
}
}
Possibly add a field to the user profile database table which denotes if they have filled out their profile information. Something like profile_complete. Then you can do a test on pages to see if profile_complete is true and display the page if so, and display the profile page if not.

Multi-level Registration in Drupal

How to implement two type of registration like student and teacher?
I need two type of registration one for Teacher and one for Student. Both are different registration and both have different roles. Is it possible in Drupal? And also I need registering Student there is no admin approval but for Teacher registration, admin approval is required. How can I achieve this in Drupal 6?
In the custom user registration form add one more select box field with ROLE TYPE (student, teacher).Then on the submit hook check like shown below.
function add_student_form_submit($form, &$form_state) {
$fields = array();
$fields['is_new'] = true;
$fields['name'] = $form_state['values']['user_name'];
$fields['pass'] = $form_state['values']['pass'];
$role_type = $form_state['values']['role_type'];
//Add the user to the corresponding role
$fields['roles'] = array($role_type)
//here you can achieve the thing which you want.If the role is a teacher then set
//status = 0, else status = 1
if($role_type == 'student')
$fields['status'] = 1;
else
$fields['status'] = 0; // $user = user_save(drupal_anonymous_user(), $fields); //This works in D7
$user = user_save('', $fields); //pretty sure this is what works in D6 }
If the user is the teacher you should go to http://localhost/domain_name/admin/user/user. Here you can filter the Inactive users and activate them.
hey you can use below modules for creating multilevel registration.
http://drupal.org/project/content_profile
http://drupal.org/project/autoassignrole
above modules help you to create multilevel registration form in site. from content profile you can create form and also give auto assign role to student.
As far as i'm aware, drupal doesn't provide any mechanism for having multiple types of registration forms. However you can fairly easily create your own registration form from scratch. All you really need is the user_save function to create a new user. See the sample code below as part of a form_submit hook
function add_student_form_submit($form, &$form_state) {
$fields = array();
$fields['is_new'] = true;
$fields['name'] = $form_state['values']['user_name'];
$fields['pass'] = $form_state['values']['pass'];
$fields['status'] = 1;
// $user = user_save(drupal_anonymous_user(), $fields); //This works in D7
$user = user_save('', $fields); //pretty sure this is what works in D6
}
Using this you can create whatever custom logic you want for each form

Where is the action.class in sfDoctrineGuardPlugin for create new user?

I installed sfDoctrineGuardUser for Symfony 1.4.11, but I can't find the action.class, where register user. I find only class sfGuardCreateUserTask :
protected function execute($arguments = array(), $options = array())
{
$databaseManager = new sfDatabaseManager($this->configuration);
$user = new sfGuardUser();
$user->setEmailAddress($arguments['email_address']);
$user->setUsername($arguments['username']);
$user->setPassword($arguments['password']);
$user->setFirstName($arguments['first_name']);
$user->setLastName($arguments['last_name']);
$user->setIsActive(true);
$user->setIsSuperAdmin($options['is-super-admin']);
$user->save();
$this->logSection('guard', sprintf('Create user "%s"', $arguments['username']));
}
but this isn't this...
I can't find anywhere for example $user->setFirstName($arguments['first_name']); and modified to:
$user->setFirstName($arguments['first_name'] . '#');
Where is the action.class in sfDoctrineGuardPlugin for create new user?
Basically, you don't need that action (or to customize it) in order to create new users. Just create a custom action that generates your registration form and handles the post:
$user = new sfGuardUser();
$user-> // manipulate however you like
$user->save();
try
cache\frontend\prod\modules\autoSfGuardUser\actions
or something similar
if this is what you're looking for, don't rewrite it in there!!
Instead, copy the action to your normal sfGuard module and edit it there
Everything you need is already published by the symfony team :
http://symfony.com/blog/call-the-expert-simple-registration-with-sfdoctrineguardplugin
for further information : http://symfony.com/blog/call-the-expert-customizing-sfdoctrineguardplugin

Categories