From 11acd6e799983196a2573f0e95ebc10703040a70 Mon Sep 17 00:00:00 2001 From: flynsarmy Date: Fri, 22 Aug 2014 14:38:53 +1000 Subject: [PATCH 1/2] Refs #485, #504 - Add support for nested columns. --- modules/backend/formwidgets/FileUpload.php | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/modules/backend/formwidgets/FileUpload.php b/modules/backend/formwidgets/FileUpload.php index e2cac70cd..125246f46 100644 --- a/modules/backend/formwidgets/FileUpload.php +++ b/modules/backend/formwidgets/FileUpload.php @@ -1,5 +1,6 @@ vars['imageWidth'] = $this->imageWidth; } + protected function getColumn() + { + $model = $this->model; + $columnName = $this->columnName; + $relations = Str::evalHtmlArray($columnName); + $last_relation = array_pop($relations); + + while ( $relations ) + { + $relation = array_shift($relations); + $model = $model->$relation; + } + return $model->$last_relation(); + } + protected function getFileList() { $columnName = $this->columnName; - $list = $this->model->$columnName()->withDeferred($this->sessionKey)->orderBy('sort_order')->get(); + $list = $this->getColumn()->withDeferred($this->sessionKey)->orderBy('sort_order')->get(); /* * Set the thumb for each file @@ -98,7 +114,7 @@ class FileUpload extends FormWidgetBase { if (($file_id = post('file_id')) && ($file = File::find($file_id))) { $columnName = $this->columnName; - $this->model->$columnName()->remove($file, $this->sessionKey); + $this->getColumn()->remove($file, $this->sessionKey); } } @@ -190,7 +206,7 @@ class FileUpload extends FormWidgetBase throw new SystemException('File is not valid'); $columnName = $this->columnName; - $fileRelation = $this->model->$columnName(); + $fileRelation = $this->getColumn(); $file = new File(); $file->data = $uploadedFile; From 4df7af076d852926d7b4f5d8140e85deab2fcff7 Mon Sep 17 00:00:00 2001 From: flynsarmy Date: Fri, 22 Aug 2014 14:59:32 +1000 Subject: [PATCH 2/2] Remove unused variables --- modules/backend/formwidgets/FileUpload.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/modules/backend/formwidgets/FileUpload.php b/modules/backend/formwidgets/FileUpload.php index 125246f46..3b174fde0 100644 --- a/modules/backend/formwidgets/FileUpload.php +++ b/modules/backend/formwidgets/FileUpload.php @@ -81,7 +81,6 @@ class FileUpload extends FormWidgetBase protected function getFileList() { - $columnName = $this->columnName; $list = $this->getColumn()->withDeferred($this->sessionKey)->orderBy('sort_order')->get(); /* @@ -113,7 +112,6 @@ class FileUpload extends FormWidgetBase public function onRemoveAttachment() { if (($file_id = post('file_id')) && ($file = File::find($file_id))) { - $columnName = $this->columnName; $this->getColumn()->remove($file, $this->sessionKey); } } @@ -205,7 +203,6 @@ class FileUpload extends FormWidgetBase if (!$uploadedFile->isValid()) throw new SystemException('File is not valid'); - $columnName = $this->columnName; $fileRelation = $this->getColumn(); $file = new File();