Blame view

protected/modules/admin/components/I18dRcrudController.php 1.4 KB
a1684257   Administrator   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
  <?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,
                  ));
          }
      }
  }