diff --git a/src/components/imaging/filters/Thumbnail.php b/src/components/imaging/filters/Thumbnail.php index 82470994..5dc0bef8 100644 --- a/src/components/imaging/filters/Thumbnail.php +++ b/src/components/imaging/filters/Thumbnail.php @@ -11,9 +11,8 @@ namespace skeeks\cms\components\imaging\filters; -use yii\base\Component; -use skeeks\imagine\Image; use Imagine\Image\ManipulatorInterface; +use skeeks\imagine\Image; use yii\base\Exception; /** @@ -28,6 +27,12 @@ class Thumbnail extends \skeeks\cms\components\imaging\Filter * @var int Качество сохраняемого фото */ public $q; + + /** + * @var int Если не задана ширина или высота, то проверять оригинальный размер файла и новый файл не будет крупнее + */ + public $s = 1; + public $m = ManipulatorInterface::THUMBNAIL_INSET; public function init() @@ -38,12 +43,12 @@ public function init() throw new Exception("Необходимо указать ширину или высоту"); } - $q = (int) $this->q; + $q = (int)$this->q; if (!$q) { - $this->q = (int) \Yii::$app->seo->img_preview_quality; + $this->q = (int)\Yii::$app->seo->img_preview_quality; } - $q = (int) $this->q; + $q = (int)$this->q; if ($q < 10) { $this->q = 10; @@ -61,30 +66,49 @@ protected function _save() $this->m = ManipulatorInterface::THUMBNAIL_INSET; }*/ if (!$this->w) { + //Если ширина не указана нужно ее расчитать $size = Image::getImagine()->open($this->_originalRootFilePath)->getSize(); + + //Если размер оригинальной кратинки больше, то уменьшаем его + if ($this->s == 1) { + if ($this->h > $size->getHeight()) { + $this->h = $size->getHeight(); + } + } + + $width = ($size->getWidth() * $this->h) / $size->getHeight(); Image::thumbnailV2($this->_originalRootFilePath, (int)round($width), $this->h, $this->m)->save($this->_newRootFilePath, [ - 'jpeg_quality' => $this->q, - 'webp_quality' => $this->q, - ]); + 'jpeg_quality' => $this->q, + 'webp_quality' => $this->q, + ]); } else { if (!$this->h) { $size = Image::getImagine()->open($this->_originalRootFilePath)->getSize(); + + //Если размер оригинальной кратинки больше, то уменьшаем его + if ($this->s == 1) { + if ($this->w > $size->getWidth()) { + $this->w = $size->getWidth(); + } + } + + $height = ($size->getHeight() * $this->w) / $size->getWidth(); Image::thumbnailV2($this->_originalRootFilePath, $this->w, (int)round($height), $this->m)->save($this->_newRootFilePath, [ - 'jpeg_quality' => $this->q, - 'webp_quality' => $this->q, - ]); + 'jpeg_quality' => $this->q, + 'webp_quality' => $this->q, + ]); } else { $image = Image::thumbnailV2($this->_originalRootFilePath, $this->w, $this->h, $this->m)->save($this->_newRootFilePath, [ - 'jpeg_quality' => $this->q, - 'webp_quality' => $this->q, - ]); + 'jpeg_quality' => $this->q, + 'webp_quality' => $this->q, + ]); } } } diff --git a/src/models/CmsContentProperty.php b/src/models/CmsContentProperty.php index 04d50675..ea49c5e9 100644 --- a/src/models/CmsContentProperty.php +++ b/src/models/CmsContentProperty.php @@ -9,6 +9,7 @@ namespace skeeks\cms\models; +use skeeks\cms\query\CmsContentPropertyActiveQuery; use skeeks\cms\relatedProperties\models\RelatedPropertyModel; use Yii; use yii\helpers\ArrayHelper; @@ -228,4 +229,12 @@ public function asText() return parent::asText(); return $result." ($this->code)"; } + + /** + * @return CmsContentPropertyActiveQuery + */ + public static function find() + { + return (new CmsContentPropertyActiveQuery(get_called_class())); + } } \ No newline at end of file diff --git a/src/models/behaviors/HasStorageFileMulti.php b/src/models/behaviors/HasStorageFileMulti.php index 28f36543..69ef59d0 100644 --- a/src/models/behaviors/HasStorageFileMulti.php +++ b/src/models/behaviors/HasStorageFileMulti.php @@ -191,7 +191,24 @@ public function saveStorgaFile($e) } catch (\Exception $e) { } } else { + + //Если файл не существует, то будет удален + if (!$storageFile = CmsStorageFile::findOne($fileId)) { + continue; + } + + //Если файл еще не был привязан, то нужно привязать + if (!in_array($fileId, $oldIds)) { + if ($this->owner->isNewRecord) { + $this->_linkFiles[$relation][] = $storageFile; + } else { + $this->owner->link($relation, $storageFile); + } + } + + //Файл попадает в перечень файлов $files[] = $fileId; + //Удаляется ID из претендентов на удаление ArrayHelper::remove($oldIds, $fileId); } } diff --git a/src/query/CmsContentElementActiveQuery.php b/src/query/CmsContentElementActiveQuery.php index 2aad4ae9..7cfc181a 100644 --- a/src/query/CmsContentElementActiveQuery.php +++ b/src/query/CmsContentElementActiveQuery.php @@ -19,6 +19,14 @@ class CmsContentElementActiveQuery extends CmsActiveQuery { + /** + * @param mixed $id + * @return CmsTreeActiveQuery + */ + public function sxId(mixed $id) + { + return $this->andWhere(['sx_id' => $id]); + } /** * Фильтрация по дате публикации diff --git a/src/query/CmsContentPropertyActiveQuery.php b/src/query/CmsContentPropertyActiveQuery.php new file mode 100644 index 00000000..40f0706e --- /dev/null +++ b/src/query/CmsContentPropertyActiveQuery.php @@ -0,0 +1,24 @@ + + */ + +namespace skeeks\cms\query; + +/** + * @author Semenov Alexander + */ +class CmsContentPropertyActiveQuery extends CmsActiveQuery +{ + /** + * @param mixed $id + * @return CmsContentPropertyActiveQuery + */ + public function sxId(mixed $id) + { + return $this->andWhere(['sx_id' => $id]); + } +} \ No newline at end of file diff --git a/src/query/CmsTreeActiveQuery.php b/src/query/CmsTreeActiveQuery.php index 023a78a3..51b193b7 100644 --- a/src/query/CmsTreeActiveQuery.php +++ b/src/query/CmsTreeActiveQuery.php @@ -18,6 +18,7 @@ */ class CmsTreeActiveQuery extends CmsActiveQuery { + public $is_active = false; /** * @param mixed $id * @return CmsTreeActiveQuery