<commit_before><?php

namespace app\controllers;

use app\models\forms\PostForm;
use Yii;
use yii\helpers\ArrayHelper;
use yii\web\NotFoundHttpException;
use app\helpers\MarkdownParser;
use app\models\Post;
use app\models\Topic;

/**
 * Class PostController
 */
class PostController extends \app\components\BaseController
{
    /**
     * @param $id
     * @return string
     */
    public function actionView($id)
    {
        /** @var Post $post */
        $post = Post::findOne(['id' => $id]);

        /** @var Topic $topic */
        $topic = Topic::find()
            ->where(['id' => $post->topic_id])
            ->with('forum')
            ->one();

        $dataProvider = Post::getDataProviderByTopic($topic->id);
        $dataProvider->pagination->route = 'topic/view';
        $dataProvider->pagination->params = [
            'id' => $topic->id,
            'page' => $this->getPostPage($post),
        ];

        $posts = $dataProvider->getModels();

        $model = new PostForm();

        return $this->render('/topic/view', [
            'dataProvider' => $dataProvider,
            'model' => $model,
            'topic' => $topic,
            'posts' => $posts,
        ]);
    }

    /**
     * @return string
     */
    public function actionMention()
    {
        if (Yii::$app->getRequest()->getIsAjax()) {
            Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;

            $id = substr(Yii::$app->getRequest()->post('id'), 1);

            $posts = Post::find()
                ->with('user')
                ->where(['topic_id' => $id])
                ->asArray()
                ->all();

            $users = ArrayHelper::getColumn($posts, 'user');
            $usernames = array_unique(ArrayHelper::getColumn($users, 'username'));
            $usernames = array_values($usernames);

            return $usernames;
        }

        throw new NotFoundHttpException();
    }

    /**
     * @return string
     */
    public function actionPreview()
    {
        if (Yii::$app->getRequest()->getIsAjax()) {
            Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;

            $text = Yii::$app->getRequest()->post('message');
            if ($text == '') {
                return 'Пустое сообщение.';
            }

            $parsedown = new MarkdownParser();

            return $parsedown->parse($text);
        }
<commit_msg>Remove self username from mention popup<commit_after><?php

namespace app\controllers;

use app\models\forms\PostForm;
use Yii;
use yii\helpers\ArrayHelper;
use yii\web\NotFoundHttpException;
use app\helpers\MarkdownParser;
use app\models\Post;
use app\models\Topic;

/**
 * Class PostController
 */
class PostController extends \app\components\BaseController
{
    /**
     * @param $id
     * @return string
     */
    public function actionView($id)
    {
        /** @var Post $post */
        $post = Post::findOne(['id' => $id]);

        /** @var Topic $topic */
        $topic = Topic::find()
            ->where(['id' => $post->topic_id])
            ->with('forum')
            ->one();

        $dataProvider = Post::getDataProviderByTopic($topic->id);
        $dataProvider->pagination->route = 'topic/view';
        $dataProvider->pagination->params = [
            'id' => $topic->id,
            'page' => $this->getPostPage($post),
        ];

        $posts = $dataProvider->getModels();

        $model = new PostForm();

        return $this->render('/topic/view', [
            'dataProvider' => $dataProvider,
            'model' => $model,
            'topic' => $topic,
            'posts' => $posts,
        ]);
    }

    /**
     * @return string
     */
    public function actionMention()
    {
        if (Yii::$app->getRequest()->getIsAjax()) {
            Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;

            $id = substr(Yii::$app->getRequest()->post('id'), 1);

            $posts = Post::find()
                ->with('user')
                ->where(['topic_id' => $id])
                ->asArray()
                ->all();

            $users = ArrayHelper::getColumn($posts, 'user');
            $usernames = array_unique(ArrayHelper::getColumn($users, 'username'));

            $key = array_search(Yii::$app->getUser()->getIdentity()->username, $usernames);
            if (is_array($usernames) && (isset($usernames[$key]) || array_key_exists($key, $usernames))) {
                unset($usernames[$key]);
            }

            $usernames = array_values($usernames);

            return $usernames;
        }

        throw new NotFoundHttpException();
    }

    /**
     * @return string
     */
    public function actionPreview()
    {
        if (Yii::$app->getRequest()->getIsAjax()) {
            Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;

            $text = Yii::$app->getRequest()->post('message');
            if ($text == '') {
                return 'Пустое сообщение.';
            }

            $parsedown = new MarkdownParser();

            return $parsedown->parse($text);
        }

{'fraction_non_alphanumeric': 0.17255594817432274, 'fraction_numerical': 0.00039261876717707107, 'mean_word_length': 1.9332181922855498, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 84, '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': '5806408', 'n_tokens_mistral': 1515, 'n_tokens_neox': 1492, 'n_words': 258}