示例#1
0
 public function getImage($item, $dirtyAlias)
 {
     $params = $data = $this->parseImageAlias($dirtyAlias);
     $alias = $params['alias'];
     $size = $params['size'];
     $itemId = preg_replace('/[^0-9]+/', '', $item);
     $modelName = preg_replace('/[0-9]+/', '', $item);
     $image = Image::find()->where(['modelName' => $modelName, 'itemId' => $itemId, 'urlAlias' => $alias])->one();
     if (!$image) {
         return $this->getPlaceHolder();
     }
     return $image;
 }
示例#2
0
 public function getImageByName($name)
 {
     if ($this->getModule()->className === null) {
         $imageQuery = Image::find();
     } else {
         $class = $this->getModule()->className;
         $imageQuery = $class::find();
     }
     $finder = $this->getImagesFinder(['name' => $name]);
     $imageQuery->where($finder);
     $imageQuery->orderBy(['isMain' => SORT_DESC, 'id' => SORT_ASC]);
     $img = $imageQuery->one();
     if (!$img) {
         return $this->getModule()->getPlaceHolder();
     }
     return $img;
 }