source: branches/mvc/Application/Model/Permission.php

Last change on this file was 47, checked in by chronos, 10 years ago
  • Odstraněno: Zbytečná PHP ukončovací značka "?>" z konce všech souborů.
  • Property svn:executable set to *
File size: 1.8 KB
Line 
1<?php
2
3class Permission extends Model
4{
5 function LoadForUser($User)
6 {
7 $Result = array();
8 $DbResult = $this->Database->query('SELECT * FROM `PermissionAssignment` WHERE `User`='.$User);
9 while($DbRow = $DbResult->fetch_assoc())
10 {
11 if($DbRow['SubGroup'] > 0) $Result = array_merge($Result, $this->LoadForGroup($DbRow['SubGroup']));
12 if($DbRow['Operation'] > 0)
13 {
14 $DbResult2 = $this->Database->query('SELECT `PermissionOperation`.*, `Module`.`Name` FROM `PermissionOperation` JOIN `Module` ON `Module`.`Id` = `PermissionOperation`.`Module` WHERE `PermissionOperation`.`Id`='.$DbRow['Operation']);
15 $DbRow2 = $DbResult2->fetch_assoc();
16 $Result[$DbRow2['Name']][$DbRow2['Action']][$DbRow2['Item']] = true;
17 }
18 }
19 $this->Data = $Result;
20 }
21
22 function LoadForGroup($Group)
23 {
24 $Result = array();
25 $DbResult = $this->Database->query('SELECT * FROM `PermissionAssignment` WHERE `Group`='.$Group);
26 while($DbRow = $DbResult->fetch_assoc())
27 {
28 if($DbRow['SubGroup'] > 0) $Result = array_merge($Result, $this->LoadForGroup($DbRow['SubGroup']));
29 if($DbRow['Operation'] > 0)
30 {
31 $DbResult2 = $this->Database->query('SELECT `PermissionOperation`.*, `Module`.`Name` FROM `PermissionOperation` JOIN `Module` ON `Module`.`Id` = `PermissionOperation`.`Module` WHERE `PermissionOperation`.`Id`='.$DbRow['Operation']);
32 $DbRow2 = $DbResult2->fetch_assoc();
33 $Result[$DbRow2['Name']][$DbRow2['Action']][$DbRow2['Item']] = true;
34 }
35 }
36 return($Result);
37 }
38
39 function Check($Module, $Action, $Item = 0)
40 {
41 if(array_key_exists($Module, $this->Data) and array_key_exists($Action, $this->Data[$Module]) and array_key_exists($Item, $this->Data[$Module][$Action])) $Result = true;
42 else $Result = false;
43 return($Result);
44 }
45}
Note: See TracBrowser for help on using the repository browser.