/** * {@inheritDoc} */ public function render() { $today = date('Y-m-d'); $thisWeek = date('Y-m-d', strtotime('last monday')); $this->addCss('css/friendstoolbar.css'); $meta = new Usermeta(); $meta_table = $meta->getTable(); $this->vars['numFriends'] = Usermeta::where('current_member', '!=', Usermeta::IS_STAFF)->count(); $this->vars['todayFriends'] = User::join($meta_table, 'users.id', '=', $meta_table . '.user_id')->where('current_member', '!=', Usermeta::IS_STAFF)->where('created_at', '>=', $today)->count(); $this->vars['weekFriends'] = User::join($meta_table, 'users.id', '=', $meta_table . '.user_id')->where('current_member', '!=', Usermeta::IS_STAFF)->where('created_at', '>=', $thisWeek)->count(); $this->vars['averageFriends'] = $this->getAverageFriends(); return $this->makePartial('widget'); }
public function onRun() { $this->addAssets(); $user = $this->getUser(); $this->page['options'] = Usermeta::getOptions(); $this->page['user'] = $user; }
public function render() { $friends = User::count(); $partners = Usermeta::select('id')->where('current_member', Usermeta::IS_MEMBER)->count(); $notPartners = $friends - $partners; $this->vars['totalFriends'] = number_format($friends); $this->vars['notPartners'] = number_format($notPartners); $this->vars['partners'] = number_format($partners); $this->vars['partnerPercent'] = round($partners / $friends * 100) . '%'; return $this->makePartial('widget'); }
public function render() { $results = Usermeta::select(DB::raw('count(user_id) as count'), 'gender')->groupBy('gender')->get(); $count = User::count(); $total = 0; foreach ($results as $result) { if (empty($result->gender)) { continue; } $data[$result->gender] = $result->count; $total += $result->count; } $data[Lang::get('dma.friends::lang.user.noGender')] = $count - $total; arsort($data); $this->vars['data'] = $data; return $this->makePartial('widget'); }
public function getOptinFriends($friends) { $numWithOptin = Usermeta::where('email_optin', 1)->count(); return round($numWithOptin / $friends * 100); }
/** * Render the registration form. Override the partial "register-form" * in the active theme to customize the registration form */ public function onRegister() { $options = Usermeta::getOptions(); return $this->renderPartial('@modalDisplay', ['title' => Lang::get('dma.friends::lang.userLogin.registerTitle'), 'content' => $this->renderPartial('register-form', ['options' => $options, 'avatars' => $this->getAvatars(), 'terms' => $this->renderPartial('terms-and-conditions.htm')])]); }
/** * Register a user * * @param array $data * An array of attributes to register a user. * Any fields that are not properties on the user object * Will be applied to the Usermeta object * * @param array $rules * A set of validation rules to validate against * see http://laravel.com/docs/5.1/validation * * @return User $user * return the user object after registration */ public static function register($data, $rules = []) { $rules += ['first_name' => 'required|min:2', 'last_name' => 'required|min:2', 'email' => 'required|email|between:2,64', 'password' => 'required|min:6', 'password_confirmation' => 'required|min:6']; Event::fire('auth.preRegister', [$data, $rules]); $validation = Validator::make($data, $rules); if ($validation->fails()) { throw new ValidationException($validation); } /* * Register user */ $requireActivation = UserSettings::get('require_activation', true); $automaticActivation = UserSettings::get('activate_mode') == UserSettings::ACTIVATE_AUTO; $userActivation = UserSettings::get('activate_mode') == UserSettings::ACTIVATE_USER; /* * Data altercations */ $data['first_name'] = ucwords($data['first_name']); $data['last_name'] = ucwords($data['last_name']); $data['birth_date'] = UserExtend::parseBirthdate($data['birthday']); $data['phone'] = UserExtend::parsePhone($data['phone']); $data['email_optin'] = isset($data['email_optin']) ? $data['email_optin'] : false; // Split the data into whats required for the user and usermeta models $userData = ['name' => $data['first_name'] . ' ' . $data['last_name'], 'password' => $data['password'], 'password_confirmation' => $data['password_confirmation'], 'email' => $data['email'], 'street_addr' => $data['street_addr'], 'city' => $data['city'], 'state' => $data['state'], 'zip' => $data['zip'], 'phone' => $data['phone']]; $user = Auth::register($userData, $automaticActivation); // Save user metadata $usermeta = Usermeta::create($data); $user->metadata()->save($usermeta); if (isset($data['avatar'])) { UserExtend::uploadAvatar($user, $data['avatar']); } /* * Activation is by the user, send the email */ if ($userActivation) { $this->sendActivationEmail($user); } /* * Automatically activated or not required, log the user in */ if ($automaticActivation || !$requireActivation) { Auth::login($user); } if ($user) { /* * Fire event that user has registered */ Event::fire('auth.register', [$user]); return $user; } return false; }
/** * Extend User fields in Rainlab.User plugin * @param mixed $widget */ private function extendedUserFields($widget) { if (!$widget->getController() instanceof \RainLab\User\Controllers\Users) { return; } if ($widget->getContext() != 'update') { return; } // Make sure the User metadata exists for this user. if (!Metadata::getFromUser($widget->model)) { return; } $widget->addFields(['metadata[first_name]' => ['label' => 'First Name', 'tab' => 'Metadata', 'span' => 'left'], 'metadata[last_name]' => ['label' => 'Last Name', 'tab' => 'Metadata', 'span' => 'right'], 'metadata[email_optin]' => ['label' => 'Email Opt-in', 'type' => 'checkbox', 'tab' => 'Metadata'], 'metadata[current_member]' => ['label' => 'Current member?', 'type' => 'dropdown', 'span' => 'left', 'options' => ['Non Member', 'Member', 'Staff'], 'tab' => 'Metadata'], 'metadata[current_member_number]' => ['label' => 'Current Member Number', 'tab' => 'Metadata', 'span' => 'left'], 'metadata[gender]' => ['label' => 'Gender', 'tab' => 'Metadata', 'span' => 'left'], 'metadata[education]' => ['label' => 'Education', 'tab' => 'Metadata'], 'metadata[household_income]' => ['label' => 'Household Income', 'tab' => 'Metadata'], 'metadata[household_size]' => ['label' => 'Household Size', 'tab' => 'Metadata'], 'points' => ['tab' => 'Points', 'type' => 'points'], 'activities[activities]' => ['tab' => 'Activities', 'type' => 'partial', 'path' => '@/plugins/dma/friends/models/activity/users.htm'], 'badges[badges]' => ['tab' => 'Badges', 'type' => 'partial', 'path' => '@/plugins/dma/friends/models/badge/users.htm'], 'rewards[rewards]' => ['tab' => 'Rewards', 'type' => 'partial', 'path' => '@/plugins/dma/friends/models/reward/users.htm'], 'print' => ['tab' => 'Membership Card', 'type' => 'printmembershipcard']], 'primary'); }
/** * @SWG\Definition( * definition="response.profile.options", * type="object", * @SWG\Property( * property="gender", * type="array", * items=@SWG\Schema(type="string") * ), * @SWG\Property( * property="race", * type="array", * items=@SWG\Schema(type="string") * ), * @SWG\Property( * description="Currently hardcode to return only USA states", * property="states", * type="array", * items=@SWG\Schema(ref="#/definitions/state") * ), * @SWG\Property( * property="household_income", * type="array", * items=@SWG\Schema(type="string") * ), * @SWG\Property( * property="education", * type="array", * items=@SWG\Schema(type="string") * ), * @SWG\Property( * property="avatars", * type="array", * items=@SWG\Schema(type="string") * ) * ) * * * @SWG\Get( * path="users/profile-options/{field}", * description="Returns user profile options", * summary="Get profile options", * tags={ "user"}, * * @SWG\Parameter( * description="Return options only for the given field", * in="path", * name="field", * required=false, * type="string", * enum={"gender", "race", "states", "household_income", "education", "avatars"} * ), * * @SWG\Response( * response=200, * description="Successful response", * @SWG\Schema(ref="#/definitions/response.profile.options") * ), * @SWG\Response( * response=500, * description="Unexpected error", * @SWG\Schema(ref="#/definitions/error500") * ), * @SWG\Response( * response=404, * description="Not Found", * @SWG\Schema(ref="#/definitions/error404") * ) * ) */ public function profileOptions($field = null) { $opts = null; // Options from Usermeta $options = Usermeta::getOptions(); // Avatar options as is used in the UserProfile component $options['avatars'] = $this->getThemeAvatarOptions(); if (!is_null($field)) { $fieldOpts = array_get($options, strtolower(trim($field)), null); if (!is_null($fieldOpts)) { $opts = [$field => $fieldOpts]; } else { $message = 'Valid fields are: [ ' . implode(', ', array_keys($options)) . ' ]'; return Response::api()->errorInternalError($message); } } else { $opts = $options; // Return all } return $opts; }