This commit is contained in:
2024-11-20 15:56:54 +03:00
commit f23aee6dcb
15 changed files with 1557 additions and 0 deletions

View File

@@ -0,0 +1,66 @@
<?php
namespace dominion\file\schema;
use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Definition\Type;
use dominion\file\Config;
class FileConfigMutationType extends ObjectType
{
public function __construct()
{
$config = [
'fields' => function() {
return [
'save' => [
'type' => Type::int(),
'description' => 'Сохранение наклейки',
'args' => [
'module' => Type::nonNull(Type::string()),
'type' => Type::nonNull(Type::string()),
'height' => Type::nonNull(Type::int()),
'width' => Type::nonNull(Type::int()),
'name' => Type::string(),
'crop' => Type::boolean(),
'cut' => Type::boolean(),
'addBorder' => Type::boolean(),
'border_top' => Type::int(),
'border_right' => Type::int(),
'border_left' => Type::int(),
'border_bottom' => Type::int(),
'quality' => Type::int(),
'file' => Type::string(),
'fileName' => Type::string(),
'fileDelete' => Type::boolean(),
],
'resolve' => function(Config $root, $args) {
return $root->customSave($args);
},
],
'delete' => [
'type' => Type::int(),
'description' => 'Удаление',
'resolve' => function(Config $root, $args) {
return $root->delete();
},
],
'resize' => [
'type' => Types::fileConfigResizeStep(),
'description' => 'Сохранение наклейки',
'args' => [
'all' => Type::boolean(),
'fileId' => Type::int()
],
'resolve' => function(Config $root, $args) {
return $root->resize($args);
},
],
];
}
];
parent::__construct($config);
}
}

View File

@@ -0,0 +1,42 @@
<?php
namespace dominion\file\schema;
use GraphQL\Type\Definition\Type;
use dominion\api\GraphQLSchemaPagination;
use dominion\file\Config;
use dominion\api\GraphQLPagination;
class FileConfigPaginationType extends GraphQLSchemaPagination
{
public function __construct()
{
$config = [
'fields' => function(){
$output = $this->getCustomFields();
$output['data'] = [
'type' => Type::listOf(Types::fileConfig()),
'description' => 'Конфигурация миниатюр',
'args' => GraphQLPagination::argumentModify([
'id' => [
'type' => Type::int(),
'description' => 'Id конфига',
],
'sort' => [
'type' => Type::string(),
'description' => 'Сортировка (пример "isNew_asc" или "isVisible_desc")',
],
]),
'resolve' => function($root, $args){
return Config::getData($args, $root);
}
];
return $output;
}
];
parent::__construct($config);
}
}

View File

@@ -0,0 +1,33 @@
<?php
namespace dominion\file\schema;
use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Definition\Type;
class FileConfigResizeStepType extends ObjectType
{
public function __construct()
{
$config = [
'fields' => function() {
return [
'fileId' => [
'type' => Type::int(),
'description' => 'последний обработтанный файл',
],
'count' => [
'type' => Type::int(),
],
'step' => [
'type' => Type::string(),
'description' => 'type',
],
];
}
];
parent::__construct($config);
}
}

89
schema/FileConfigType.php Normal file
View File

@@ -0,0 +1,89 @@
<?php
namespace dominion\file\schema;
use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Definition\Type;
class FileConfigType extends ObjectType
{
public function __construct()
{
$config = [
'fields' => function() {
return [
'id' => [
'type' => Type::int(),
'description' => 'Id',
],
'module' => [
'type' => Type::string(),
'description' => 'module',
],
'type' => [
'type' => Type::string(),
'description' => 'type',
],
'height' => [
'type' => Type::int(),
'description' => 'height',
],
'width' => [
'type' => Type::int(),
'description' => 'width',
],
'name' => [
'type' => Type::string(),
'description' => 'name',
],
'cut' => [
'type' => Type::boolean(),
'description' => 'cut',
],
'crop' => [
'type' => Type::boolean(),
'description' => 'crop',
],
'addBorder' => [
'type' => Type::boolean(),
'description' => 'addBorder',
],
'fileId' => [
'type' => Type::int(),
'description' => 'Шаблон изображения',
],
'border_top' => [
'type' => Type::int(),
'description' => 'отступы для окна внутри шаблона (сверху)',
],
'border_right' => [
'type' => Type::int(),
'description' => 'тступы для окна внутри шаблона (справа)',
],
'border_left' => [
'type' => Type::int(),
'description' => 'отступы для окна внутри шаблона (слева)',
],
'border_bottom' => [
'type' => Type::int(),
'description' => 'отступы для окна внутри шаблона (снизу)',
],
'quality' => [
'type' => Type::int(),
'description' => 'качество (степень сжатия)',
],
'fileObj' => [
'type' => Types::fileTemplate(),
'description' => 'объект файла',
'resolve' => function($root, $args) {
return $root->file;
}
],
];
}
];
parent::__construct($config);
}
}

