public function init()
{
+ foreach (['js', 'css'] as $type) {
+ foreach ($this->$type as &$file) {
+ $file = FileVersionService::versionFile($file);
+ }
+ }
+
$u = file_get_contents(__DIR__ . '/../inc/compress_timestamp.php');
if (preg_match('/=\s*(?P<stamp>\d+);/', $u, $matches)) {
array_unshift($this->css, '/min/css_' . $matches['stamp'] . '.css');
--- /dev/null
+<?php
+namespace app\assets;
+
+use Yii;
+
+class FileVersionService
+{
+ /**
+ * Генерирует версию файла на основе его содержимого.
+ *
+ * @param string $file Путь к файлу
+ * @return string Путь с версией
+ */
+ public static function versionFile(string $file): string
+ {
+ $hash = md5(file_get_contents(Yii::getAlias($file)));
+ return "$file?v=$hash";
+ }
+}
namespace yii_app\assets\timetable;
+use app\assets\FileVersionService;
use yii\web\AssetBundle;
class StartAsset extends AssetBundle
'css/timetable/start.css',
];
public $jsOptions = ['defer' => true];
+
+ public function init()
+ {
+ parent::init();
+
+ foreach (['js', 'css'] as $type) {
+ foreach ($this->$type as &$file) {
+ $file = FileVersionService::versionFile($file);
+ }
+ }
+ }
}
namespace yii_app\assets\timetable;
+use app\assets\FileVersionService;
use yii\web\AssetBundle;
class TimetableAsset extends AssetBundle
'/css/print.css',
];
public $jsOptions = ['defer' => true];
+
+ public function init()
+ {
+ parent::init();
+
+ foreach (['js', 'css'] as $type) {
+ foreach ($this->$type as &$file) {
+ $file = FileVersionService::versionFile($file);
+ }
+ }
+ }
}
namespace yii_app\forms\timetable;
+use yii_app\records\AdminStores;
use yii_app\records\TimetableFactModel;
use yii\base\Model;
use yii\db\ActiveQuery;
{
$stores = CityStore::find()
->select(['name', 'id'])
- ->andWhere(['id' => $_SESSION["store_arr_dostup"]])
+ ->andWhere(['id' => AdminStores::find()
+ ->andWhere(['admin_id' => \Yii::$app->user->id])
+ ->select('store_id')
+ ->column()])
->andWhere(['visible' => '1'])
->indexBy('id')
- ->cache(3600)
->column();
natsort($stores);
return $stores;