I'd like to modify a field in the user table every time a subscription payment is made. Here's what I have so far (got this code off the forum as well): PHP: Am_Di::getInstance()->hook->add('paymentAfterInsert', 'customPaymentAfterInsert');function customPaymentAfterInsert(Am_Event_PaymentAfterInsert $event){ $invoice = $event->getInvoice(); $$user_id = $invoice->user_id; //update db where user_id=$user_id with some value} My question is how can I execute the query using amember's active record? Thanks in advance!
It is really easy PHP: Am_Di::getInstance()->hook->add('paymentAfterInsert', 'customPaymentAfterInsert');function customPaymentAfterInsert(Am_Event_PaymentAfterInsert $event){ $payment = $event->getPayment(); // InvoicePayment object $invoice = $event->getInvoice(); // Invoice object $user = $invoice->getUser(); // User object // now change field (only created as SQL field!) $user->customfield = 'newvalue'; $user->update(); // to run any custom query Am_Di::getInstance()->db->query("UPDATE xx SET yy=22"); // or run another custom select $rows = Am_Di::getInstance()->db->select("SELECT * FROM xx WHERE user_id=?d", $user->user_id);}
how would you write that hook/query to update a plain_password custom field with the user's actual password every time a new user registers or updates their password or the admin updates the password manually?
Here is example: PHP: Am_Di::getInstance()->hook->add(Am_Event::SET_PASSWORD, 'onSetPassword');function onSetPassword(Am_Event_SetPassword $e){ $user = $e->getUser(); $password = $e->getPassword(); $user->updateQuick('plain_password', $password); // Or $user->data()->set('plain_password', $password)->update(); if field is not sql}