/** * @inheritdoc */ public function behaviors() { return ['timestamp' => TimestampBehavior::className(), 'sluggable' => ['class' => SluggableBehavior::className(), 'attribute' => 'name'], 'tree' => ['class' => NestedSetsBehavior::className(), 'treeAttribute' => 'tree'], 'files' => ['class' => FilesBehavior::className(), 'attributes' => ['uploadedImage' => ['filesystem' => 'local', 'path' => '/categories', 'fileName' => '{model.slug}.{file.extension}', 'relation' => 'image', 'deleteOnUnlink' => true, 'on beforeSave' => function (FileInterface $file) { $image = ImageManagerStatic::make($file->getPath()); $image->resize(400, null, function (Constraint $constraint) { $constraint->aspectRatio(); $constraint->upsize(); }); $image->save($file->getPath(), 100); }]]], 'relations' => ['class' => RelationsBehavior::className(), 'settings' => ['image' => ['deleteOnUnlink' => true]], 'relations' => ['imageRelation' => $this->hasOne(CategoryFile::className(), ['id' => 'image_id'])]]]; }
/** * @inheritdoc */ public function behaviors() { return ['sluggable' => ['class' => SluggableBehavior::className(), 'attribute' => 'title', 'ensureUnique' => true], 'timestamp' => TimestampBehavior::className(), 'files' => ['class' => FilesBehavior::className(), 'attributes' => ['uploadedImages' => ['filesystem' => 'local', 'path' => '/products/{model.id}', 'fileName' => '{model.slug}.{file.extension}', 'multiple' => true, 'relation' => 'images', 'on beforeSave' => function (FileInterface $file) { $image = ImageManagerStatic::make($file->getPath()); $image->resize(1000, null, function (Constraint $constraint) { $constraint->aspectRatio(); $constraint->upsize(); }); $image->save($file->getPath(), 100); }, 'on afterDeleteAll' => function (StorageConfig $config, FilesystemComponent $filesystemComponent) { $path = $config->resolvePath($this); $filesystemComponent->deleteDirectory($path, $config->filesystem); }]]], 'relations' => ['class' => RelationsBehavior::className(), 'settings' => ['relatedEAttributes' => ['deleteOnUnlink' => true], 'images' => ['deleteOnUnlink' => true, 'extraColumns' => ['attribute' => 'images']]], 'relations' => ['imagesRelation' => $this->hasMany(ProductFile::className(), ['product_id' => 'id'])->where(['attribute' => 'images'])]]]; }
/** * @inheritdoc */ public function behaviors() { return ['tree' => ['class' => NestedSetsBehavior::className(), 'treeAttribute' => 'tree'], 'files' => ['class' => FilesBehavior::className(), 'attributes' => ['uploadedIcon' => ['filesystem' => 'local', 'path' => '/menus', 'fileName' => function ($fileName, MenuItem $model) { return Inflector::slug($model->label) . '.' . pathinfo($fileName, PATHINFO_EXTENSION); }, 'relation' => 'icon', 'deleteOnUnlink' => true, 'on beforeSave' => function (FileInterface $file) { $image = ImageManagerStatic::make($file->getPath()); $image->resize(100, null, function (Constraint $constraint) { $constraint->aspectRatio(); $constraint->upsize(); }); $image->save($file->getPath(), 100); }], 'uploadedActiveIcon' => ['filesystem' => 'local', 'path' => '/menus', 'fileName' => function ($fileName, MenuItem $model) { return Inflector::slug($model->label) . '-active.' . pathinfo($fileName, PATHINFO_EXTENSION); }, 'relation' => 'activeIcon', 'deleteOnUnlink' => true, 'on beforeSave' => function (FileInterface $file) { $image = ImageManagerStatic::make($file->getPath()); $image->resize(100, null, function (Constraint $constraint) { $constraint->aspectRatio(); $constraint->upsize(); }); $image->save($file->getPath(), 100); }], 'uploadedVideo' => ['filesystem' => 'local', 'path' => '/menus', 'fileName' => function ($fileName, MenuItem $model) { return Inflector::slug($model->label) . '.' . pathinfo($fileName, PATHINFO_EXTENSION); }, 'relation' => 'video', 'deleteOnUnlink' => true]]], 'relations' => ['class' => RelationsBehavior::className(), 'settings' => ['icon' => ['deleteOnUnlink' => true], 'activeIcon' => ['deleteOnUnlink' => true], 'video' => ['deleteOnUnlink' => true]], 'relations' => ['iconRelation' => $this->hasOne(MenuItemFile::className(), ['id' => 'icon_id']), 'activeIconRelation' => $this->hasOne(MenuItemFile::className(), ['id' => 'active_icon_id']), 'videoRelation' => $this->hasOne(MenuItemFile::className(), ['id' => 'video_id'])]]]; }