<commit_before><?php

namespace frontend\controllers;

use Yii;
use common\models\Goods;
use frontend\models\Goodssearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;

/**
 * GoodsController implements the CRUD actions for Goods model.
 */
class GoodsController extends Controller
{
    public function behaviors()
    {
        return [
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'delete' => ['post'],
                ],
            ],
        ];
    }

    /**
     * Lists all Goods models.
     * @return mixed
     */
    public function actionIndex($idcat)
    {

        $searchModel = new Goodssearch();
        $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
        $model=Goods::find()->where(['idcat' => $idcat])->all();
        $catname=Goods::getCatnamebyid($idcat);
        return $this->render('index', [
            'searchModel' => $searchModel,
            'dataProvider' => $dataProvider,
            'model' => $model,
            'idcat' => $idcat,
            'catname' => $catname,
        ]);
    }

    /**
     * Displays a single Goods model.
     * @param integer $id
     * @return mixed
     */
    public function actionView($id)
    {
        $model = $this->findModel($id);
        $catname=Goods::getCatnamebyid($model->idcat);    
        return $this->render('view', [
            'model' => $model,
            'catname' => $catname,
        ]);
    }

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

        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            return $this->redirect(['view', 'id' => $model->id]);
        } else {
            return $this->render('create', [
                'model' => $model,
            ]);
        }
    }

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

        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            return $this->redirect(['view', 'id' => $model->id]);
        } else {
            return $this->render('update', [
                'model' => $model,
            ]);
        }
    }

    /**
     * Deletes an existing Goods model.
     * If deletion is successful, the browser will be redirected to the 'index' page.
     * @param integer $id
     * @return mixed
     */
    public function actionDelete($id)
    {
        $this->findModel($id)->delete();

        return $this->redirect(['index']);
    }

    /**
     * Finds the Goods model based on its primary key value.
     * If the model is not found, a 404 HTTP exception will be thrown.
     * @param integer $id
     * @return Goods the loaded model
     * @throws NotFoundHttpException if the model cannot be found
     */
    protected function findModel($id)
    {
        if (($model = Goods::findOne($id)) !== null) {
            return $model;
        } else {
            throw new NotFoundHttpException('The requested page does not exist.');
        }
    }

    public function actionAddtodiff($userid)
    {

       $b= Yii::$app->session->get('goodsForDiff');
       if (!in_array($userid, $b)){
           $b[] = $userid;
           Yii::$app->session->set('goodsForDiff', $b);
       }    
       $success=true;
       return "Добавлено для сравнения";
      
    }

    public function actionDiff()
    {
        $searchModel = new Goodssearch();
        $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
        $gfd= Yii::$app->session->get('goodsForDiff');
        $model=Goods::find()->where(['id' => $gfd])->all();<commit_msg>beta 0.2 (change sitecontroller) point make image branch<commit_after><?php

namespace frontend\controllers;

use Yii;
use common\models\Goods;
use frontend\models\Goodssearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;

/**
 * GoodsController implements the CRUD actions for Goods model.
 */
class GoodsController extends Controller
{
    public function behaviors()
    {
        return [
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'delete' => ['post'],
                ],
            ],
        ];
    }

    /**
     * Lists all Goods models.
     * @return mixed
     */
    public function actionIndex($idcat)
    {

        $searchModel = new Goodssearch();
        $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
        $model=Goods::find()->where(['idcat' => $idcat])->all();
        $catname=Goods::getCatnamebyid($idcat);
        return $this->render('index', [
            'searchModel' => $searchModel,
            'dataProvider' => $dataProvider,
            'model' => $model,
            'idcat' => $idcat,
            'catname' => $catname,
        ]);
    }

    /**
     * Displays a single Goods model.
     * @param integer $id
     * @return mixed
     */
    public function actionView($id)
    {
        $model = $this->findModel($id);
        $catname=Goods::getCatnamebyid($model->idcat);    
        return $this->render('view', [
            'model' => $model,
            'catname' => $catname,
        ]);
    }

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

        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            return $this->redirect(['view', 'id' => $model->id]);
        } else {
            return $this->render('create', [
                'model' => $model,
            ]);
        }
    }

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

        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            return $this->redirect(['view', 'id' => $model->id]);
        } else {
            return $this->render('update', [
                'model' => $model,
            ]);
        }
    }

    /**
     * Deletes an existing Goods model.
     * If deletion is successful, the browser will be redirected to the 'index' page.
     * @param integer $id
     * @return mixed
     */
    public function actionDelete($id)
    {
        $this->findModel($id)->delete();

        return $this->redirect(['index']);
    }

    /**
     * Finds the Goods model based on its primary key value.
     * If the model is not found, a 404 HTTP exception will be thrown.
     * @param integer $id
     * @return Goods the loaded model
     * @throws NotFoundHttpException if the model cannot be found
     */
    protected function findModel($id)
    {
        if (($model = Goods::findOne($id)) !== null) {
            return $model;
        } else {
            throw new NotFoundHttpException('The requested page does not exist.');
        }
    }

    public function actionAddtodiff($userid)
    {

       $b= Yii::$app->session->get('goodsForDiff');
       if (count($b)>0) {
           if (!in_array($userid, $b)){
               $b[] = $userid;
               Yii::$app->session->set('goodsForDiff', $b);
           }    
       } else {
               $b[] = $userid;
               Yii::$app->session->set('goodsForDiff', $b);
       }  
       $success=true;
       return "Добавлено для сравнения";
      
    }

    public function actionDiff()
    {
        $searchModel = new Goodssearch();
        $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
        $gfd= Yii::$app->session->get('goodsForDiff');
        $model=Goods::find()->where(['id' => $gfd])->all();
{'fraction_non_alphanumeric': 0.15351993214588636, 'fraction_numerical': 0.0010905125408942203, 'mean_word_length': 1.947857142857143, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 116, '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': '1997740', 'n_tokens_mistral': 2455, 'n_tokens_neox': 2424, 'n_words': 577}