Skip to content

Commit

Permalink
Merge pull request #91 from TwistPHP/hotfix-upload-assets
Browse files Browse the repository at this point in the history
Fixed upload asset group selection
  • Loading branch information
ahosgood committed May 13, 2016
2 parents 76bb875 + 2b2e379 commit fa12ada
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion dist/twist/Core/Controllers/Base.controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ public function _model(){
* Get a Route URI var from the route vars, passing in null will return the whole array of route vars.
*
* @param null $strVarKey
* @return array|null
* @return string|array|null
*/
protected function _var($strVarKey = null){

Expand Down
24 changes: 17 additions & 7 deletions dist/twist/Core/Controllers/Upload.controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,29 @@ public function asset($strFileKey = null,$intIndex = null){
//Now if the file upload was successful process the asset (if required)
if($arrOut['status']){

$arrDynamicRoute = $this->_route('dynamic');

//Get the asset group to be used for the upload
$arrAssetGroup = array();
$intAssetGroup = \Twist::framework()->setting('ASSET_DEFAULT_GROUP');

if(count($arrDynamicRoute)){
if(count($arrDynamicRoute) > 1 && $arrDynamicRoute[0] == 'asset'){
$intAssetGroup = \Twist::Asset()->getGroupBySlug($arrDynamicRoute[1]);
}elseif($arrDynamicRoute[0] !== 'asset'){
$intAssetGroup = \Twist::Asset()->getGroupBySlug($arrDynamicRoute[0]);
//Allow for a URI to be registered such as: Twist::Route()->upload('/account/upload/{function}/{asset_group}');
if($this->_var('asset_group') != null && $this->_var('asset_group') != ''){
$arrAssetGroup = \Twist::Asset()->getGroupBySlug($this->_var('asset_group'));
}else{
$arrDynamicRoute = $this->_route('dynamic');

if(count($arrDynamicRoute)){
if(count($arrDynamicRoute) > 1 && $arrDynamicRoute[0] == 'asset'){
$arrAssetGroup = \Twist::Asset()->getGroupBySlug($arrDynamicRoute[1]);
}elseif($arrDynamicRoute[0] !== 'asset'){
$arrAssetGroup = \Twist::Asset()->getGroupBySlug($arrDynamicRoute[0]);
}
}
}

if(count($arrAssetGroup)){
$intAssetGroup = $arrAssetGroup['id'];
}

$intAssetID = \Twist::Asset()->add($arrOut['file']['path'],$intAssetGroup);
$arrAsset = \Twist::Asset()->get($intAssetID);

Expand Down

0 comments on commit fa12ada

Please sign in to comment.