<commit_before><?php
/**
 * @link https://github.com/himiklab/yii2-sortable-grid-view-widget
 * @copyright Copyright (c) 2014 HimikLab
 * @license http://opensource.org/licenses/MIT MIT
 */

namespace himiklab\sortablegrid;

use yii\base\Action;
use yii\base\InvalidConfigException;
use yii\web\BadRequestHttpException;

/**
 * Action for sortable Yii2 GridView widget.
 *
 * For example:
 *
 * ```php
 * public function actions()
 * {
 *    return [
 *       'sort' => [
 *          'class' => SortableGridAction::className(),
 *          'modelName' => Model::className(),
 *       ],
 *   ];
 * }
 * ```
 *
 * @author HimikLab
 * @package himiklab\sortablegrid
 */
class SortableGridAction extends Action
{
    public $modelName;

    public function run()
    {
        if (!isset($_POST['items']) || !is_array($_POST['items'])) {
            throw new BadRequestHttpException('POST param `items` isn`t set');
        }

        /** @var \yii\db\ActiveRecord $model */
        $model = new $this->modelName;
        if (!$model->hasMethod('gridSort', true)) {
            throw new InvalidConfigException("Not found right `SortableGridBehavior` behavior in `{$this->modelName}`");
        }

        $model->gridSort($_POST['items']);
    }
}<commit_msg>use framework wrapper for POST data<commit_after><?php
/**
 * @link https://github.com/himiklab/yii2-sortable-grid-view-widget
 * @copyright Copyright (c) 2014 HimikLab
 * @license http://opensource.org/licenses/MIT MIT
 */

namespace himiklab\sortablegrid;

use Yii;
use yii\base\Action;
use yii\base\InvalidConfigException;
use yii\web\BadRequestHttpException;

/**
 * Action for sortable Yii2 GridView widget.
 *
 * For example:
 *
 * ```php
 * public function actions()
 * {
 *    return [
 *       'sort' => [
 *          'class' => SortableGridAction::className(),
 *          'modelName' => Model::className(),
 *       ],
 *   ];
 * }
 * ```
 *
 * @author HimikLab
 * @package himiklab\sortablegrid
 */
class SortableGridAction extends Action
{
    public $modelName;

    public function run()
    {
        if ($items = Yii::$app->request->post('items')) {
            throw new BadRequestHttpException('POST param `items` isn`t set');
        }

        /** @var \yii\db\ActiveRecord $model */
        $model = new $this->modelName;
        if (!$model->hasMethod('gridSort', true)) {
            throw new InvalidConfigException("Not found right `SortableGridBehavior` behavior in `{$this->modelName}`");
        }

        $model->gridSort($items);
    }
}
{'fraction_non_alphanumeric': 0.15749901068460626, 'fraction_numerical': 0.004748713889988128, 'mean_word_length': 2.8773006134969323, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, 'https://': 2, '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': '6306241', 'n_tokens_mistral': 789, 'n_tokens_neox': 779, 'n_words': 165}