Skip to content

Commit

Permalink
tableName option is now public and editable
Browse files Browse the repository at this point in the history
  • Loading branch information
jirisvoboda committed Jun 13, 2016
1 parent 41ca264 commit 00efe05
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions GalleryBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ class GalleryBehavior extends Behavior {
*/
public $saveOptions = ['quality' => 100];

/**
* Table name of Gallery
* @var string
*/
public $tableName = 'app_gallery_image';

/**
* @var array images
*/
Expand All @@ -151,12 +157,6 @@ class GalleryBehavior extends Behavior {
*/
protected $_galleryId;

/**
* Table name of Gallery
* @var string
*/
protected $_galleryTable = 'app_gallery_image';

/**
* @inheritdoc
*/
Expand Down Expand Up @@ -219,7 +219,7 @@ public function getImages($sort = SORT_ASC)

$imagesData = $query
->select(['id', 'name', 'description', 'rank'])
->from($this->_galleryTable)
->from($this->tableName)
->where(['type' => $this->type, 'owner_id' => $this->getGalleryId()])
->orderBy(['rank' => $sort])
->all();
Expand Down Expand Up @@ -336,7 +336,7 @@ public function deleteImage($image_id)

$db = \Yii::$app->db;
$db->createCommand()
->delete($this->_galleryTable, ['id' => $image_id])
->delete($this->tableName, ['id' => $image_id])
->execute();
}

Expand Down Expand Up @@ -389,7 +389,7 @@ public function addImage($fileName, $attrs = [])
$db = \Yii::$app->db;

$db->createCommand()
->insert($this->_galleryTable, \yii\helpers\ArrayHelper::merge($attrs, [
->insert($this->tableName, \yii\helpers\ArrayHelper::merge($attrs, [
'type' => $this->type,
'owner_id' => $this->getGalleryId()
]))
Expand All @@ -398,7 +398,7 @@ public function addImage($fileName, $attrs = [])
$id = $db->getLastInsertID();

$db->createCommand()
->update($this->_galleryTable, ['rank' => $id], ['id' => $id])
->update($this->tableName, ['rank' => $id], ['id' => $id])
->execute();

$this->replaceImage($id, $fileName);
Expand Down Expand Up @@ -445,7 +445,7 @@ public function arrange($order, $sort = SORT_ASC)
foreach ($order as $k => $v)
{
\Yii::$app->db->createCommand()
->update($this->_galleryTable, ['rank' => $orders[$i]], ['id' => $k])
->update($this->tableName, ['rank' => $orders[$i]], ['id' => $k])
->execute();

$i++;
Expand Down Expand Up @@ -481,7 +481,7 @@ public function updateImagesData($imagesData)
{
$rawImages = (new Query())
->select(['id', 'name', 'description', 'rank'])
->from($this->_galleryTable)
->from($this->tableName)
->where(['type' => $this->type, 'owner_id' => $this->getGalleryId()])
->andWhere(['in', 'id', $imageIds])
->orderBy(['rank' => 'asc'])
Expand All @@ -505,7 +505,7 @@ public function updateImagesData($imagesData)
$image->description = $imagesData[$image->id]['description'];
}
\Yii::$app->db->createCommand()
->update($this->_galleryTable, [
->update($this->tableName, [
'name' => $image->name,
'description' => $image->description
], [
Expand Down

0 comments on commit 00efe05

Please sign in to comment.