Initial import
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\models;
|
||||
|
||||
/**
|
||||
* Class FileImage
|
||||
* @package app\models
|
||||
* @property $id
|
||||
* @property string $media_key
|
||||
* @property string $object_key
|
||||
* @property string $file_name
|
||||
* @property string $file_type
|
||||
* @property string $file_extension
|
||||
* @property string $file_size
|
||||
* @property string $date_time
|
||||
* @property string $resolutions
|
||||
* @property array $resolutionArray
|
||||
* @property int $order_index
|
||||
* @property boolean $has_article
|
||||
*/
|
||||
class FileCms extends _Base
|
||||
{
|
||||
public static function remove($id)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function getResolutionArray()
|
||||
{
|
||||
if ($this->resolutions) {
|
||||
$res = $this->resolutions;
|
||||
$res = ltrim($res, '"');
|
||||
$res = rtrim($res, '"');
|
||||
$res = str_replace('\"', '"', $res);
|
||||
return json_decode($res);
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
public function deleteResolution($rez)
|
||||
{
|
||||
if ($rez) {
|
||||
$resolutions = $this->resolutionArray;
|
||||
$key = array_search($rez, $resolutions);
|
||||
if (false !== $key) {
|
||||
unset($resolutions[$key]);
|
||||
}
|
||||
$this->resolutions = json_encode($resolutions);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array['id', 'src']
|
||||
*/
|
||||
public function getImageData($ready = null)
|
||||
{
|
||||
$imageTypes = ['image/jpeg', 'image/png'];
|
||||
if (in_array($this->file_type, $imageTypes)) {
|
||||
$crops = [];
|
||||
|
||||
//if(!empty($this->resolutionArray)) {
|
||||
foreach ($this->resolutionArray as $rez) {
|
||||
$file = '/_files/ready/' . $this->media_key . '/' . $this->object_key . '/' . $rez . '/' . $this->file_name;
|
||||
if (file_exists($_SERVER['DOCUMENT_ROOT'] . $file))
|
||||
$crops[$rez] = $file;
|
||||
}
|
||||
//}
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'src_raw' => '/_files/raw/' . $this->media_key . '/' . $this->object_key . '/' . $this->file_name,
|
||||
'src' => $ready ? '/_files/ready/' . $this->media_key . '/' . $this->object_key . '/' . $ready . '/' . $this->file_name : null,
|
||||
'file_name' => $this->file_name,
|
||||
'crops' => array_keys($crops),
|
||||
'crop_files' => $crops,
|
||||
'type' => $this->file_type,
|
||||
'extension' => $this->file_extension,
|
||||
'size' => number_format($this->file_size / 1024 / 1024, 2, '.', '') . 'M'
|
||||
];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user