<commit_before><?php

    namespace papalapa\yiistart\controllers;

    use yii\base\Model;
    use yii\db\ActiveRecord;
    use yii\filters\AccessControl;
    use yii\filters\VerbFilter;
    use yii\helpers\Html;
    use yii\web\BadRequestHttpException;
    use yii\web\Controller;
    use yii\web\ForbiddenHttpException;
    use yii\web\NotFoundHttpException;

    /**
     * Class ManageController
     * @package papalapa\yiistart\controllers
     */
    abstract class ManageController extends Controller
    {
        /**
         * Default active record model class
         * @var ActiveRecord
         */
        protected $model;
        /**
         * Default active record search model class
         * @var ActiveRecord
         */
        protected $searchModel;
        /**
         * Permissions array
         * @var array
         */
        protected $permissions = [
            'create' => null,
            'view'   => null,
            'update' => null,
            'index'  => null,
            'delete' => null,
        ];
        /**
         * Scenarios of actions
         * @var array
         */
        protected $scenarios = [
            'create' => Model::SCENARIO_DEFAULT,
            'view'   => Model::SCENARIO_DEFAULT,
            'update' => Model::SCENARIO_DEFAULT,
            'index'  => Model::SCENARIO_DEFAULT,
            'delete' => Model::SCENARIO_DEFAULT,
        ];

        /**
         * @inheritdoc
         */
        public function behaviors()
        {
            return [
                'verbs'  => [
                    'class'   => VerbFilter::className(),
                    'actions' => [
                        'index'  => ['get'],
                        'view'   => ['get'],
                        'create' => ['get', 'post'],
                        'update' => ['get', 'put', 'post'],
                        'delete' => ['post', 'delete'],
                    ],
                ],
                'access' => [
                    'class' => AccessControl::className(),
                    'only'  => ['index', 'view', 'create', 'update', 'delete'],
                    'rules' => [
                        [
                            'allow' => true,
                            'roles' => ['manager', 'admin', 'developer'],
                        ],
                        [
                            'allow'        => false,
                            'roles'        => [],
                            'denyCallback' => function ($rule, $action) {
                                $this->deniedError();
                            },
                        ],
                    ],
                ],
            ];
        }

        /**
         * Lists all models.
         * @return string
         * @throws ForbiddenHttpException
         */
        public function actionIndex()
        {
            if (!\Yii::$app->user->can($this->permissions['index'])) {
                throw new ForbiddenHttpException('У вас недостаточно прав на просмотр');
            }

            /* @var $searchModel ActiveRecord */
            $searchModel  = new $this->searchModel;
            $dataProvider = $searchModel->search(\Yii::$app->request->queryParams);

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

        /**
         * Displays a single model.
         * @param $id
         * @return string
         * @throws ForbiddenHttpException
         * @throws NotFoundHttpException<commit_msg>Manage controller<commit_after><?php

    namespace papalapa\yiistart\controllers;

    use yii\base\Model;
    use yii\db\ActiveRecord;
    use yii\filters\AccessControl;
    use yii\filters\VerbFilter;
    use yii\helpers\Html;
    use yii\web\BadRequestHttpException;
    use yii\web\Controller;
    use yii\web\ForbiddenHttpException;
    use yii\web\NotFoundHttpException;

    /**
     * Class ManageController
     * @package papalapa\yiistart\controllers
     */
    abstract class ManageController extends Controller
    {
        /**
         * Default active record model class
         * @var ActiveRecord
         */
        protected $model;
        /**
         * Default active record search model class
         * @var ActiveRecord
         */
        protected $searchModel;
        /**
         * Permissions array
         * @var array
         */
        protected $permissions = [
            'create' => null,
            'view'   => null,
            'update' => null,
            'index'  => null,
            'delete' => null,
        ];
        /**
         * Scenarios of actions
         * @var array
         */
        protected $scenarios = [
            'create' => Model::SCENARIO_DEFAULT,
            'view'   => Model::SCENARIO_DEFAULT,
            'update' => Model::SCENARIO_DEFAULT,
            'index'  => Model::SCENARIO_DEFAULT,
            'delete' => Model::SCENARIO_DEFAULT,
        ];

        /**
         * @inheritdoc
         */
        public function behaviors()
        {
            return [
                'verbs'  => [
                    'class'   => VerbFilter::className(),
                    'actions' => [
                        'index'  => ['get'],
                        'view'   => ['get'],
                        'create' => ['get', 'post'],
                        'update' => ['get', 'put', 'post'],
                        'delete' => ['post', 'delete'],
                    ],
                ],
                'access' => [
                    'class' => AccessControl::className(),
                    'only'  => ['index', 'view', 'create', 'update', 'delete'],
                    'rules' => [
                        [
                            'allow' => true,
                            'roles' => ['manager', 'admin', 'developer'],
                        ],
                        [
                            'allow'        => false,
                            'roles'        => [],
                            'denyCallback' => function ($rule, $action) {
                                return $this->deniedError();
                            },
                        ],
                    ],
                ],
            ];
        }

        /**
         * Lists all models.
         * @return string
         * @throws ForbiddenHttpException
         */
        public function actionIndex()
        {
            if (!\Yii::$app->user->can($this->permissions['index'])) {
                throw new ForbiddenHttpException('У вас недостаточно прав на просмотр');
            }

            /* @var $searchModel ActiveRecord */
            $searchModel  = new $this->searchModel;
            $dataProvider = $searchModel->search(\Yii::$app->request->queryParams);

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

        /**
         * Displays a single model.
         * @param $id
         * @return string
         * @throws ForbiddenHttpException
         * @throws NotFoundHttpException
{'fraction_non_alphanumeric': 0.12709124138900604, 'fraction_numerical': 0.0, 'mean_word_length': 1.1708880073237717, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 79, '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': '2953799', 'n_tokens_mistral': 1828, 'n_tokens_neox': 1785, 'n_words': 351}