Skip to content

Commit

Permalink
add changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ArrayIterator committed Nov 16, 2023
1 parent bb7d6a3 commit c63bc0c
Show file tree
Hide file tree
Showing 8 changed files with 344 additions and 76 deletions.
147 changes: 147 additions & 0 deletions Entities/Attachment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
<?php
declare(strict_types=1);

namespace ArrayAccess\TrayDigita\App\Modules\Media\Entities;

use ArrayAccess\TrayDigita\App\Modules\Users\Entities\Admin;
use ArrayAccess\TrayDigita\App\Modules\Users\Entities\Site;
use ArrayAccess\TrayDigita\Database\Entities\Abstracts\AbstractAttachment;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\HasLifecycleCallbacks;
use Doctrine\ORM\Mapping\Index;
use Doctrine\ORM\Mapping\JoinColumn;
use Doctrine\ORM\Mapping\ManyToOne;
use Doctrine\ORM\Mapping\Table;
use Doctrine\ORM\Mapping\UniqueConstraint;

/**
* @property-read ?Admin $user
*/
#[Entity]
#[Table(
name: self::TABLE_NAME,
options: [
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'comment' => 'Attachments created by admin user',
]
)]
#[UniqueConstraint(
name: 'unique_path_storage_type',
columns: ['path', 'storage_type']
)]
#[Index(
columns: ['id', 'site_id'],
name: 'index_id_site_id'
)]
#[Index(
columns: ['storage_type', 'mime_type'],
name: 'index_storage_type_mime_type'
)]
#[Index(
columns: ['user_id'],
name: 'relation_attachments_user_id_admins_id'
)]
#[Index(
columns: ['site_id'],
name: 'relation_attachments_site_id_sites_id'
)]
#[Index(
columns: ['name', 'file_name', 'status', 'mime_type', 'storage_type', 'site_id'],
name: 'index_name_file_name_status_mime_type_storage_type_site_id'
)]
#[HasLifecycleCallbacks]
class Attachment extends AbstractAttachment
{
public const TABLE_NAME = 'attachments';

#[Column(
name: 'site_id',
type: Types::BIGINT,
length: 20,
nullable: true,
options: [
'unsigned' => true,
'default' => null,
'comment' => 'Site id'
]
)]
protected ?int $site_id = null;
#[
JoinColumn(
name: 'site_id',
referencedColumnName: 'id',
nullable: true,
onDelete: 'RESTRICT',
options: [
'relation_name' => 'relation_attachments_site_id_sites_id',
'onUpdate' => 'CASCADE',
'onDelete' => 'RESTRICT'
]
),
ManyToOne(
targetEntity: Site::class,
cascade: [
"persist"
],
fetch: 'EAGER'
)
]
protected ?Site $site = null;

#[
JoinColumn(
name: 'user_id',
referencedColumnName: 'id',
nullable: true,
onDelete: 'RESTRICT',
options: [
'relation_name' => 'relation_attachments_user_id_admins_id',
'onUpdate' => 'CASCADE',
'onDelete' => 'RESTRICT'
],
),
ManyToOne(
targetEntity: Admin::class,
cascade: [
'persist'
],
fetch: 'LAZY',
)
]
protected ?Admin $user = null;

public function setUser(?Admin $user): void
{
$this->user = $user;
$this->setUserId($user?->getId());
}

public function getUser(): ?Admin
{
return $this->user;
}

public function getSiteId(): ?int
{
return $this->site_id;
}

public function setSiteId(?int $site_id): void
{
$this->site_id = $site_id;
}

public function getSite(): ?Site
{
return $this->site;
}

public function setSite(?Site $site): void
{
$this->site = $site;
$this->setSiteId($site?->getId());
}
}
147 changes: 147 additions & 0 deletions Entities/UserAttachment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
<?php
declare(strict_types=1);

namespace ArrayAccess\TrayDigita\App\Modules\Media\Entities;

use ArrayAccess\TrayDigita\App\Modules\Users\Entities\Site;
use ArrayAccess\TrayDigita\App\Modules\Users\Entities\User;
use ArrayAccess\TrayDigita\Database\Entities\Abstracts\AbstractAttachment;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\HasLifecycleCallbacks;
use Doctrine\ORM\Mapping\Index;
use Doctrine\ORM\Mapping\JoinColumn;
use Doctrine\ORM\Mapping\ManyToOne;
use Doctrine\ORM\Mapping\Table;
use Doctrine\ORM\Mapping\UniqueConstraint;

