Skip to content

Commit

Permalink
Merge pull request #40 from rainlab/next
Browse files Browse the repository at this point in the history
[2.x] Compatibility with RainLab.User v3
  • Loading branch information
daftspunk authored May 1, 2024
2 parents 2a42930 + 1ebcdc4 commit 4b35328
Show file tree
Hide file tree
Showing 56 changed files with 1,397 additions and 768 deletions.
19 changes: 0 additions & 19 deletions LICENCE.md

This file was deleted.

5 changes: 5 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# License

This plugin is an official extension of the October CMS platform and is free to use if you have a platform license.

See End User License Agreement at https://octobercms.com/eula for more details.
119 changes: 19 additions & 100 deletions Plugin.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
<?php namespace RainLab\UserPlus;

use Yaml;
use File;
use Event;
use System\Classes\PluginBase;
use RainLab\User\Models\User as UserModel;
use RainLab\Notify\Models\Notification as NotificationModel;
use RainLab\User\Controllers\Users as UsersController;
use RainLab\Notify\NotifyRules\SaveDatabaseAction;
use RainLab\User\Classes\UserEventBase;

/**
* Plugin Information File
Expand All @@ -17,116 +11,41 @@ class Plugin extends PluginBase
/**
* @var array require plugins
*/
public $require = ['RainLab.User', 'RainLab.Location', 'RainLab.Notify'];
public $require = [
'RainLab.User',
'RainLab.Location'
];

/**
* Returns information about this plugin.
*
* @return array
* pluginDetails
*/
public function pluginDetails()
{
return [
'name' => 'rainlab.userplus::lang.plugin.name',
'description' => 'rainlab.userplus::lang.plugin.description',
'author' => 'Alexey Bobkov, Samuel Georges',
'icon' => 'icon-user-plus',
'homepage' => 'https://github.com/rainlab/userplus-plugin'
'name' => "User Plus+",
'description' => "Adds profile fields to users.",
'author' => 'Alexey Bobkov, Samuel Georges',
'icon' => 'icon-user-plus',
'homepage' => 'https://github.com/rainlab/userplus-plugin'
];
}

/**
* boot
*/
public function boot()
{
$this->extendUserModel();
$this->extendUsersController();
$this->extendSaveDatabaseAction();
$this->extendUserEventBase();
Event::subscribe(\RainLab\UserPlus\Classes\ExtendUserPlugin::class);
}

/**
* registerComponents
*/
public function registerComponents()
{
return [
\RainLab\UserPlus\Components\AddressBook::class => 'addressBook',
\RainLab\UserPlus\Components\Notifications::class => 'notifications',
];
}

protected function extendUserModel()
{
UserModel::extend(function($model) {
$model->addFillable([
'phone',
'mobile',
'company',
'street_addr',
'city',
'zip'
]);

if (!$model->isClassExtendedWith(\RainLab\Location\Behaviors\LocationModel::class)) {
$model->extendClassWith(\RainLab\Location\Behaviors\LocationModel::class);
}

$model->morphMany['notifications'] = [
NotificationModel::class,
'name' => 'notifiable',
'order' => 'created_at desc'
];
});
}

protected function extendUsersController()
{
UsersController::extendFormFields(function($widget) {
// Prevent extending of related form instead of the intended User form
if (!$widget->model instanceof UserModel) {
return;
}

if ($widget->isNested) {
return;
}

$configFile = plugins_path('rainlab/userplus/config/profile_fields.yaml');
$config = Yaml::parse(File::get($configFile));
$widget->addTabFields($config);
});
}

public function registerNotificationRules()
{
return [
'events' => [],
'actions' => [],
'conditions' => [
\RainLab\UserPlus\NotifyRules\UserLocationAttributeCondition::class
],
'presets' => '$/rainlab/userplus/config/notify_presets.yaml',
];
}

protected function extendUserEventBase()
{
if (!class_exists(UserEventBase::class)) {
return;
}

UserEventBase::extend(function($event) {
$event->conditions[] = \RainLab\UserPlus\NotifyRules\UserLocationAttributeCondition::class;
});
}

protected function extendSaveDatabaseAction()
{
if (!class_exists(SaveDatabaseAction::class)) {
return;
}

SaveDatabaseAction::extend(function ($action) {
$action->addTableDefinition([
'label' => 'User activity',
'class' => UserModel::class,
'param' => 'user'
]);
});
}
}
51 changes: 44 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,50 @@
# User Plus+ plugin

This plugin extends the [User plugin](http://octobercms.com/plugin/rainlab-user) with extra profile fields and features.
This plugin extends the [User plugin](https://octobercms.com/plugin/rainlab-user) with extra profile fields and features.

* Adds the following extra fields to a user: `phone`, `mobile`, `company`, `street_addr`, `city`, `zip`.
* A user can belong to a Country and/or State, sourced from the [Location plugin](http://octobercms.com/plugin/rainlab-location).
- Adds the following extra fields to a user: `company`, `phone`, `address_line1`, `address_line2`, `city`, `zip`, `state_id`, `country_id`.
- Adds an Address Book to store multiple addresses for a user.
- A user can belong to a Country and/or State, sourced from the [Location plugin](https://octobercms.com/plugin/rainlab-location).

### Potential features
View this plugin on the October CMS marketplace:

* A user can befriend other users via a friendship system.
* A user can earn "Experience Points" by performing predefined activities.
- https://octobercms.com/plugin/rainlab-user

> Note these features may or may not be implemented in the future, but act only as an indicator of the plugin's potential.
### Address Book Component

The `addressBook` component is used to manage multiple addresses for a user. Enable or disable the address book using the **System → User Settings → Profile** page.

To see an example of the usage, we recommend installing this plugin with the `RainLab.Vanilla` theme.

- https://github.com/rainlab/vanilla-theme

### Notifications Component

The `notifications` component is used to display notifications assigned to the user, it allows them to mark notifications as read. It is best to add this component to the layout, the component will render the popover in a hidden state.

```twig
{% component 'notifications' %}
```

The link to display notifications can be anywhere, and should have the `data-notifications-toggle` attribute to trigger the popover.

```html
<button
type="button"
class="btn btn-default"
data-notifications-toggle>
View Notifications
</button>
```

You may also display a counter with the `notifications.hasUnread` check.

```twig
{% if notifications.hasUnread %}
<span class="counter">{{ notifications.unreadCount }}</span>
{% endif %}
```

### License

This plugin is an official extension of the October CMS platform and is free to use if you have a platform license. See [EULA license](LICENSE.md) for more details.
Loading

0 comments on commit 4b35328

Please sign in to comment.