HCE Project DC service web UI  0.2
Hierarchical Cluster Engine DC service web UI
 All Classes Namespaces Files Functions Variables Pages
UsersSitesRightsController.php
Go to the documentation of this file.
1 <?php
3 {
7  private $_authorizer;
8 
12  public function init()
13  {
14  $this->_authorizer = $this->module->getAuthorizer();
15  $this->layout = $this->module->layout;
16  $this->defaultAction = 'index';
17 
18  // Register the scripts
19  $this->module->registerScripts();
20  }
21 
25  public function filters()
26  {
27  return array('accessControl');
28  }
29 
36  public function accessRules()
37  {
38  return array(
39  array('allow', // Allow superusers to access Rights
40  'actions' => array(
41  'index', 'search', 'update', 'edit', 'editOperationsFields',
42  ),
43  'users' => $this->_authorizer->getSuperusers(),
44  ),
45  array('deny', // Deny all users
46  'users' => array('*'),
47  ),
48  );
49  }
50 
51  public $log;
52 
56  public function actionIndex()
57  {
58  Logger::log('');
59  $data = array();
60  $model = new SitesView();
61  $this->log = Logger::getTrace();
62  $this->render('index', array('dataProvider' => $data,
63  'log' => $this->log,
64  ));
65  }
66 
70  public function actionSearch($pattern, $siteId, $searchUserId, $rights, $pageSize, $currentPage = 0)
71  {
72  $userId = Yii::app()->user->id;
73  $model = new UsersSitesRights();
74 
75  $params = $model->buildFindParams(compact(
76  'userId',
77  'pattern',
78  'siteId',
79  'searchUserId',
80  'limit',
81  'currentPage',
82  'pageSize'
83  ));
84 
85  $model->createRequest($params);
86  $sites = $model->search($params);
87  $itemsProvider = new CArrayDataProvider($sites, array(
88  'pagination' => array(
89  'pageSize' => $pageSize,
90  ),
91  ));
92 
93  $pages = new CPagination(1000000000);
94  $pages->pageVar = 'currentPage';
95 
96  $this->log = Logger::getTrace();
97  $this->render('search', array(
98  'model' => $model,
99  'sites' => $model->encode($sites),
100  'itemsProvider' => $itemsProvider,
101  'pages' => $pages,
102  'currentPage' => $currentPage,
103  'pageSize' => $pageSize,
104  'log' => $this->log,
105  ));
106  }
107 
111  public function actionUpdate()
112  {
113  $sites = Yii::app()->request->getPost('sites');
114  $rights = Yii::app()->request->getPost('Rights');
115 
116  $model = new UsersSitesRights();
117  $model->setRightsAllRecords($model->decode($sites), $rights);
118 
119  Yii::app()->user->setFlash($this->module->flashSuccessKey, 'Update success');
120  $this->redirect(Yii::app()->request->urlReferrer);
121  }
122 
129  public function actionEdit($siteId, $userId)
130  {
131  $model = new UsersSitesRights();
132  $site = $model->findByAttributes(array(
133  'Site_Id' => $siteId, 'User_Id' => $userId,
134  ));
135  if (empty($site)) {
136  $site = compact('siteId', 'userId');
137  }
138  $this->render('edit', array(
139  'siteId' => $siteId,
140  'userId' => $userId,
141  'site' => $site,
142  'model' => $model,
143  'sites' => $model->encode(array($site)),
144  ));
145  }
146 
150  public function actionEditOperationsFields()
151  {
152  $model = new UsersSitesRights();
153  if (Yii::app()->request->isPostRequest) {
154  $rightsList = Yii::app()->getRequest()->getPost('RightsList');
155  $model->setRightsList($rightsList);
156  }
157  $rightsList = $model->getRightsList();
158  $this->render('editOperationsFields', compact('model', 'rightsList'));
159  }
160 }