<commit_before><?php

namespace Backend\Modules\MediaGalleries\Domain\MediaGallery;

use Ramsey\Uuid\Uuid;
use Doctrine\ORM\Mapping as ORM;
use Backend\Core\Engine\Model;
use Backend\Modules\MediaLibrary\Domain\MediaGroup\MediaGroup;
use Common\ModuleExtraType;

/**
 * MediaGallery
 *
 * @ORM\Entity(repositoryClass="Backend\Modules\MediaGalleries\Domain\MediaGallery\MediaGalleryRepository")
 * @ORM\HasLifecycleCallbacks
 */
class MediaGallery
{
    /**
     * @var string
     *
     * @ORM\Id()
     * @ORM\GeneratedValue(strategy="UUID")
     * @ORM\Column(type="guid")
     */
    private $id;

    /**
     * @var int
     *
     * @ORM\Column(type="integer")
     */
    protected $userId;

    /**
     * @var int
     *
     * ToDo: when Fork CMS has ModuleExtra entity in core, use its Entity as type
     *
     * @ORM\Column(type="integer")
     */
    protected $moduleExtraId;

    /**
     * @var string
     *
     * @ORM\Column(type="string")
     */
    protected $action;

    /**
     * @var string
     *
     * @ORM\Column(type="string")
     */
    protected $title;

    /**
     * @var string|null
     *
     * @ORM\Column(type="string", nullable=true)
     */
    protected $text;

    /**
     * @var \DateTime
     *
     * @ORM\Column(type="datetime")
     */
    protected $createdOn;

    /**
     * @var \DateTime
     *
     * @ORM\Column(type="datetime")
     */
    protected $editedOn;

    /**
     * @var \DateTime
     *
     * @ORM\Column(type="datetime")
     */
    protected $publishOn;

    /**
     * @var Status
     *
     * @ORM\Column(type="media_gallery_status")
     */
    protected $status;

    /**
     * @var MediaGroup
     *
     * @ORM\OneToOne(
     *      targetEntity="Backend\Modules\MediaLibrary\Domain\MediaGroup\MediaGroup",
     *      cascade="persist",
     *      orphanRemoval=true
     * )
     * @ORM\JoinColumn(
     *      name="mediaGroupId",
     *      referencedColumnName="id",
     *      onDelete="cascade"
     * )
     */
    protected $mediaGroup;

    /**
     * MediaGallery constructor.
     *
     * @param string $title
     * @param string $action
     * @param int $userId
     * @param \DateTime $publishOn
     * @param MediaGroup $mediaGroup
     * @param Status $status
     * @param string|null $text
     */
    private function __construct(
        string $title,
        string $action,
        int $userId,
        \DateTime $publishOn,
        MediaGroup $mediaGroup,
        Status $status,
        string $text = null
    ) {
        $this->userId = $userId;
        $this->action = $action;
        $this->title = $title;
        $this->publishOn = $publishOn;
        $this->mediaGroup = $mediaGroup;
        $this->status = $status;
        $this->text = $text;
    }

    /**
     * @param MediaGalleryDataTransferObject $mediaGalleryDataTransferObject
     * @return MediaGallery
     */
    public static function fromDataTransferObject(MediaGalleryDataTransferObject $mediaGalleryDataTransferObject): MediaGallery
    {
        if ($mediaGalleryDataTransferObject->hasExistingMediaGallery()) {
            /** @var MediaGallery $mediaGallery */
            $mediaGallery = $mediaGalleryDataTransferObject->getMediaGalleryEntity();

            $mediaGallery->action = $mediaGalleryDataTransferObject->action;
            $mediaGallery->title = $mediaGalleryDataTransferObject->title;
            $mediaGallery->text = $mediaGalleryDataTransferObject->text;
            $mediaGallery->publishOn = $mediaGalleryDataTransferObject->publishOn;
            $mediaGallery->mediaGroup = $mediaGalleryDataTransferObject->mediaGroup;
            $mediaGallery->status = $mediaGalleryDataTransferObject->status;

            return $mediaGallery;
        }

        /** @var MediaGallery $mediaGallery */
        $mediaGallery = new self(
            $mediaGalleryDataTransferObject->title,
            $mediaGalleryDataTransferObject->action,
            $mediaGalleryDataTransferObject->userId,
            $mediaGalleryDataTransferObject->publishOn,
            $mediaGalleryDataTransferObject->mediaGroup,
            $mediaGalleryDataTransferObject->status,
            $mediaGalleryDataTransferObject->text
        );

        return $mediaGallery;
    }

