-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathRGridViewAction.php
More file actions
65 lines (56 loc) · 1.3 KB
/
RGridViewAction.php
File metadata and controls
65 lines (56 loc) · 1.3 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
/**
* RGridViewAction class file.
*
* @author Slava Rudnev <slava.rudnev@gmail.com>
* @link https://github.com/RSol/RGridView
*/
/**
* RGridViewAction store the ordered models.
*
* To use RGridViewAction add it in your controller:
* <pre>
* public function actions()
* {
* return array(
* 'order' => array(
* 'class' => 'ext.RGridView.RGridViewAction',
* 'model' => 'Model',
* 'orderField' => 'order',
* ),
* );
* }
* </pre>
*
* Additional
*
* @author Slava Rudnev <slava.rudnev@gmail.com>
* @version 0.1
*/
class RGridViewAction extends CAction
{
public $model = 'Model';
public $orderField = 'order';
public function run()
{
$ansver = array('msg'=>'Data not sended');
if(isset($_POST['Order']))
{
$models = explode(',', $_POST['Order']);
$models = array_filter($models);
$orderModel = CActiveRecord::model($this->model);
foreach($models as $order => $id)
{
Yii::app()->db->createCommand()
->update($orderModel->tableName(), array(
$this->orderField =>$order,
), $orderModel->getMetaData()->tableSchema->primaryKey.'=:range_id', array(
':range_id' => $id,
));
}
$ansver = array('msg'=>'Ok');
}
echo CJSON::encode($ansver);
Yii::app()->end();
}
}