owner; $query = $owner->hasOne($this->model, $this->links); $conditions = $this->conditions; foreach($conditions as $condition) { $query->andWhere($condition); } return $query; } /** * All images query * * @return \yii\db\ActiveQuery */ public function getImages() { /** * @var ActiveRecord $owner */ $owner = $this->owner; $query = $owner->hasMany($this->model, $this->links); $conditions = $this->conditions; foreach($conditions as $left => $right) { $query->andWhere([$left => $right]); } return $query; } /** * Get images config array for FileInput * * @return array */ public function getImagesConfig() { $op = []; $images = $this->getImages()->all(); $config = $this->config; if(!isset( $config[ 'id' ] )) { return $op; } foreach($images as $image) { $op[] = [ 'caption' => ( isset( $config[ 'caption' ] ) ) ? $image->{$config[ 'caption' ]} : '', 'url' => ( isset( $config[ 'delete_action' ] ) ) ? Url::to([ $config[ 'delete_action' ], 'id' => $image->{$config[ 'id' ]}, ]) : '', 'key' => $image->{$config[ 'id' ]}, 'extra' => [ 'id' => $image->{$config[ 'id' ]}, ], ]; } return $op; } /** * Get images HTML * * @param string $preset * * @return array */ public function getImagesHTML($preset = 'admin_thumb') { $op = []; $images = $this->getImages()->all(); foreach($images as $image) { $op[] = ArtboxImageHelper::getImage($image->imageUrl, $preset); } return $op; } public function getImageUrl($dummy = true) { $image = $this->getImage()->one(); if(!empty($image)) { return $image->getImageUrl(); } elseif($dummy) { return '/storage/no-image.png'; } else { return NULL; } } }