1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace carono\exchange1c; |
4
|
|
|
|
5
|
|
|
use yii\helpers\FileHelper; |
6
|
|
|
use yii\web\IdentityInterface; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* exchange module definition class |
10
|
|
|
*/ |
11
|
|
|
class ExchangeModule extends \yii\base\Module |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @inheritdoc |
15
|
|
|
*/ |
16
|
|
|
public $controllerNamespace = 'carono\exchange1c\controllers'; |
17
|
|
|
/** |
18
|
|
|
* @var \carono\exchange1c\interfaces\ProductInterface |
19
|
|
|
*/ |
20
|
|
|
public $productClass; |
21
|
|
|
/** |
22
|
|
|
* @var \carono\exchange1c\interfaces\OfferInterface |
23
|
|
|
*/ |
24
|
|
|
public $offerClass; |
25
|
|
|
/** |
26
|
|
|
* @var \carono\exchange1c\interfaces\DocumentInterface |
27
|
|
|
*/ |
28
|
|
|
public $documentClass; |
29
|
|
|
/** |
30
|
|
|
* @var \carono\exchange1c\interfaces\GroupInterface |
31
|
|
|
*/ |
32
|
|
|
public $groupClass; |
33
|
|
|
/** |
34
|
|
|
* @var \carono\exchange1c\interfaces\PartnerInterface |
35
|
|
|
*/ |
36
|
|
|
public $partnerClass; |
37
|
|
|
/** |
38
|
|
|
* @var \carono\exchange1c\interfaces\WarehouseInterface |
39
|
|
|
*/ |
40
|
|
|
public $warehouseClass; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Обмен документами |
44
|
|
|
* |
45
|
|
|
* @var bool |
46
|
|
|
*/ |
47
|
|
|
public $exchangeDocuments = false; |
48
|
|
|
/** |
49
|
|
|
* Режим отладки - сохраняем xml файлы в runtime |
50
|
|
|
* |
51
|
|
|
* @var bool |
52
|
|
|
*/ |
53
|
|
|
public $debug = false; |
54
|
|
|
/** |
55
|
|
|
* При обмене используем архиватор, если расширения нет, то зачение не учитывается |
56
|
|
|
* |
57
|
|
|
* @var bool |
58
|
|
|
*/ |
59
|
|
|
public $useZip = true; |
60
|
|
|
public $tmpDir = '@runtime/1c_exchange'; |
61
|
|
|
/** |
62
|
|
|
* При сохранении товара, используем валидацию или нет |
63
|
|
|
* |
64
|
|
|
* @var bool |
65
|
|
|
*/ |
66
|
|
|
public $validateModelOnSave = false; |
67
|
|
|
public $timeLimit = 1800; |
68
|
|
|
public $memoryLimit = null; |
69
|
|
|
public $bootstrapUrlRule = true; |
70
|
|
|
public $auth; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @inheritdoc |
74
|
|
|
*/ |
75
|
|
|
public function init() |
76
|
|
|
{ |
77
|
|
|
if (!isset(\Yii::$app->i18n->translations['models'])) { |
78
|
|
|
\Yii::$app->i18n->translations['models'] = [ |
79
|
|
|
'class' => 'yii\i18n\PhpMessageSource', |
80
|
|
|
'basePath' => '@app/messages', |
81
|
|
|
'sourceLanguage' => 'en', |
82
|
|
|
]; |
83
|
|
|
} |
84
|
|
|
parent::init(); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function getTmpDir($part = null) |
88
|
|
|
{ |
89
|
|
|
$dir = \Yii::getAlias($this->tmpDir); |
90
|
|
|
if (!is_dir($dir)) { |
91
|
|
|
FileHelper::createDirectory($dir, 0777, true); |
92
|
|
|
} |
93
|
|
|
return $dir . ($part ? DIRECTORY_SEPARATOR . trim($part, '/\\') : ''); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @param $login |
98
|
|
|
* @param $password |
99
|
|
|
* @return null|IdentityInterface |
100
|
|
|
*/ |
101
|
|
|
public function auth($login, $password) |
102
|
|
|
{ |
103
|
|
|
/** |
104
|
|
|
* @var $class \yii\web\IdentityInterface |
105
|
|
|
* @var IdentityInterface $user |
106
|
|
|
*/ |
107
|
|
|
$class = \Yii::$app->user->identityClass; |
108
|
|
|
if (!method_exists($class, 'findByUsername')) { |
109
|
|
|
return null; |
110
|
|
|
} |
111
|
|
|
$user = $class::findByUsername($login); |
112
|
|
|
if ($user && method_exists($user, 'validatePassword') && $user->validatePassword($password)) { |
113
|
|
|
return $user; |
114
|
|
|
} else { |
115
|
|
|
return null; |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|