Skip to content

Commit

Permalink
placeHolder next step
Browse files Browse the repository at this point in the history
  • Loading branch information
CostaRico committed Aug 8, 2014
1 parent acb2a87 commit 61ac881
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 14 deletions.
7 changes: 7 additions & 0 deletions Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace rico\yii2images;


use rico\yii2images\models\PlaceHolder;
use yii;
use rico\yii2images\models\Image;

Expand All @@ -16,6 +17,8 @@ class Module extends \yii\base\Module

public $controllerNamespace = 'rico\yii2images\controllers';

public $placeHolderPath;




Expand Down Expand Up @@ -45,6 +48,10 @@ public function getImage($item, $dirtyAlias)
':alias' => $alias
])*/
->one();
if(!$image){
$image = new PlaceHolder();
}

return $image;
}

Expand Down
4 changes: 2 additions & 2 deletions behaviors/ImageBehave.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public function getImages()

$imageRecords = $imageQuery->all();
if(!$imageRecords){
return [];
return [new models\PlaceHolder()];
}
return $imageRecords;
}
Expand All @@ -191,7 +191,7 @@ public function getImage()

$img = $imageQuery->one();
if(!$img){
return null;
return new models\PlaceHolder();
}

return $img;
Expand Down
41 changes: 29 additions & 12 deletions models/PlaceHolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,39 @@

namespace rico\yii2images\models;

/**
* TODO: check path to save and all image method for placeholder
*/

class PlaceHolder extends Image {
public function getUrl($size = false){
$url = $this->getModule()->placeHolderUrl;
if(!$url){
throw new \Exception('PlaceHolder image must have url setting!!!');
}
return $url;
}
use yii;

class PlaceHolder extends Image
{

public function getPathToOrigin(){
private $modelName = '';
private $itemId = '';
public $filePath = 'placeHolder.png';
public $urlAlias = 'placeHolder';

$url = $this->getModule()->placeHolderPath;
if(!$url){

/* public function getUrl($size = false){
$url = $this->getModule()->placeHolderUrl;
if(!$url){
throw new \Exception('PlaceHolder image must have url setting!!!');
}
return $url;
}*/

public function getPathToOrigin()
{

$url = Yii::getAlias($this->getModule()->placeHolderPath);
if (!$url) {
throw new \Exception('PlaceHolder image must have path setting!!!');
}
return $url;
}
}


}

0 comments on commit 61ac881

Please sign in to comment.