Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set GalleryImage as child of \yii\db\ActiveRecord #76

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 42 additions & 12 deletions GalleryImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,60 @@

namespace zxbodya\yii2\galleryManager;

class GalleryImage
/**
* Class GalleryImage
* This is the model class for table "{{%gallery_image}}"
* We can change table name use $tableName property of GalleryBehavior
* @see \zxbodya\yii2\galleryManager\GalleryBehavior::$tableName.
*
* We can use this class in rules:
* public function rules()
* {
* return [
* [['mainPhoto'], 'exist', 'skipOnError' => true, 'targetClass' => get_class(Yii::createObject(GalleryImage::class, [
* $this->getBehavior('galleryBehavior')
* ])), 'targetAttribute' => ['mainPhoto' => 'id']],
* ];
* }
*
* @property int $id
* @property string $type
* @property string $ownerId
* @property int $rank
* @property string $name
* @property string $description
*
* @package zxbodya\yii2\galleryManager
*/
class GalleryImage extends \yii\db\ActiveRecord
{
public $name;
public $description;
public $id;
public $rank;
/**
* @var string table name of AR
*/
protected static $tableName;
/**
* @var GalleryBehavior
*/
protected $galleryBehavior;

/**
* @param GalleryBehavior $galleryBehavior
* @param array $props
* @param array $props
*/
function __construct(GalleryBehavior $galleryBehavior, array $props)
public function __construct(GalleryBehavior $galleryBehavior, array $props = [])
{

$this->galleryBehavior = $galleryBehavior;
self::$tableName = $galleryBehavior->tableName;

parent::__construct($props);
}

$this->name = isset($props['name']) ? $props['name'] : '';
$this->description = isset($props['description']) ? $props['description'] : '';
$this->id = isset($props['id']) ? $props['id'] : '';
$this->rank = isset($props['rank']) ? $props['rank'] : '';
/**
* {@inheritdoc}
*/
public static function tableName()
{
return static::$tableName;
}

/**
Expand Down