<commit_before><?php

namespace Lorry\Presenter\Manage\Moderator;

use Lorry\Presenter\AbstractPresenter;
use Lorry\Exception\FileNotFoundException;
use Lorry\Exception\ForbiddenException;
use Lorry\Service\LocalisationService;
use Lorry\Exception\ModelValueInvalidException;

class Approve extends AbstractPresenter
{

    /**
     *
     * @param Lorry\Service\PersistenceService $persistence
     * @param int $id
     * @return \Lorry\Model\Addon
     * @throws FileNotFoundException
     * @throws ForbiddenException
     */
    public static function getAddon($persistence, $id)
    {
        $addon = $persistence->build('Addon')->byId($id);
        if (!$addon) {
            throw new FileNotFoundException();
        }
        if (!$addon->isSubmittedForApproval() && !$addon->isApproved() && !$addon->isRejected()) {
            throw new ForbiddenException();
        }
        return $addon;
    }

    public function get($id)
    {
        $this->security->requireModerator();
        $this->offerIdentification();
        $this->security->requireIdentification();

        $addon = self::getAddon($this->persistence, $id);
        // if not submitted

        $game = $addon->fetchGame();
        $owner = $addon->fetchOwner();

        $this->context['addon'] = $addon->getTitle();
        $this->context['addon_en'] = $addon->getTitle('en');
        $this->context['addon_de'] = $addon->getTitle('de');
        $this->context['user'] = $owner->forPresenter();

        $duplicate = array();
        if ($addon->isApproved()) {
            $this->context['approved'] = true;
            $this->context['namespace'] = $addon->getShort();
        } else {
            $this->context['namespace'] = $addon->getProposedShort();
            $duplicate['namespace'] = ($this->persistence->build('Addon')->byShort($addon->getProposedShort())
                !== null);
            $duplicate['title_en'] = count($this->persistence->build('Addon')->all()->byTitle($addon->getTitle('en'),
                        0, 0, 'en')) > 1;
            $duplicate['title_de'] = count($this->persistence->build('Addon')->all()->byTitle($addon->getTitle('de'),
                        0, 0, 'de')) > 1;
        }
        $this->context['duplicate'] = $duplicate;

        $this->context['rejected'] = $addon->isRejected();

        $this->context['game'] = array('title' => $game->getTitle(), 'short' => $game->getShort());
        $this->context['timestamp'] = date($this->localisation->getFormat(LocalisationService::FORMAT_DATETIME),
            $addon->getApprovalSubmit());

        if (!isset($this->context['comment'])) {<commit_msg>fix getShort/getNamespace called from legacy Presenter<commit_after><?php

namespace Lorry\Presenter\Manage\Moderator;

use Lorry\Presenter\AbstractPresenter;
use Lorry\Exception\FileNotFoundException;
use Lorry\Exception\ForbiddenException;
use Lorry\Service\LocalisationService;
use Lorry\Exception\ModelValueInvalidException;

class Approve extends AbstractPresenter
{

    /**
     *
     * @param Lorry\Service\PersistenceService $persistence
     * @param int $id
     * @return \Lorry\Model\Addon
     * @throws FileNotFoundException
     * @throws ForbiddenException
     */
    public static function getAddon($persistence, $id)
    {
        $addon = $persistence->build('Addon')->byId($id);
        if (!$addon) {
            throw new FileNotFoundException();
        }
        if (!$addon->isSubmittedForApproval() && !$addon->isApproved() && !$addon->isRejected()) {
            throw new ForbiddenException();
        }
        return $addon;
    }

    public function get($id)
    {
        $this->security->requireModerator();
        $this->offerIdentification();
        $this->security->requireIdentification();

        $addon = self::getAddon($this->persistence, $id);
        // if not submitted

        $game = $addon->fetchGame();
        $owner = $addon->fetchOwner();

        $this->context['addon'] = $addon->getTitle();
        $this->context['addon_en'] = $addon->getTitle('en');
        $this->context['addon_de'] = $addon->getTitle('de');
        $this->context['user'] = $owner->forPresenter();

        $duplicate = array();
        if ($addon->isApproved()) {
            $this->context['approved'] = true;
            $this->context['namespace'] = $addon->getNamespace();
        } else {
            $this->context['namespace'] = $addon->getProposedShort();
            $duplicate['namespace'] = ($this->persistence->build('Addon')->byShort($addon->getProposedShort())
                !== null);
            $duplicate['title_en'] = count($this->persistence->build('Addon')->all()->byTitle($addon->getTitle('en'),
                        0, 0, 'en')) > 1;
            $duplicate['title_de'] = count($this->persistence->build('Addon')->all()->byTitle($addon->getTitle('de'),
                        0, 0, 'de')) > 1;
        }
        $this->context['duplicate'] = $duplicate;

        $this->context['rejected'] = $addon->isRejected();

        $this->context['game'] = array('title' => $game->getTitle(), 'short' => $game->getShort());
        $this->context['timestamp'] = date($this->localisation->getFormat(LocalisationService::FORMAT_DATETIME),
            $addon->getApprovalSubmit());

        if (!isset($this->context['comment'])) {
{'fraction_non_alphanumeric': 0.1807410193718262, 'fraction_numerical': 0.002256911792364115, 'mean_word_length': 2.856417693981146, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 115, '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': '7546912', 'n_tokens_mistral': 1573, 'n_tokens_neox': 1558, 'n_words': 233}