View File

@@ -0,0 +1,57 @@
<?php
namespace dominion\file\schema;
use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Definition\Type;
use dominion\file\File;
class FileTemplateType extends ObjectType
{
public function __construct()
{
$config = [
'fields' => function() {
return [
'id' => [
'type' => Type::int(),
'description' => 'Id',
],
'description' => [
'type' => Type::string(),
'description' => 'Описание',
],
'originalName' => [
'type' => Type::string(),
'description' => 'Название файла при загрузке',
],
'ext' => [
'type' => Type::string(),
'description' => 'ext',
],
'fileSize' => [
'type' => Type::int(),
'description' => 'fileSize',
],
'file' => [
'type' => Type::string(),
'description' => 'Путь к файлу',
'resolve' => function($root, $args) {
return File::getPathFull($root->id);
}
],
'size' => [
'type' => Type::string(),
'description' => 'Размер файла',
'resolve' => function($root, $args) {
return $root->size;
}
],
];
}
];
parent::__construct($config);
}
}

64
schema/FileType.php Normal file
View File

@@ -0,0 +1,64 @@
<?php
namespace dominion\file\schema;
use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Definition\Type;
use dominion\file\File;
class FileType extends ObjectType
{
public function __construct()
{
$config = [
'fields' => function() {
return [
'id' => [
'type' => Type::int(),
'description' => 'Id',
],
'description' => [
'type' => Type::string(),
'description' => 'Описание',
],
'originalName' => [
'type' => Type::string(),
'description' => 'Название файла при загрузке',
],
'ext' => [
'type' => Type::string(),
'description' => 'ext',
],
'fileSize' => [
'type' => Type::int(),
'description' => 'fileSize',
],
'file' => [
'type' => Type::string(),
'description' => 'Путь к файлу',
'args' => [
'type' => [
'type' => Type::string(),
'description' => "Тип миниатюры ('snippet', 'small', 'medium', 'large', 'landing', 'adv1080') по умолчанию нет",
],
],
'resolve' => function($root, $args) {
$type = isset($args['type']) ? $args['type'] : null;
return File::getPathFull($root->id, $type);
}
],
'size' => [
'type' => Type::string(),
'description' => 'Размер файла',
'resolve' => function($root, $args) {
return $root->size;
}
],
];
}
];
parent::__construct($config);
}
}

36
schema/FileTypes.php Normal file
View File

@@ -0,0 +1,36 @@
<?php
namespace dominion\file\schema;
trait FileTypes
{
private static $fileConfig;
private static $fileConfigPagination;
private static $fileConfigResizeStep;
private static $file;
//
private static $fileConfigMutation;
public static function fileConfig()
{
return self::$fileConfig ?: (self::$fileConfig = new FileConfigType());
}
public static function fileConfigPagination()
{
return self::$fileConfigPagination ?: (self::$fileConfigPagination = new FileConfigPaginationType());
}
public static function fileConfigResizeStep()
{
return self::$fileConfigResizeStep ?: (self::$fileConfigResizeStep = new FileConfigResizeStepType());
}
public static function file()
{
return self::$file ?: (self::$file = new FileType());
}
//
public static function fileConfigMutation()
{
return self::$fileConfigMutation ?: (self::$fileConfigMutation = new FileConfigMutationType());
}
}

17
schema/Types.php Normal file
View File

@@ -0,0 +1,17 @@
<?php
namespace dominion\file\schema;
class Types
{
use FileTypes;
private static $fileTemplate;
public static function fileTemplate()
{
return self::$fileTemplate ?: (self::$fileTemplate = new FileTemplateType());
}
}