16 public static function model($className = __CLASS__)
28 return 'users_sites_rights';
43 foreach ($dataProvider[
"itemsList"][0][
"itemObject"] as $item) {
47 foreach ($sites as $site) {
48 $ids[
'sites'][] = $site[
'id'];
49 $ids[
'users'][] = $site[
'userId'];
54 $usersSitesRights = $this->findAllByAttributes(array(
55 'Site_Id' => $ids[
'sites'],
'User_Id' => $ids[
'users'], )
57 foreach ($sites as &$site) {
58 $site[
'Rights'] = array();
59 foreach ($usersSitesRights as $userSiteRight) {
60 if ($site[
'id'] == $userSiteRight->Site_Id &&
61 $site[
'userId'] == $userSiteRight->User_Id) {
62 $site[
'Rights'] = $userSiteRight->Rights;
65 if (!empty($params[
'rights']) && !array_intersect($params[
'rights'], $site[
'Rights'])) {
70 return array_filter($sites);
82 $json = json_encode($criterions);
84 $path = Yii::app()->getBasePath().
'/json_temp/';
85 $file = fopen($path.$params[
'userId'].
'_request.json',
'w');
98 $api = Yii::app()->params[
'api'];
99 $path = Yii::app()->getBasePath().
'/shell/';
100 $pathJson = Yii::app()->getBasePath().
'/json_temp/';
101 $cmd =
"sh ".$path.
"site_find_by_criterions.sh $api $pathJson $userId";
102 $json = shell_exec($cmd);
103 $file = fopen($pathJson.$userId.
'_response.json',
'w');
104 fwrite($file,
$json);
119 $path = Yii::app()->getBasePath().
'/json_temp/';
121 return file_get_contents($path.$userId.
'_response.json');
134 if (empty($records)) {
137 foreach ($records as $record) {
158 if (empty($params[
'siteId']) ||
159 empty($params[
'userId']) ||
160 (!isset($params[
'rights']) &&
164 if (empty($params[
'conditions'])) {
165 $params[
'conditions'] =
'User_Id = :userId AND Site_Id = :siteId';
167 if (empty($params[
'params'])) {
168 $params[
'params'] = array(
169 ':siteId' => $params[
'siteId'],
170 ':userId' => $params[
'userId'],
173 if (!empty($autoSet)) {
176 if (!empty($params[
'rights'])) {
177 $rightsBitMask = $this->createBitMask(
178 $params[
'rights'], $this->statesData
180 $isExists = $this->findAll($params[
'conditions'], $params[
'params']);
181 if (!empty($isExists)) {
182 if (!empty($autoSet)) {
185 $result = $this->updateAll(
186 array(
'Rights' => $rightsBitMask),
187 $params[
'conditions'],
194 $model->Site_Id = $params[
'siteId'];
195 $model->User_Id = $params[
'userId'];
196 $model->Rights = $rightsBitMask;
197 $result = $model->save();
200 $result = $this->deleteAll(
201 $params[
'conditions'], $params[
'params']
217 return base64_encode(serialize(
$data));
229 return unserialize(base64_decode(
$data));
241 if (!empty($params[
'rights'])) {
242 if (strpos($params[
'rights'],
',') !==
false) {
243 $params[
'rights'] = explode(
',', $params[
'rights']);
245 $params[
'rights'] = (array) $params[
'rights'];
247 foreach ($params[
'rights'] as &$right) {
251 if (!empty($params[
'currentPage']) && $params[
'currentPage'] >= 2) {
252 $currentPage = $params[
'currentPage'] * $params[
'pageSize'];
253 $params[
'limit'] = array(
254 ($currentPage - $params[
'pageSize']),
258 if (empty($params[
'limit'])) {
259 $params[
'limit'] = array(0, ($params[
'pageSize'] + 1));
276 'id',
'siteId',
'Id',
'Site_Id',
281 $rights = (!empty($rights[$siteId]) ? $rights[$siteId] : array());
311 'url' =>
"http://%$pattern%",
312 'criterions' => array(
313 "ORDER BY" =>
"CDate ASC",
316 if (!empty($searchUserId)) {
317 $criterions[
'criterions'][
'WHERE'][
'AND'][] =
"`User_Id`=$searchUserId";
319 if (!empty($siteId)) {
320 $criterions[
'criterions'][
'WHERE'][
'AND'][] =
"`Site_Id`=\"$siteId\"";
322 if (!empty($limit)) {
323 $criterions[
'criterions'][
'LIMIT'] = implode(
', ', $limit);
325 if (!empty($criterions[
'criterions'][
'WHERE'][
'AND'])) {
326 $criterions[
'criterions'][
'WHERE'] = implode(
' AND ', $criterions[
'criterions'][
'WHERE'][
'AND']);