Trait luya\admin\aws\FlowActiveWindowTrait
Available since version | 1.0.0 |
---|---|
Source Code | https://github.com/luyadev/luya-module-admin/blob/master/src/aws/FlowActiveWindowTrait.php |
Helper Trait to enable FlowActiveWindowInterface functions by define the relation table informations.
use FlowActiveWindowTrait;
public function flowConfig()
{
return [
'table' => 'relation_table_name', // the table which contains the relation data between model/item and image.
'itemField' => 'group_id', // the field defined on where the window is attached
'imageField' => 'image_id', // the value of the image id can be stored in.
];
}
This trait allows you also to easy get all images from the storage system by using the flowGetImages()
method.
Public Methods
Method | Description | Defined By |
---|---|---|
flowConfig() | An array which defines the configuration for this flow uploader active window. | luya\admin\aws\FlowActiveWindowTrait |
flowDeleteImage() | This method will be called when the delete button will be triggered for an uploaded image. Now you should removed the corresponding reference item in your database table. The image objec deletion will be trigger by the active window. | luya\admin\aws\FlowActiveWindowTrait |
flowGetImages() | Get all images for the current item/model directly from the Storage Components findImages method. This helper method
allows you to easy foreach all images in your frontend implemenation and create the gallery collection. |
luya\admin\aws\FlowActiveWindowTrait |
flowListImages() | Get an array with all ids for the storage component. Only the image ids for the current model/item id should be returned: | luya\admin\aws\FlowActiveWindowTrait |
flowSaveImage() | This method will be called when the storage item is created, so you can perform the database save action by implementing this method. | luya\admin\aws\FlowActiveWindowTrait |
Protected Methods
Method | Description | Defined By |
---|---|---|
getConfigValue() | Get a specific value from the fowConfig() method. |
luya\admin\aws\FlowActiveWindowTrait |
Method Details
An array which defines the configuration for this flow uploader active window.
return [
'table' => 'relation_table_name', // the table which contains the relation data between model/item and image.
'itemField' => 'group_id', // the field defined on where the window is attached
'imageField' => 'image_id', // the value of the image id can be stored in.
];
public abstract void flowConfig ( ) |
abstract public function flowConfig();
This method will be called when the delete button will be triggered for an uploaded image. Now you should removed the corresponding reference item in your database table. The image objec deletion will be trigger by the active window.
public void flowDeleteImage ( luya\admin\image\Item $image ) | ||
$image | \admin\image\Item |
public function flowDeleteImage(Item $image)
{
Yii::$app->db->createCommand()->delete($this->getConfigValue('table'), [$this->getConfigValue('imageField') => $image->id])->execute();
}
Get all images for the current item/model directly from the Storage Components findImages
method. This helper method
allows you to easy foreach all images in your frontend implemenation and create the gallery collection.
public \admin\image\Iterator flowGetImages ( ) | ||
return | \admin\image\Iterator |
An iterator object with all images of the current modeL/item. |
---|
public function flowGetImages()
{
return Yii::$app->storage->findImages(['in', 'id', $this->flowListImages()]);
}
Get an array with all ids for the storage component. Only the image ids for the current model/item id should be returned:
return [1,2,3]; // where 1,2,3 are ids of the image from the storage component
public array flowListImages ( ) | ||
return | array |
An array where only the images are returned. |
---|
public function flowListImages()
{
return ArrayHelper::getColumn((new Query())->select([$this->getConfigValue('imageField')])->from($this->getConfigValue('table'))->where([$this->getConfigValue('itemField') => $this->id])->indexBy($this->getConfigValue('imageField'))->all(), $this->getConfigValue('imageField'));
}
This method will be called when the storage item is created, so you can perform the database save action by implementing this method.
public void flowSaveImage ( luya\admin\image\Item $image ) | ||
$image | \admin\image\Item |
The storage image item object which has been generated from active window. |
public function flowSaveImage(Item $image)
{
Yii::$app->db->createCommand()->insert($this->getConfigValue('table'), [
$this->getConfigValue('itemField') => $this->id,
$this->getConfigValue('imageField') => $image->id,
])->execute();
}
Get a specific value from the fowConfig()
method.
protected string getConfigValue ( $key ) | ||
$key | string |
The requested key from the config |
return | string |
The value for the $key |
---|---|---|
throws | yii\base\InvalidConfigException |
protected function getConfigValue($key)
{
if (!isset($this->flowConfig()[$key])) {
throw new InvalidConfigException("The flowConfig() method must return an array with a field named '$key'.");
}
return $this->flowConfig()[$key];
}