<?php

class I18dRcrudController extends I18dCrudController
{
    public $actionsMenu;
    public $layout = 'crud_layout';
    public $defaultAction = 'admin';

    public $labels = array(
        'admin' => 'Управление',
        'create' => 'Добавить',
        'update' => 'Редактировать',
        'order' => 'Упорядочить',
    );

    public $modelName;
    public $i18ModelName;


    public function actionOrder()
    {
        if (Yii::app()->request->isPostRequest && isset($_POST['Order'])) {
            if ($_POST['Order'] != 'none') {
                $models = explode(',', $_POST['Order']);
                for ($i = 0; $i < sizeof($models); $i++) {
                    if ($model = $this->loadModel($models[$i])) {
                        $model->rank = $i;
                        $model->save();
                    }
                }
            }
            $this->redirect(array('admin'));
        }
        else {
            $dataProvider = new CActiveDataProvider(
                $this->modelName,
                array(
                    'pagination' => false,
                    'criteria' => array(
                        'order' => '`rank` ASC, id DESC',
                    ),
                ));
            $this->render(
                'order',
                array(
                    'dataProvider' => $dataProvider,
                ));
        }
    }
}