/**
* @property-read ?User $user
*/
#[Entity]
#[Table(
name: self::TABLE_NAME,
options: [
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'comment' => 'Attachments created by common user',
]
)]
#[UniqueConstraint(
name: 'unique_path_storage_type',
columns: ['path', 'storage_type']
)]
#[Index(
columns: ['id', 'site_id'],
name: 'index_id_site_id'
)]
#[Index(
columns: ['storage_type', 'mime_type'],
name: 'index_storage_type_mime_type'
)]
#[Index(
columns: ['user_id'],
name: 'relation_user_attachments_user_id_users_id'
)]
#[Index(
columns: ['site_id'],
name: 'relation_user_attachments_site_id_sites_id'
)]
#[Index(
columns: ['name', 'file_name', 'status', 'mime_type', 'storage_type', 'site_id'],
name: 'index_name_file_name_status_mime_type_storage_type_site_id'
)]
#[HasLifecycleCallbacks]
class UserAttachment extends AbstractAttachment
{
public const TABLE_NAME = 'user_attachments';

#[Column(
name: 'site_id',
type: Types::BIGINT,
length: 20,
nullable: true,
options: [
'unsigned' => true,
'comment' => 'Site id'
]
)]
protected ?int $site_id = null;

#[
JoinColumn(
name: 'site_id',
referencedColumnName: 'id',
nullable: true,
onDelete: 'RESTRICT',
options: [
'relation_name' => 'relation_user_attachments_site_id_sites_id',
'onUpdate' => 'CASCADE',
'onDelete' => 'RESTRICT'
]
),
ManyToOne(
targetEntity: Site::class,
cascade: [
"persist"
],
fetch: 'EAGER'
)
]
protected ?Site $site = null;

#[
JoinColumn(
name: 'user_id',
referencedColumnName: 'id',
nullable: true,
onDelete: 'RESTRICT',
options: [
'relation_name' => 'relation_user_attachments_user_id_users_id',
'onUpdate' => 'CASCADE',
'onDelete' => 'RESTRICT'
],
),
ManyToOne(
targetEntity: User::class,
cascade: [
'persist'
],
fetch: 'LAZY',
)
]
protected ?User $user = null;

public function setUser(?User $user): void
{
$this->user = $user;
$this->setUserId($user?->getId());
}

public function getUser(): ?User
{
return $this->user;
}

public function getSiteId(): ?int
{
return $this->site_id;
}

public function setSiteId(?int $site_id): void
{
$this->site_id = $site_id;
}

public function getSite(): ?Site
{
return $this->site;
}

public function setSite(?Site $site): void
{
$this->site = $site;
$this->setSiteId($site?->getId());
}
}
35 changes: 1 addition & 34 deletions Languages/media-module.pot → Languages/module.pot
Original file line number Diff line number Diff line change
Expand Up @@ -25,37 +25,4 @@ msgstr ""
"X-Poedit-SearchPathExcluded-0: *.css\n"
"X-Poedit-SearchPathExcluded-1: *.html\n"
"X-Poedit-SearchPathExcluded-2: *.json\n"

#: Media.php:43
msgctxt "module"
msgid "Media Manager"
msgstr ""

#: Media.php:52
msgctxt "module"
msgid ""
"Module to make application support media & file "
"attachments"
msgstr ""

#: Uploader/Abstracts/AbstractUploader.php:128
msgctxt "module"
msgid "File does not have file name"
msgstr ""

#: Uploader/Abstracts/AbstractUploader.php:143
#, php-format
msgctxt "module"
msgid "Could not determine file type from mimetype %s"
msgstr ""

#: Uploader/Abstracts/AbstractUploader.php:259
msgctxt "module"
msgid "Could not save uploaded file"
msgstr ""

#: Uploader/Abstracts/AbstractUploader.php:271
msgctxt "module"
msgid ""
"Could not save uploaded file & determine target file."
msgstr ""
"X-Poedit-SearchPathExcluded-3: *.json\n"
Loading

0 comments on commit c63bc0c

Please sign in to comment.