<commit_before><?php namespace DMA\Friends;

use Backend;
use Illuminate\Support\Facades\Event;
use Rainlab\User\Models\User as User;
use DMA\Friends\Models\Usermeta as Metadata;
use DMA\Friends\Classes\ActivityManager;
use System\Classes\PluginBase;
use DMA\Friends\Classes\FriendsEventHandler;
use App;
use Illuminate\Foundation\AliasLoader;

/**
 * Friends Plugin Information File
 *
 * @authors <NAME>, <NAME>
 */
class Plugin extends PluginBase
{

    /** 
     * @var array Plugin dependencies
     */
    public $require = [
        'RainLab.User'
    ]; 

    /**
     * Returns information about this plugin.
     *
     * @return array
     */
    public function pluginDetails()
    {
        return [
            'name'        => 'Friends',
            'description' => 'A platform for users to earn badges and redeem rewards',
            'author'      => 'Dallas Museum of Art',
            'icon'        => 'icon-leaf'
        ];
    }

    public function registerPermissions()
    {
        return [
            'dma.friends.access_admin'  => ['label' => 'Manage Friends'],
        ];
    }

    public function registerSettings()
    {
        return [
            'locations' => [
                'label' => 'Locations',
                'description'   => 'Manage the kiosk locations',
                'category'      => 'Friends',
                'icon'          => 'icon-location-arrow',
                'url'           => Backend::url('dma/friends/locations'),
                'order'         => 0,
            ],  
            'categories' => [
                'label'         => 'Categories',
                'description'   => 'Manage the Categories',
                'category'      => 'Friends',
                'icon'          => 'icon-square',
                'url'           => Backend::url('dma/friends/categories'),
                'order'         => 10,
            ],
        ];
    }

    public function registerNavigation()
    {
        return [
            'friends' => [
                'label'         => 'Friends',
                'url'           => Backend::url('dma/friends/badges'),
                'icon'          => 'icon-users',
                'permissions'   => ['dma.friends.*'],
                'order'         => 500,
                'sideMenu'  => [
                    'activities'   => [
                        'label'     => 'Activities',
                        'icon'      => 'icon-child',
                        'url'       => Backend::url('dma/friends/activities'),
                    ],  
                    'badges'    => [
                        'label'     => 'Badges',
                        'icon'      => 'icon-shield',
                        'url'       => Backend::url('dma/friends/badges'),
                        'permissions'   => ['dma.friends.access_admin'],
                    ],
                    'rewards'   => [
                        'label'     => 'Rewards',
                        'icon'      => 'icon-money',
                        'url'       => Backend::url('dma/friends/rewards'),
                    ],
                    'activitylogs'   => [
                        'label'     => 'Activity Logs',
                        'icon'      => 'icon-rocket',
                        'url'       => Backend::url('dma/friends/activitylogs'),
                    ],
                    
                ]
            ]
        ];
    }

    public function registerComponents()
    {
        return [
            'DMA\Friends\Components\ActivityCodeForm'   => 'ActivityCodeForm',
            'DMA\Friends\Components\BadgeRecommend'     => 'BadgeRecommend',
            'DMA\Friends\Components\Modal'              => 'Modal',
            'DMA\Friends\Components\UserBadges'         => 'UserBadges',
        ];
    }

    /**
     * Register additional friends activity types
     */
    public function registerFriendsActivities()
    {
        return [
            'DMA\Friends\Activities\ActivityCode'   => 'ActivityCode',
            'DMA\Friends\Activities\LikeWorkOfArt'  => 'LikeWorkOfArt',
        ];
    }

