<commit_before><?php

namespace backend\controllers;

use backend\models\Media;
use common\models\Blog;
use common\models\search\BlogSearch;
use yii\web\NotFoundHttpException;
use yii\web\VerbFilter;
use yii\grid\DataColumn;

/**
 * BlogController implements the CRUD actions for Blog model.
 */
class BlogController extends \yii\web\Controller
{
    public $pageTitle = 'Blog';
    public $pageIcon = 'fa fa-book';

	public function behaviors()
	{
		return [
            'access' => [
                'class' => \yii\web\AccessControl::className(),
                //'only' => ['index', 'create', 'update', 'delete'],
                'rules' => [
                    [
                        'actions' => ['index', 'create', 'update', 'delete'], // Define specific actions
                        'allow' => true, // Has access
                        'roles' => ['admin'], // '@' All logged in users / or your access role e.g. 'admin', 'user'
                    ],
                    [
                        'allow' => false, // Do not have access
                        'roles'=>['?'], // Guests '?'
                    ],
                ],
            ],
			'verbs' => [
				'class' => VerbFilter::className(),
				'actions' => [
					'delete' => ['post'],
				],
			],
		];
	}

	/**
	 * Lists all Blog models.
	 * @return mixed
	 */
	public function actionIndex()
	{
		$searchModel = new BlogSearch;
		$dataProvider = $searchModel->search($_GET);

        $getColumns = [
            ['class' => 'yii\grid\SerialColumn'],
            'title',
            [
                'class' => DataColumn::className(),
                'attribute' => 'authorName',
                'format' => 'text',
                'label' => 'Author',
            ],
            'update_time',
            'publish_time',
            [
                'class' => DataColumn::className(),
                'attribute' => 'statusLabel',
                'format' => 'text',
                'label' => 'Status',
            ],
            ['class' => 'backend\components\ActionColumn'],
        ];

        $meta['title'] = $this->pageTitle;
        $meta['description'] = 'List all posts';
        $meta['pageIcon'] = $this->pageIcon;

		return $this->render('/global/index', [
			'dataProvider' => $dataProvider,
			'searchModel' => $searchModel,
            'meta' => $meta,
            'getColumns' => $getColumns,
		]);
	}

	/**
	 * Creates a new Blog model.
	 * If creation is successful, the browser will be redirected to the 'view' page.
	 * @return mixed
	 */
	public function actionCreate()
	{
		$model = new Blog;

		if ($model->save(false)) {
			return $this->redirect(['update', 'id' => $model->id]);
		}

        return false;
	}

	/**
	 * Updates an existing Blog model.
	 * If update is successful, the browser will be redirected to the 'view' page.
	 * @param string $id
	 * @return mixed
	 */
	public function actionUpdate($id)
	{
		$model = $this->findModel($id);

        $meta['title'] = $this->pageTitle;
        $meta['description'] = 'Update post';
        $meta['pageIcon'] = $this->pageIcon;

        //If any media upload catch it and upload it
        \Yii::$app->kato->mediaUpload($model->id, 'blog');

		if ($model->load($_POST) && $model->save()) {
			return $this->redirect(['update', 'id' => $model->id]);
		} else {
			return $this->render('/global/update', [
				'model' => $model,
                'meta' => $meta,
			]);
		}
	}

	/**
	 * Deletes an existing Blog model.
	 * If deletion is successful, the browser will be redirected to the 'index' page.
	 * @param string $id
	 * @return mixed
	 */<commit_msg>Save media type as model class name<commit_after><?php

namespace backend\controllers;

use backend\models\Media;
use common\models\Blog;
use common\models\search\BlogSearch;
use yii\web\NotFoundHttpException;
use yii\web\VerbFilter;
use yii\grid\DataColumn;

/**
 * BlogController implements the CRUD actions for Blog model.
 */
class BlogController extends \yii\web\Controller
{
    public $pageTitle = 'Blog';
    public $pageIcon = 'fa fa-book';

	public function behaviors()
	{
		return [
            'access' => [
                'class' => \yii\web\AccessControl::className(),
                //'only' => ['index', 'create', 'update', 'delete'],
                'rules' => [
                    [
                        'actions' => ['index', 'create', 'update', 'delete'], // Define specific actions
                        'allow' => true, // Has access
                        'roles' => ['admin'], // '@' All logged in users / or your access role e.g. 'admin', 'user'
                    ],
                    [
                        'allow' => false, // Do not have access
                        'roles'=>['?'], // Guests '?'
                    ],
                ],
            ],
			'verbs' => [
				'class' => VerbFilter::className(),
				'actions' => [
					'delete' => ['post'],
				],
			],
		];
	}

	/**
	 * Lists all Blog models.
	 * @return mixed
	 */
	public function actionIndex()
	{
		$searchModel = new BlogSearch;
		$dataProvider = $searchModel->search($_GET);

        $getColumns = [
            ['class' => 'yii\grid\SerialColumn'],
            'title',
            [
                'class' => DataColumn::className(),
                'attribute' => 'authorName',
                'format' => 'text',
                'label' => 'Author',
            ],
            'update_time',
            'publish_time',
            [
                'class' => DataColumn::className(),
                'attribute' => 'statusLabel',
                'format' => 'text',
                'label' => 'Status',
            ],
            ['class' => 'backend\components\ActionColumn'],
        ];

        $meta['title'] = $this->pageTitle;
        $meta['description'] = 'List all posts';
        $meta['pageIcon'] = $this->pageIcon;

		return $this->render('/global/index', [
			'dataProvider' => $dataProvider,
			'searchModel' => $searchModel,
            'meta' => $meta,
            'getColumns' => $getColumns,
		]);
	}

	/**
	 * Creates a new Blog model.
	 * If creation is successful, the browser will be redirected to the 'view' page.
	 * @return mixed
	 */
	public function actionCreate()
	{
		$model = new Blog;

		if ($model->save(false)) {
			return $this->redirect(['update', 'id' => $model->id]);
		}

        return false;
	}

	/**
	 * Updates an existing Blog model.
	 * If update is successful, the browser will be redirected to the 'view' page.
	 * @param string $id
	 * @return mixed
	 */
	public function actionUpdate($id)
	{
		$model = $this->findModel($id);
        
        $meta['title'] = $this->pageTitle;
        $meta['description'] = 'Update post';
        $meta['pageIcon'] = $this->pageIcon;

        //If any media upload catch it and upload it
        \Yii::$app->kato->mediaUpload($model->id, $model->className());

		if ($model->load($_POST) && $model->save()) {
			return $this->redirect(['update', 'id' => $model->id]);
		} else {
			return $this->render('/global/update', [
				'model' => $model,
                'meta' => $meta,
			]);
		}
	}

	/**
	 * Deletes an existing Blog model.
	 * If deletion is successful, the browser will be redirected to the 'index' page.
	 * @param string $id
	 * @return mixed
	 */
{'fraction_non_alphanumeric': 0.1676031245717418, 'fraction_numerical': 0.0, 'mean_word_length': 1.8891528107680127, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 102, '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': '1198194', 'n_tokens_mistral': 2264, 'n_tokens_neox': 2066, 'n_words': 524}