<?php

$params = require(__DIR__ . '/params.php');

require (__DIR__."/../lib/docxGenerator.php");


$config = [
    'id' => 'basic',
    'name'  =>  'НРЦ',
    'basePath' => dirname(__DIR__),
    'bootstrap' => ['debug'], // debug
    'charset'   =>  'utf-8',
    'language'  =>  'uk',
    'sourceLanguage' => 'en',
    'timeZone' => 'Europe/Kiev',
    // 'on beforeAction' => function($event){
    //     if(Yii::$app->controller->action->id != 'maintenance'){
    //         return Yii::$app->controller->redirect(['/site/maintenance']);
    //     }
    // },
    'aliases' => [ 
        '@bower' => '@vendor/bower-asset',   // путь к bower-пакетам
        '@npm'   => '@vendor/npm-asset',     // путь к npm-пакетам
        '@webroot' => dirname(__DIR__) . '/web', // корень веб
        '@web' => '',
    ],
    'components' => [
        'templater' => [
            'class' => 'app\components\Templater',            
        ],
        'num2text' => [
            'class' => 'app\components\NumberToText',            
        ],
        'image' => array(
            'class' => 'yii\image\ImageDriver',
            'driver' => 'GD',  //GD or Imagick
        ),
        'view' => [
            'theme' => [
                'pathMap' => [
                    '@dektrium/user/views' => '@app/views/user'
                ],
            ],
        ],
        'request' => [
            'cookieValidationKey' => '2Q3pzGXlQIxOPm1TyemO0YlVF1ylwRSmZz',
            'baseUrl'   =>  '',
            'parsers' => ['application/json' => 'yii\web\JsonParser',], // for rest api
        ],
        'formatter' => [
            'dateFormat' => 'dd.MM.Y',
            'datetimeFormat' => 'php:d.m.Y H:i:s',
            'timeFormat' => 'H:i:s',
            'locale' => 'uk',
            'defaultTimeZone' => 'Europe/Kiev',
        ],
        'cache' => [
            'class' => 'yii\caching\FileCache',
        ],
        'user' => [
            'identityClass' => 'app\models\User',
        ],
        'errorHandler' => [
            'errorAction' => 'site/error',
        ],
        'authManager' => [
            'class' => 'dektrium\rbac\components\DbManager',
        ],
        'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            'useFileTransport' => false,
            'viewPath' => '@app/mailer',
            'transport' => [
                'class' => 'Swift_SmtpTransport',
                'host' => getenv('SMTP_HOST'),
                'username' => getenv('SMTP_USER'),
                'password' => getenv('SMTP_PASS'),
                'port' => getenv('SMTP_PORT'),
                'encryption' => getenv('SMTP_ENC'),
            ],
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
        'i18n' => [
            'translations' => [
                'app' => [
                    'class' => 'yii\i18n\PhpMessageSource',
                    'basePath' => '@app/messages',
                    'fileMap' => [
                        'app' => 'app.php',
                        'app/error' => 'error.php',
                    ]
                ],
                'user' => [
                    'class' => 'yii\i18n\PhpMessageSource',
                    'basePath' => '@app/messages',
                    'fileMap' => [
                        'user' => 'user.php',
                    ]
                ],
            ],
        ],
        'db' => require(__DIR__ . '/db.php'),
        'urlManager' => [
            'showScriptName' => false,
            //'enableStrictParsing' => true, // rest api dont work
            'enablePrettyUrl' => true,
            'rules' => [
                ['class' => 'yii\rest\UrlRule',
                    'controller' => ['auction','publish','trade','notification'],
                    'pluralize' => false,
                    'except' => ['delete']
                ],// for rest api
                'public/view/<id>' => 'public/view',
               '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
                '<alias:register>' => 'user/registration/<alias>',
                '<alias:logout|login>' => 'user/security/<alias>',
                '/news/<name:[\w]+>' => '/site/view',
                '/product/<slug:[\w-]+>' => '/products/view',
                '/dopomoga/category/<slug:[\w-]+>' => '/dopomoga/category',
                //'/category/<slug:[\w-]+>' => '/categoriesblog/category',
                //'/blog/<slug:[\w-]+>' => '/categoriesblog/category',
                // '/page/<slug:[\w-]+>' => '/categoriesblog/page',
            ]
        ],
        'assetManager'  =>  [
            'basePath'  =>  '@webroot/assets',
            'baseUrl'   =>  '@web/assets',
            'bundles' => [
                'kartik\file\FileInputAsset' => [
                    'sourcePath' => '@webroot/replaces/fileinput',
                ]
            ]
        ]
    ],
    'controllerMap' => [
        'elfinder' => [
            'class' => 'mihaildev\elfinder\Controller',
            'access' => ['@'], //глобальный доступ к фаил менеджеру @ - для авторизорованных , ? - для гостей , чтоб открыть всем ['@', '?']
            'disabledCommands' => ['netmount'], //отключение ненужных команд https://github.com/Studio-42/elFinder/wiki/Client-configuration-options#commands
            'roots' => [
                [
                    'baseUrl'=>'@web',
                    'basePath'=>'@webroot',
                    'path' => 'uploads/global',
                    'name' => 'Global'
                ],
                [
                    'class' => 'mihaildev\elfinder\volume\UserPath',
                    'path'  => 'uploads/user_{id}',
                    'name'  => 'My Documents'
                ],

            ],
        ]
    ],
    'modules' => [
        'user' => [
            'class' => 'dektrium\user\Module',
            // 'enableUnconfirmedLogin' => true,
            'mailer' => [
                'class' => 'app\components\DektriumMailer',
                'viewPath' => '@app/views/user/mail',
            ],
            'confirmWithin' => 21600,
            'cost' => 12,
            'admins' => ['neiron'],
            'modelMap' => [
                'RegistrationForm' => 'app\models\RegistrationForm',
                'User' => 'app\models\User',
                'UserSearch' => 'app\models\UsersSearch',
                'LoginForm' => 'app\models\LoginForm',
                'Profile' => 'app\models\Profile',
            ],
            'controllerMap' => [
                'registration' => 'app\models\RegistrationController',
                'settings' => 'app\controllers\SettingsController',
                //'security' => 'app\controllers\SecurityController',
                'admin' => 'app\controllers\AdminController',
            ],
        ],
        'rbac' => [
            'class' => 'dektrium\rbac\RbacWebModule',
        ],
        'redactor' => [
            'class' => 'yii\redactor\RedactorModule',
            'uploadDir' => '@webroot/uploadfolder',
            'uploadUrl' => '@web/uploadfolder',
            'imageAllowExtensions'=>['jpg','png','gif']
        ],
        // 'debug' => [
        //    'class' => 'yii\debug\Module',
        // ],
    ],
    'params' => $params,
];

if (YII_ENV_DEV) {
    // configuration adjustments for 'dev' environment
    $config['bootstrap'][] = 'debug';
    $config['modules']['debug'] = [
        'class' => 'yii\debug\Module',
    ];
    // $config['modules']['debug']['allowedIPs'] = ['93.78.238.18','192.168.2.5','127.0.0.1','10.0.0.1','192.168.2.207', '::1', '93.78.206.*'];

    $config['bootstrap'][] = 'gii';
    //$config['modules']['gii'] = 'yii\gii\Module';
    //$config['modules']['gii'] = ['class' => 'yii\gii\Module'];
    $config['modules']['gii'] = [
        'class' => 'yii\gii\Module',
        // 'allowedIPs' => ['93.78.238.18','127.0.0.1','10.0.0.1','192.168.2.207', '::1', '93.78.206.*'],
    ];
}

return $config;
