$data = $request->post();
$isNew = $model->isNewRecord;
-
+ Yii::warning('Request: ' . json_encode($data, JSON_UNESCAPED_UNICODE));
if ($isNew) {
$model->guid = DataHelper::createGuidMy('07');
$model->status = WriteOffsErp::STATUS_CREATED;
}
-
+ Yii::warning('Model: ' . json_encode($model, JSON_UNESCAPED_UNICODE));
if (isset($data['matrix_type_id'])) {
$model->matrix_type_id = (int) $data['matrix_type_id'];
}
if (!$model->load($data) || !$model->validate() || !$model->save()) {
throw new Exception('Ошибка при сохранении букета');
}
-
+ Yii::warning('Model 2: ' . json_encode($model, JSON_UNESCAPED_UNICODE));
$model->processRelations($data);
$transaction->commit();
Yii::$app->session->setFlash('success', 'Данные успешно сохранены');
private function renderView(BouquetComposition $model)
{
$files = $model->getFiles();
-
+ // usort($files['photo'], fn($a, $b) => strtotime($a->created_at) <=> strtotime($b->created_at));
+ Yii::warning('Order files' . json_encode($files['photo'], JSON_UNESCAPED_UNICODE));
+ Yii::warning('Order files url' . json_encode(array_map(fn($file) => Url::to([$file->url], true), $files['photo']), JSON_UNESCAPED_UNICODE));
return $this->render('view', [
'model' => $model,
'onlineStoresList' => BouquetForecast::getStoresList($model->id, BouquetForecast::ONLINE_STORES, CityStore::class, ['visible' => CityStore::IS_VISIBLE]),
public function getFiles(): array
{
return [
- 'photo' => Files::find()->where(['entity_id' => $this->id, 'file_type' => self::PHOTO_TYPE, 'entity' => self::PHOTO_BOUQUET])->all(),
- 'video' => Files::find()->where(['entity_id' => $this->id, 'file_type' => self::VIDEO_TYPE, 'entity' => self::VIDEO_PRESENTATION])->all(),
- 'process' => Files::find()->where(['entity_id' => $this->id, 'file_type' => self::VIDEO_TYPE, 'entity' => self::VIDEO_BUILD_PROCESS])->all(),
+ 'photo' => Files::find()
+ ->where(['entity_id' => $this->id, 'file_type' => self::PHOTO_TYPE, 'entity' => self::PHOTO_BOUQUET])
+ ->orderBy(['created_at' => SORT_ASC])
+ ->all(),
+ 'video' => Files::find()
+ ->where(['entity_id' => $this->id, 'file_type' => self::VIDEO_TYPE, 'entity' => self::VIDEO_PRESENTATION])
+ ->all(),
+ 'process' => Files::find()
+ ->where(['entity_id' => $this->id, 'file_type' => self::VIDEO_TYPE, 'entity' => self::VIDEO_BUILD_PROCESS])
+ ->all(),
];
}
mkdir($filePath, 0777, true);
}
$targetFile = $uploads . $target_dir. "/" . $file->baseName . '.' . $file->extension;
+ Yii::warning('Saved file: ' . json_encode($targetFile, JSON_UNESCAPED_UNICODE));
$file->saveAs($targetFile);
$type = 'image';
}
$fileRecord = new Files;
- $fileRecord->created_at = date("Y-m-d H:i:s");
+ $fileRecord->created_at = date("Y-m-d H:i:s", time() + 1);
$fileRecord->entity_id = $entity_id;
$fileRecord->entity = $entity;
$fileRecord->file_type = $type;