    /**
     * Gets the value of id.
     *
     * @return string
     */
    public function getId(): string
    {
        return $this->id;
    }

    /**
     * Gets the value of userId.
     *
     * @return int
     */
    public function getUserId(): int
    {
        return $this->userId;
    }

    /**
     * Gets the value of moduleExtraId.
     *
     * @return int
     */
    public function getModuleExtraId(): int
    {
        return $this->moduleExtraId;
    }

    /**
     * Gets the Action
     *
     * @return string
     */
    public function getAction(): string
    {
        return $this->action;
    }

    /**
     * Gets the value of title.
     *
     * @return string
     */
    public function getTitle(): string
    {
        return $this->title;
    }

    /**
     * Gets the value of text.
     *
     * @return string|null
     */
    public function getText()
    {
        return $this->text;
    }

    /**
     * Gets the value of createdOn.
     *
     * @return \DateTime
     */
    public function getCreatedOn(): \DateTime
    {
        return $this->createdOn;
    }

    /**
     * Gets the value of editedOn.
     *
     * @return \DateTime
     */
    public function getEditedOn(): \DateTime
    {
        return $this->editedOn;
    }

    /**
     * Get extra label
     *
     * @return string The gallery extra_label.
     */
    protected function getExtraLabel(): string
    {
        return '"' . $this->title . '"' . ' - ' . ucfirst($this->action);
    }

    /**
     * Gets the value of publishOn.
     *
     * @return \DateTime
     */
    public function getPublishOn(): \DateTime
    {
        return $this->publishOn;
    }

    /**
     * @return Status
     */
    public function getStatus(): Status
    {
        return $this->status;
    }

    /**
     * Gets the value of mediaGroup.
     *
     * @return MediaGroup
     */
    public function getMediaGroup(): MediaGroup
    {
        return $this->mediaGroup;
    }

    /**
     * @ORM\PrePersist
     */
    public function onPrePersist()
    {
        $this->createdOn = $this->editedOn = new \Datetime();

        $this->moduleExtraId = Model::insertExtra(
            ModuleExtraType::widget(),
            'MediaGalleries',
            'Gallery',
            'Gallery',
            [],
            false
        );
    }

    /**
     * @ORM\PreUpdate
     */
    public function onPreUpdate()
    {
        $this->editedOn = new \Datetime();
    }

    /**
     * @ORM\PostRemove
     */
    public function onPostRemove()
    {
        Model::deleteExtraById(
            $this->moduleExtraId,
            true
        );
    }

    /**
     * Update module extra data
     *
     * @ORM\PostPersist
     * @ORM\PostUpdate
     */
    public function updateModuleExtraData()
    {
        // Update ModuleExtra data
        Model::updateExtra(
            $this->getModuleExtraId(),
            'data',
            [
                'gallery_id' => $this->id,
                'extra_label' => $this->getExtraLabel(),
                'edit_url' =>
                    Model::createURLForAction('MediaGalleryEdit', 'MediaGalleries')
                    . '&id=' . $this->id,
            ]
        );

        // Update hidden
        Model::updateExtra(
            $this->moduleExtraId,
            'hidden',
            'N'
        );
    }

    /**
     * Is visible only returns true if the "status" is "active" and the "publishOn" is in the past.
     *
     * @return bool
     */
    public function isVisible(): bool
    {
        $now = new \DateTime();

        return ($this->status->isActive() && $this->publishOn->getTimestamp() < $now->getTimestamp());
    }
}
<commit_msg>removed obsolete code<commit_after><?php

namespace Backend\Modules\MediaGalleries\Domain\MediaGallery;