    public function boot()
    {

    	// Register ServiceProviders
    	App::register('\EllipseSynergie\ApiResponse\Laravel\ResponseServiceProvider');
        App::register('DMA\Friends\FriendsServiceProvider');

        // Register Event Subscribers
        $subscriber = new FriendsEventHandler;
        Event::subscribe($subscriber);

        // Extend the user model to support our custom metadata        
        User::extend(function($model) {        
            $model->hasOne['metadata']          = ['DMA\Friends\Models\Usermeta'];     
            $model->hasMany['activityLogs']     = ['DMA\Friends\Models\ActivityLog'];      
            $model->belongsToMany['steps']      = ['DMA\Friends\Models\Step',       'table' => 'dma_friends_step_user',     'user_id', 'step_id'];     
            $model->belongsToMany['badges']     = ['DMA\Friends\Models\Badge',      'table' => 'dma_friends_badge_user',    'user_id', 'badge_id'];        
            $model->belongsToMany['groups']     = ['DMA\Friends\Models\UserGroup',  'table' => 'users_groups',              'user_id', 'group_id'];
            $model->belongsToMany['rewards']    = ['DMA\Friends\Models\Reward',     'table' => 'dma_friends_reward_user',   'user_id', 'reward_id'];       
        });
    	
        Event::listen('backend.form.extendFields', function($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',
                ],  
                'metadata[last_name]' => [
                    'label' => 'Last Name',
                    'tab'   => 'Metadata',
                ], 
                'metadata[points]' => [
                    'label' => 'Points',
                    'tab'   => 'Metadata',
                ],
                'metadata[email_optin]' => [
                    'label' => 'Email Opt-in',
                    'type'  => 'checkbox',
                    'tab'   => 'Metadata',
                ],
                'metadata[current_member]' => [
                    'label' => 'Current member?',
                    'type'  => 'checkbox',
                    'tab'   => 'Metadata',
                ],
                'metadata[current_member_number]' => [<commit_msg>fixed tab spaces<commit_after><?php namespace DMA\Friends;

use Backend;
use Illuminate\Support\Facades\Event;
use Rainlab\User\Models\User as User;
use DMA\Friends\Models\Usermeta as Metadata;
use DMA\Friends\Classes\ActivityManager;
use System\Classes\PluginBase;
use DMA\Friends\Classes\FriendsEventHandler;
use App;
use Illuminate\Foundation\AliasLoader;

/**
 * Friends Plugin Information File
 *
 * @authors <NAME>, <NAME>
 */
class Plugin extends PluginBase
{

    /** 
     * @var array Plugin dependencies
     */
    public $require = [
        'RainLab.User'
    ]; 

    /**
     * Returns information about this plugin.
     *
     * @return array
     */
    public function pluginDetails()
    {
        return [
            'name'        => 'Friends',
            'description' => 'A platform for users to earn badges and redeem rewards',
            'author'      => 'Dallas Museum of Art',
            'icon'        => 'icon-leaf'
        ];
    }

    public function registerPermissions()
    {
        return [
            'dma.friends.access_admin'  => ['label' => 'Manage Friends'],
        ];
    }

    public function registerSettings()
    {
        return [
            'locations' => [
                'label' => 'Locations',
                'description'   => 'Manage the kiosk locations',
                'category'      => 'Friends',
                'icon'          => 'icon-location-arrow',
                'url'           => Backend::url('dma/friends/locations'),
                'order'         => 0,
            ],  
            'categories' => [
                'label'         => 'Categories',
                'description'   => 'Manage the Categories',
                'category'      => 'Friends',
                'icon'          => 'icon-square',
                'url'           => Backend::url('dma/friends/categories'),
                'order'         => 10,
            ],
        ];
    }

    public function registerNavigation()
    {
        return [
            'friends' => [
                'label'         => 'Friends',
                'url'           => Backend::url('dma/friends/badges'),
                'icon'          => 'icon-users',
                'permissions'   => ['dma.friends.*'],
                'order'         => 500,
                'sideMenu'  => [
                    'activities'   => [
                        'label'     => 'Activities',
                        'icon'      => 'icon-child',
                        'url'       => Backend::url('dma/friends/activities'),
                    ],  
                    'badges'    => [
                        'label'     => 'Badges',
                        'icon'      => 'icon-shield',
                        'url'       => Backend::url('dma/friends/badges'),
                        'permissions'   => ['dma.friends.access_admin'],
                    ],
                    'rewards'   => [
                        'label'     => 'Rewards',
                        'icon'      => 'icon-money',
                        'url'       => Backend::url('dma/friends/rewards'),
                    ],
                    'activitylogs'   => [
                        'label'     => 'Activity Logs',
                        'icon'      => 'icon-rocket',
                        'url'       => Backend::url('dma/friends/activitylogs'),
                    ],
                    
                ]
            ]
        ];
    }

    public function registerComponents()
    {
        return [
            'DMA\Friends\Components\ActivityCodeForm'   => 'ActivityCodeForm',
            'DMA\Friends\Components\BadgeRecommend'     => 'BadgeRecommend',
            'DMA\Friends\Components\Modal'              => 'Modal',
            'DMA\Friends\Components\UserBadges'         => 'UserBadges',
        ];
    }

    /**
     * Register additional friends activity types
     */
    public function registerFriendsActivities()
    {
        return [
            'DMA\Friends\Activities\ActivityCode'   => 'ActivityCode',
            'DMA\Friends\Activities\LikeWorkOfArt'  => 'LikeWorkOfArt',
        ];
    }

    public function boot()
    {

        // Register ServiceProviders
        App::register('\EllipseSynergie\ApiResponse\Laravel\ResponseServiceProvider');
        App::register('DMA\Friends\FriendsServiceProvider');

        // Register Event Subscribers
        $subscriber = new FriendsEventHandler;
        Event::subscribe($subscriber);

        // Extend the user model to support our custom metadata        
        User::extend(function($model) {        
            $model->hasOne['metadata']          = ['DMA\Friends\Models\Usermeta'];     
            $model->hasMany['activityLogs']     = ['DMA\Friends\Models\ActivityLog'];      
            $model->belongsToMany['steps']      = ['DMA\Friends\Models\Step',       'table' => 'dma_friends_step_user',     'user_id', 'step_id'];     
            $model->belongsToMany['badges']     = ['DMA\Friends\Models\Badge',      'table' => 'dma_friends_badge_user',    'user_id', 'badge_id'];        
            $model->belongsToMany['groups']     = ['DMA\Friends\Models\UserGroup',  'table' => 'users_groups',              'user_id', 'group_id'];
            $model->belongsToMany['rewards']    = ['DMA\Friends\Models\Reward',     'table' => 'dma_friends_reward_user',   'user_id', 'reward_id'];       
        });
        
        Event::listen('backend.form.extendFields', function($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',
                ],  
                'metadata[last_name]' => [
                    'label' => 'Last Name',
                    'tab'   => 'Metadata',
                ], 
                'metadata[points]' => [
                    'label' => 'Points',
                    'tab'   => 'Metadata',
                ],
                'metadata[email_optin]' => [
                    'label' => 'Email Opt-in',
                    'type'  => 'checkbox',
                    'tab'   => 'Metadata',
                ],
                'metadata[current_member]' => [
                    'label' => 'Current member?',
                    'type'  => 'checkbox',
                    'tab'   => 'Metadata',
                ],
                'metadata[current_member_number]' => [
{'fraction_non_alphanumeric': 0.1393577296489918, 'fraction_numerical': 0.0008961911874533233, 'mean_word_length': 1.337814245810056, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 171, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3976619', 'n_tokens_mistral': 3656, 'n_tokens_neox': 3446, 'n_words': 600}