1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?php
- namespace app\models\base;
- use yii\base\Model;
- use yii\db\ActiveRecord;
- use yii\helpers\Url;
- /**
- * @property string $file_name
- * @property string $url
- * @property string $file_title
- */
- class Image extends Model
- {
- const SIZE_1040x586 = 1;
- const SIZE_680x383 = 2;
- const SIZE_500x282 = 3;
- const SIZE_320x180 = 4;
- const SIZE_ORIGINAL = 0;
- public $types = ["webp","jpg"];
- public $post_id = null;
- public $type = NULL;
- public function getUrl($size = 1,$type = NULL,$full = true)
- {
- $this->type = $type ?? $this->type;
- switch ($this->type){
- case "jpg":
- return "https://green.amic.ru/images/news/news/{$this->post_id}_size{$size}.jpg";
- break;
- default:
- return "https://green.amic.ru/images/news/webp/{$this->post_id}_size{$size}.webp";
- }
- return ($full?"https://api.amic.ru":"")."/uploads/news/images/".$this->file_name;
- }
- public static function find(){
- $model = new static();
- return $model;
- }
- public static function findOne($id,$type="webp"){
- $model = self::find();
- $model->type = $type;
- $model->post_id = $id;
- return $model;
- }
- }
|