use Ramsey\Uuid\Uuid;
use Doctrine\ORM\Mapping as ORM;
use Backend\Core\Engine\Model;
use Backend\Modules\MediaLibrary\Domain\MediaGroup\MediaGroup;
use Common\ModuleExtraType;

/**
 * MediaGallery
 *
 * @ORM\Entity(repositoryClass="Backend\Modules\MediaGalleries\Domain\MediaGallery\MediaGalleryRepository")
 * @ORM\HasLifecycleCallbacks
 */
class MediaGallery
{
    /**
     * @var string
     *
     * @ORM\Id()
     * @ORM\GeneratedValue(strategy="UUID")
     * @ORM\Column(type="guid")
     */
    private $id;

    /**
     * @var int
     *
     * @ORM\Column(type="integer")
     */
    protected $userId;

    /**
     * @var int
     *
     * ToDo: when Fork CMS has ModuleExtra entity in core, use its Entity as type
     *
     * @ORM\Column(type="integer")
     */
    protected $moduleExtraId;

    /**
     * @var string
     *
     * @ORM\Column(type="string")
     */
    protected $action;

    /**
     * @var string
     *
     * @ORM\Column(type="string")
     */
    protected $title;

    /**
     * @var string|null
     *
     * @ORM\Column(type="string", nullable=true)
     */
    protected $text;

    /**
     * @var \DateTime
     *
     * @ORM\Column(type="datetime")
     */
    protected $createdOn;

    /**
     * @var \DateTime
     *
     * @ORM\Column(type="datetime")
     */
    protected $editedOn;

    /**
     * @var \DateTime
     *
     * @ORM\Column(type="datetime")
     */
    protected $publishOn;

    /**
     * @var Status
     *
     * @ORM\Column(type="media_gallery_status")
     */
    protected $status;

    /**
     * @var MediaGroup
     *
     * @ORM\OneToOne(
     *      targetEntity="Backend\Modules\MediaLibrary\Domain\MediaGroup\MediaGroup",
     *      cascade="persist",
     *      orphanRemoval=true
     * )
     * @ORM\JoinColumn(
     *      name="mediaGroupId",
     *      referencedColumnName="id",
     *      onDelete="cascade"
     * )
     */
    protected $mediaGroup;

    /**
     * MediaGallery constructor.
     *
     * @param string $title
     * @param string $action
     * @param int $userId
     * @param \DateTime $publishOn
     * @param MediaGroup $mediaGroup
     * @param Status $status
     * @param string|null $text
     */
    private function __construct(
        string $title,
        string $action,
        int $userId,
        \DateTime $publishOn,
        MediaGroup $mediaGroup,
        Status $status,
        string $text = null
    ) {
        $this->userId = $userId;
        $this->action = $action;
        $this->title = $title;
        $this->publishOn = $publishOn;
        $this->mediaGroup = $mediaGroup;
        $this->status = $status;
        $this->text = $text;
    }

    /**
     * @param MediaGalleryDataTransferObject $mediaGalleryDataTransferObject
     * @return MediaGallery
     */
    public static function fromDataTransferObject(MediaGalleryDataTransferObject $mediaGalleryDataTransferObject): MediaGallery
    {
        if ($mediaGalleryDataTransferObject->hasExistingMediaGallery()) {
            /** @var MediaGallery $mediaGallery */
            $mediaGallery = $mediaGalleryDataTransferObject->getMediaGalleryEntity();

            $mediaGallery->action = $mediaGalleryDataTransferObject->action;
            $mediaGallery->title = $mediaGalleryDataTransferObject->title;
            $mediaGallery->text = $mediaGalleryDataTransferObject->text;
            $mediaGallery->publishOn = $mediaGalleryDataTransferObject->publishOn;
            $mediaGallery->mediaGroup = $mediaGalleryDataTransferObject->mediaGroup;
            $mediaGallery->status = $mediaGalleryDataTransferObject->status;

            return $mediaGallery;
        }

        return new self(
            $mediaGalleryDataTransferObject->title,
            $mediaGalleryDataTransferObject->action,
            $mediaGalleryDataTransferObject->userId,
            $mediaGalleryDataTransferObject->publishOn,
            $mediaGalleryDataTransferObject->mediaGroup,
            $mediaGalleryDataTransferObject->status,
            $mediaGalleryDataTransferObject->text
        );
    }

