|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace carono\exchange1c; |
|
4
|
|
|
|
|
5
|
|
|
use carono\exchange1c\helpers\ModuleHelper; |
|
6
|
|
|
use yii\helpers\FileHelper; |
|
7
|
|
|
use yii\helpers\Inflector; |
|
8
|
|
|
use yii\web\IdentityInterface; |
|
9
|
|
|
use Yii; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* exchange module definition class |
|
13
|
|
|
*/ |
|
14
|
|
|
class ExchangeModule extends \yii\base\Module |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @inheritdoc |
|
18
|
|
|
*/ |
|
19
|
|
|
public $controllerNamespace = 'carono\exchange1c\controllers'; |
|
20
|
|
|
/** |
|
21
|
|
|
* @var \carono\exchange1c\interfaces\ProductInterface |
|
22
|
|
|
*/ |
|
23
|
|
|
public $productClass; |
|
24
|
|
|
/** |
|
25
|
|
|
* @var \carono\exchange1c\interfaces\OfferInterface |
|
26
|
|
|
*/ |
|
27
|
|
|
public $offerClass; |
|
28
|
|
|
/** |
|
29
|
|
|
* @var \carono\exchange1c\interfaces\DocumentInterface |
|
30
|
|
|
*/ |
|
31
|
|
|
public $documentClass; |
|
32
|
|
|
/** |
|
33
|
|
|
* @var \carono\exchange1c\interfaces\GroupInterface |
|
34
|
|
|
*/ |
|
35
|
|
|
public $groupClass; |
|
36
|
|
|
/** |
|
37
|
|
|
* @var \carono\exchange1c\interfaces\PartnerInterface |
|
38
|
|
|
*/ |
|
39
|
|
|
public $partnerClass; |
|
40
|
|
|
/** |
|
41
|
|
|
* @var \carono\exchange1c\interfaces\WarehouseInterface |
|
42
|
|
|
*/ |
|
43
|
|
|
public $warehouseClass; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Обмен документами |
|
47
|
|
|
* |
|
48
|
|
|
* @var bool |
|
49
|
|
|
*/ |
|
50
|
|
|
public $exchangeDocuments = false; |
|
51
|
|
|
/** |
|
52
|
|
|
* Режим отладки - сохраняем xml файлы в runtime |
|
53
|
|
|
* |
|
54
|
|
|
* @var bool |
|
55
|
|
|
*/ |
|
56
|
|
|
public $debug = false; |
|
57
|
|
|
/** |
|
58
|
|
|
* При обмене используем архиватор, если расширения нет, то зачение не учитывается |
|
59
|
|
|
* |
|
60
|
|
|
* @var bool |
|
61
|
|
|
*/ |
|
62
|
|
|
public $useZip = true; |
|
63
|
|
|
public $tmpDir = '@runtime/1c_exchange'; |
|
64
|
|
|
/** |
|
65
|
|
|
* При сохранении товара, используем валидацию или нет |
|
66
|
|
|
* |
|
67
|
|
|
* @var bool |
|
68
|
|
|
*/ |
|
69
|
|
|
public $validateModelOnSave = false; |
|
70
|
|
|
public $timeLimit = 1800; |
|
71
|
|
|
public $memoryLimit = null; |
|
72
|
|
|
public $bootstrapUrlRule = true; |
|
73
|
|
|
public $redactorModuleName = 'carono-exchange-redactor'; |
|
74
|
|
|
public $auth; |
|
75
|
|
|
|
|
76
|
|
|
private function loadRedactorModule() |
|
77
|
|
|
{ |
|
78
|
|
|
$redactorClass = 'yii\redactor\widgets\Redactor'; |
|
79
|
|
|
$moduleRedactorName = $this->redactorModuleName; |
|
80
|
|
|
if (class_exists($redactorClass) && !Yii::$app->getModule($moduleRedactorName)) { |
|
81
|
|
|
$routeName = Inflector::camel2id($moduleRedactorName); |
|
82
|
|
|
\Yii::$app->setModule($moduleRedactorName, [ |
|
83
|
|
|
'class' => 'yii\redactor\RedactorModule', |
|
84
|
|
|
'uploadDir' => '@vendor/carono/yii2-1c-exchange/files/articles', |
|
85
|
|
|
'imageUploadRoute' => ["/$routeName/upload/image"], |
|
86
|
|
|
'fileUploadRoute' => ["/$routeName/upload/file"], |
|
87
|
|
|
'imageManagerJsonRoute' => ["/$routeName/upload/image-json"], |
|
88
|
|
|
'fileManagerJsonRoute' => ["/$routeName/upload/file-json"], |
|
89
|
|
|
'imageAllowExtensions' => ['jpg', 'png', 'gif'], |
|
90
|
|
|
'on beforeAction' => function () use ($moduleRedactorName) { |
|
91
|
|
|
$path = ModuleHelper::getModuleNameByClass(self::class, 'exchange'); |
|
92
|
|
|
$redactor = \Yii::$app->getModule($moduleRedactorName); |
|
93
|
|
|
$redactor->uploadUrl = "/$path/file/article?file="; |
|
94
|
|
|
\Yii::$app->setModule($moduleRedactorName, $redactor); |
|
95
|
|
|
} |
|
96
|
|
|
]); |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* @return null|\yii\base\Module |
|
102
|
|
|
*/ |
|
103
|
|
|
public function getRedactor() |
|
104
|
|
|
{ |
|
105
|
|
|
return Yii::$app->getModule($this->redactorModuleName); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* @inheritdoc |
|
110
|
|
|
*/ |
|
111
|
|
|
public function init() |
|
112
|
|
|
{ |
|
113
|
|
|
if (!isset(\Yii::$app->i18n->translations['models'])) { |
|
114
|
|
|
\Yii::$app->i18n->translations['models'] = [ |
|
115
|
|
|
'class' => 'yii\i18n\PhpMessageSource', |
|
116
|
|
|
'basePath' => '@app/messages', |
|
117
|
|
|
'sourceLanguage' => 'en', |
|
118
|
|
|
]; |
|
119
|
|
|
} |
|
120
|
|
|
$this->loadRedactorModule(); |
|
121
|
|
|
parent::init(); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
public function getTmpDir($part = null) |
|
125
|
|
|
{ |
|
126
|
|
|
$dir = \Yii::getAlias($this->tmpDir); |
|
127
|
|
|
if (!is_dir($dir)) { |
|
128
|
|
|
FileHelper::createDirectory($dir, 0777, true); |
|
129
|
|
|
} |
|
130
|
|
|
return $dir . ($part ? DIRECTORY_SEPARATOR . trim($part, '/\\') : ''); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* @param $login |
|
135
|
|
|
* @param $password |
|
136
|
|
|
* @return null|IdentityInterface |
|
137
|
|
|
*/ |
|
138
|
|
|
public function auth($login, $password) |
|
139
|
|
|
{ |
|
140
|
|
|
/** |
|
141
|
|
|
* @var $class \yii\web\IdentityInterface |
|
142
|
|
|
* @var IdentityInterface $user |
|
143
|
|
|
*/ |
|
144
|
|
|
$class = \Yii::$app->user->identityClass; |
|
145
|
|
|
if (method_exists($class, 'findByUsername')) { |
|
146
|
|
|
$user = $class::findByUsername($login); |
|
147
|
|
|
if ($user && method_exists($user, 'validatePassword') && $user->validatePassword($password)) { |
|
148
|
|
|
return $user; |
|
149
|
|
|
} |
|
150
|
|
|
} |
|
151
|
|
|
return null; |
|
152
|
|
|
} |
|
153
|
|
|
} |