UserController.php
1.86 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
66
67
68
69
70
71
<?php
/**
* User action handler
*/
class UserController extends WRestController
{
/**
* Define model for the controller
*/
protected $_modelName = "user";
/**
* Determine which of the standard actions will support the controller
*/
public function actions()
{
return array(
'delete' => 'WRestDeleteAction',
'get' => 'WRestGetAction',
'create' => 'WRestCreateAction',
'update' => array(
'class' => 'WRestUpdateAction',
'scenario' => 'update'
)
);
}
public function actionList()
{
$criteria = new CDbCriteria();
$model = $this->getModel();
$criteria->alias = 'user';
$criteria->limit = (int)(($limit = Yii::app()->request->getParam('limit')) ? $limit : -1);
$page = (int)Yii::app()->request->getParam('page') - 1;
$criteria->offset = ($offset = $limit * $page) ? $offset : 0;
if(($order = Yii::app()->request->getParam("sort")) ? $order : null) {
$order = json_decode($order);
$sort = array();
foreach($order as $item) {
$sort[] = sprintf("user.%s %s", $item->property, $item->direction);
}
$criteria->order = implode(", ", $sort);
}
$models = $model->with('transport')->findAll($criteria);
if ($models) {
foreach ($models as $item) {
$result[] = array_merge($item->getAllAttributes(), array("domain" => $item->transport->domain));
}
}
$result = array_merge($result, array(
'total' => $model->count($criteria)
));
$this->sendResponse(200, $result);
}
}