Skip to content

Commit

Permalink
Dev: separate image in template and image in survey
Browse files Browse the repository at this point in the history
Dev: review ordering
  • Loading branch information
Shnoulle committed Oct 24, 2018
1 parent ba3a9dc commit 117abc8
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions application/models/TemplateConfiguration.php
Expand Up @@ -785,18 +785,24 @@ private function _getRelativePath($from, $to) {
return str_repeat('..'.DIRECTORY_SEPARATOR, count($dir)) . implode(DIRECTORY_SEPARATOR, $file);
}

private function _filterImages($file)
/**
* Return image information
* @param string $file
* @param integer get file in this survey dir too
* @return array|null
*/
private function _filterImages($file,$surveyId = null)
{
$imagePath = "";
if($this->sid && file_exists(Yii::app()->getConfig('uploaddir').'/surveys/'.$this->sid.'/images/'.$file['name']) ) {
$imagePath = Yii::app()->getConfig('uploaddir').'/surveys/'.$this->sid.'/images/'.$file['name'];
}
if( file_exists($this->filesPath.$file['name']) ) {
if(file_exists($this->generalFilesPath.$file['name']) ) {
$imagePath = $this->generalFilesPath.$file['name'];
}
if( file_exists($this->filesPath.$file['name']) ) {
if(file_exists($this->filesPath.$file['name']) ) {
$imagePath = $this->filesPath.$file['name'];
}
if($surveyId && file_exists(Yii::app()->getConfig('uploaddir').'/surveys/'.$this->sid.'/images/'.$file['name']) ) {
$imagePath = Yii::app()->getConfig('uploaddir').'/surveys/'.$this->sid.'/images/'.$file['name'];
}
if(!$imagePath) {
return;
}
Expand All @@ -812,19 +818,23 @@ protected function getOptionPageAttributes()
{
$aData = $this->attributes;
$fileList = array_merge(Template::getOtherFiles($this->filesPath), Template::getOtherFiles($this->generalFilesPath));
if($this->sid) {
$fileList = array_merge($fileList,Template::getOtherFiles(Yii::app()->getConfig('uploaddir').'/surveys/'.$this->sid.'/images/'));
}
$aData['maxFileSize'] = getMaximumFileUploadSize();
$aData['imageFileList'] = [];
foreach ($fileList as $file) {
$isImage = $this->_filterImages($file);

if ($isImage) {
$aData['imageFileList'][] = $isImage;
}
};

if($this->sid) {
$fileList = Template::getOtherFiles(Yii::app()->getConfig('uploaddir').'/surveys/'.$this->sid.'/images/');
foreach ($fileList as $file) {
$isImage = $this->_filterImages($file,$this->sid);
if ($isImage) {
$aData['imageFileList'][] = $isImage;
}
};
}
return $aData;
}

Expand Down

0 comments on commit 117abc8

Please sign in to comment.