/** * Remove user credits depending of order * * @access public * @param object $order = Order object * @param array of objects $products = Products from order * @return void */ public static function remove_credits($order = false, $products = false) { if (!is_numeric($order->user_id)) { return false; } // Get user to edit if (!\Sentry::user_exists((int) $order->user_id)) { return false; } $user = new \Sentry_User((int) $order->user_id); // Remove user credits $seek = $user->get('metadata.seek_credits') - ($order->seek > 0 ? 1 : 0); $seek >= 0 or $seek = 0; $careerone = $user->get('metadata.careerone_credits') - ($order->careerone > 0 ? 1 : 0); $careerone >= 0 or $careerone = 0; $update = array('metadata' => array('seek_credits' => $seek, 'careerone_credits' => $careerone)); // Update user credits if ($user->update($update)) { return true; } return false; }
/** * Add user credits depending of order * * @access public * @param object $order = Order object * @param array of objects $products = Products from order * @return void */ public function add_credits($order = false, $products = false) { if (!is_numeric($order->user_id)) { return false; } // Get user to edit if (!\Sentry::user_exists((int) $order->user_id)) { return false; } $user = new \Sentry_User((int) $order->user_id); // Add user credits $update = array('metadata' => array('seek_credits' => $user->get('metadata.seek_credits') + $order->seek, 'careerone_credits' => $user->get('metadata.careerone_credits') + $order->careerone)); // Update user credits if ($user->update($update)) { return true; } return false; }
public function action_update($id = false) { if (!is_numeric($id)) { \Response::redirect('admin/user/list'); } // Get user to edit if (!\Sentry::user_exists((int) $id)) { \Response::redirect('admin/user/list'); } \View::set_global('title', 'Edit User'); // Get groups $groups = \Sentry::group()->all('front'); // Update group details if (\Input::post('details', false)) { $item = new \Sentry_User((int) $id); $val = \User\Controller_Admin_Validate::forge('update', $item['id']); if ($val->run()) { // Get POST values $insert = \Input::post(); array_walk($insert, create_function('&$val', '$val = trim($val);')); try { // Generate random username //$username = '******' . \Str::random('numeric', 16); $username = $insert['email']; $email = $insert['email']; $password = $insert['password']; $user_group = $insert['user_group']; $activated = $insert['activated']; $email_client = $insert['email_client']; $insert['guest'] = $user_group == 3 ? 1 : 0; unset($insert['email'], $insert['password'], $insert['confirm_password'], $insert['user_group'], $insert['details'], $insert['save'], $insert['exit'], $insert['activated'], $insert['email_client']); $only_billing = array('business_name', 'purchase_limit_value', 'purchase_limit_period', 'master', 'note', 'credit_account', 'guest'); // Set shipping data to be same as billing by default /*foreach($insert as $key => $value) { if(!in_array($key, $only_billing) && strpos($key, 'shipping_') === false) { if(empty($insert['shipping_'.$key])) $insert['shipping_'.$key] = $value; } }*/ // create the user - no activation required $vars = array('username' => $username, 'email' => $email, 'password' => $password, 'metadata' => $insert, 'activated' => $activated); // Send email to user with new password if ($email_client == 1 && !empty($vars['password'])) { $email_data = array('site_title' => \Config::get('site_title'), 'customer_identity' => ucwords($item->get('metadata.first_name') . ' ' . $item->get('metadata.last_name')), 'new_password' => $vars['password']); $this->autoresponder($item, $email_data); } if (empty($vars['password'])) { unset($vars['password']); } if ($item->update($vars)) { //Change user group if needed $user_groups = $item->groups(); if (!empty($user_groups)) { // Remove user from all other groups... foreach ($user_groups as $value) { $item->remove_from_group((int) $value['id']); } } $item = new \Sentry_User((int) $id); // ...and add it to selected one $item->add_to_group((int) $user_group); \Messages::success('User successfully updated.'); \Response::redirect(\Input::post('exit', false) ? \Uri::create('admin/user/list/') : \Uri::admin('current')); } else { // show validation errors \Messages::error('<strong>' . 'There was an error while trying to update user' . '</strong>'); } } catch (\Sentry\SentryException $e) { // show validation errors \Messages::error('<strong>' . 'There was an error while trying to update user' . '</strong>'); $errors = $e->getMessage(); \Messages::error($errors); } } else { if ($val->error() != array()) { // show validation errors \Messages::error('<strong>' . 'There was an error while trying to update user' . '</strong>'); foreach ($val->error() as $e) { \Messages::error($e->get_message()); } } } } $user = new \Sentry_User((int) $id); // Get single user group $user_group = $user->groups(); $user_group = current($user_group); $user->group = $user_group; \Theme::instance()->set_partial('content', $this->view_dir . 'update')->set('user', $user)->set('groups', $groups); }