    /**
     * Gets the value of id.
     *
     * @return string
     */
    public function getId(): string
    {
        return $this->id;
    }

    /**
     * Gets the value of userId.
     *
     * @return int
     */
    public function getUserId(): int
    {
        return $this->userId;
    }

    /**
     * Gets the value of moduleExtraId.
     *
     * @return int
     */
    public function getModuleExtraId(): int
    {
        return $this->moduleExtraId;
    }

    /**
     * Gets the Action
     *
     * @return string
     */
    public function getAction(): string
    {
        return $this->action;
    }

    /**
     * Gets the value of title.
     *
     * @return string
     */
    public function getTitle(): string
    {
        return $this->title;
    }

    /**
     * Gets the value of text.
     *
     * @return string|null
     */
    public function getText()
    {
        return $this->text;
    }

    /**
     * Gets the value of createdOn.
     *
     * @return \DateTime
     */
    public function getCreatedOn(): \DateTime
    {
        return $this->createdOn;
    }

    /**
     * Gets the value of editedOn.
     *
     * @return \DateTime
     */
    public function getEditedOn(): \DateTime
    {
        return $this->editedOn;
    }

    /**
     * Get extra label
     *
     * @return string The gallery extra_label.
     */
    protected function getExtraLabel(): string
    {
        return '"' . $this->title . '"' . ' - ' . ucfirst($this->action);
    }

    /**
     * Gets the value of publishOn.
     *
     * @return \DateTime
     */
    public function getPublishOn(): \DateTime
    {
        return $this->publishOn;
    }

    /**
     * @return Status
     */
    public function getStatus(): Status
    {
        return $this->status;
    }

    /**
     * Gets the value of mediaGroup.
     *
     * @return MediaGroup
     */
    public function getMediaGroup(): MediaGroup
    {
        return $this->mediaGroup;
    }

    /**
     * @ORM\PrePersist
     */
    public function onPrePersist()
    {
        $this->createdOn = $this->editedOn = new \Datetime();

        $this->moduleExtraId = Model::insertExtra(
            ModuleExtraType::widget(),
            'MediaGalleries',
            'Gallery',
            'Gallery',
            [],
            false
        );
    }

    /**
     * @ORM\PreUpdate
     */
    public function onPreUpdate()
    {
        $this->editedOn = new \Datetime();
    }

    /**
     * @ORM\PostRemove
     */
    public function onPostRemove()
    {
        Model::deleteExtraById(
            $this->moduleExtraId,
            true
        );
    }

    /**
     * Update module extra data
     *
     * @ORM\PostPersist
     * @ORM\PostUpdate
     */
    public function updateModuleExtraData()
    {
        // Update ModuleExtra data
        Model::updateExtra(
            $this->getModuleExtraId(),
            'data',
            [
                'gallery_id' => $this->id,
                'extra_label' => $this->getExtraLabel(),
                'edit_url' =>
                    Model::createURLForAction('MediaGalleryEdit', 'MediaGalleries')
                    . '&id=' . $this->id,
            ]
        );

        // Update hidden
        Model::updateExtra(
            $this->moduleExtraId,
            'hidden',
            'N'
        );
    }

    /**
     * Is visible only returns true if the "status" is "active" and the "publishOn" is in the past.
     *
     * @return bool
     */
    public function isVisible(): bool
    {
        $now = new \DateTime();

        return ($this->status->isActive() && $this->publishOn->getTimestamp() < $now->getTimestamp());
    }
}

{'fraction_non_alphanumeric': 0.12702107581000316, 'fraction_numerical': 0.0, 'mean_word_length': 1.7917105725324904, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 121, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7322502', 'n_tokens_mistral': 4702, 'n_tokens_neox': 4628, 'n_words': 877}