CWIS Developer Documentation

- Home
- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

Privilege.php
Go to the documentation of this file.
1 <?PHP
2
3 #
4 # FILE: Privilege.php
5 #
6 # Part of the Collection Workflow Integration System (CWIS)
7 # Copyright 2007-2013 Edward Almasy and Internet Scout Research Group
8 # http://scout.wisc.edu/cwis/
9 #
10
15 class Privilege
16 {
17
18 # ---- PUBLIC INTERFACE --------------------------------------------------
19
22
29 public function __construct($Id, $Name = NULL)
30 {
31 global $G_PrivDescriptions;
32
33 # if caller requested creation of new entry
34 if ($Id === NULL)
35 {
36 # get highest current ID
37 $DB = new Database();
38 $HighestId = $DB->Query("SELECT Id FROM CustomPrivileges"
39 ." ORDER BY Id DESC LIMIT 1", "Id");
40
41 # select new ID
42 $this->Id = max(100, ($HighestId + 1));
43
44 # add new entry to database
45 $DB->Query("INSERT INTO CustomPrivileges (Id, Name)"
46 ." VALUES (".$this->Id.", '".addslashes($Name)."')");
47 $this->Name = $Name;
48 }
49 else
50 {
51 # save ID
52 $this->Id = intval($Id);
53
54 # if ID indicates predefined privilege
55 if ($this->IsPredefined())
56 {
57 # load privilege info from predefined priv array
58 $this->Name = $G_PrivDescriptions[$this->Id];
59 }
60 else
61 {
62 # load privilege info from database
63 $DB = new Database();
64 $this->Name = $DB->Query("SELECT Name FROM CustomPrivileges"
65 ." WHERE Id = ".$this->Id, "Name");
66 }
67 }
68 }
69
74 public function Delete()
75 {
76 if (!$this->IsPredefined())
77 {
78 $DB = new Database();
79 $DB->Query("DELETE FROM CustomPrivileges"
80 ." WHERE Id = ".$this->Id);
81 }
82 }
83
88
90 public function Id()
91 {
92 return $this->Id;
93 }
94
100 public function Name($NewValue = NULL)
101 {
102 if (($NewValue !== NULL) && !$this->IsPredefined())
103 {
104 $DB = new Database();
105 $DB->Query("UPDATE CustomPrivileges"
106 ." SET Name = '".addslashes($NewValue)."'"
107 ." WHERE Id = ".$this->Id);
108 $this->Name = $NewValue;
109 }
110 return $this->Name;
111 }
112
119 public function IsPredefined($Id = NULL)
120 {
121 if ($Id === NULL)
122 {
123 $Id = $this->Id;
124 }
125 return (($Id > 0) && ($Id < 100)) ? TRUE : FALSE;
126 }
127
130 # ---- PRIVATE INTERFACE -------------------------------------------------
131
132 private $Id;
133 private $Name;
134 }
Privilege
User rights management framework allowing custom privege definition.
Definition: Privilege.php:15
Privilege\__construct
__construct($Id, $Name=NULL)
Object Constructor Pass in a value for the name and a NULL id to make a new privilege.
Definition: Privilege.php:29
Database
SQL database abstraction object with smart query caching.
Definition: Database.php:22
Privilege\Delete
Delete()
Delete this privelege from the DB NOTE: the object should not be used after calling this...
Definition: Privilege.php:74
PHP
PHP
Definition: RSSClient--Test.php:12
Privilege\IsPredefined
IsPredefined($Id=NULL)
Report whether privilege is predefined or custom Can be called as Privilege::IsPredefind(ID) ...
Definition: Privilege.php:119
Privilege\Name
Name($NewValue=NULL)
Get or set Name.
Definition: Privilege.php:100
Privilege\Id
Id()
Get Id.
Definition: Privilege.php:90