Subversion Repositories php_users

Rev

Rev 19 | Rev 21 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 19 Rev 20
Line 46... Line 46...
46
 * 
46
 * 
47
 */
47
 */
48
 
48
 
49
class UsersPermissions extends Users {
49
class UsersPermissions extends Users {
50
   
50
   
-
 
51
   /**
-
 
52
    * Extends Users::_construct
-
 
53
    * 
-
 
54
    * Adds additional fields needed for permissions. However, this
-
 
55
    * information is not actually used in the code, but is included here
-
 
56
    * for documentation and/or possible extensions
-
 
57
    * 
-
 
58
    * @param string[] $customFields Array of definition modifications to underlying structure
-
 
59
    */
51
   public function __construct( $customFields = array() ) {
60
   public function __construct( $customFields = array() ) {
-
 
61
      $permissions = array();
-
 
62
      $this->configuration = array_merge_recursive( $this->configuration, $permissions );
52
      parent::__construct( $customFields );
63
      parent::__construct( $customFields );
53
   } // constructor
64
   } // constructor
54
   
65
   
55
   
66
   
-
 
67
   /**
-
 
68
    * Extends Users::validate
-
 
69
    * 
-
 
70
    * Loads permissions if user was validated
-
 
71
    * 
-
 
72
    * @param string $username
-
 
73
    * @param string $password
-
 
74
    * @param usersPermissionsDataSource $connection
-
 
75
    * 
-
 
76
    * @returns boolean true if username/password are correct
-
 
77
    */
56
   protected function validate( $username, $password, $connection ) {
78
   protected function validate( $username, $password, $connection ) {
57
      if ( parent::validate( $username, $password, $connection ) ) {
79
      if ( parent::validate( $username, $password, $connection ) ) {
58
         $this->data['permissions'] = $connection->getPermissions( $this->data['id'] );
80
         $this->data['permissions'] = $connection->getPermissions( $this->data['id'] );
-
 
81
         return true;
59
      }
82
      }
-
 
83
      return false;
60
   }
84
   }
61
   
85
   
-
 
86
   /**
-
 
87
    * Extends Users::editScreen
-
 
88
    * 
-
 
89
    * Adds permissions in div of class category
-
 
90
    * 
-
 
91
    * @param usersPermissionsDataSource $connection
-
 
92
    * 
-
 
93
    * @returns string HTML display screen
-
 
94
    */
62
   public function editScreen( $connection ) {
95
   public function editScreen( $connection ) {
63
      $divDef = "<div class='category'>\n";
96
      $divDef = "<div class='category'>\n";
64
      $return = array();
97
      $return = array();
65
      $return[] = parent::editScreen( $connection );
98
      $return[] = parent::editScreen( $connection );
66
      if ( $this->isAdmin() ) {
99
      if ( $this->isAdmin() ) {
Line 84... Line 117...
84
         }
117
         }
85
      }
118
      }
86
      return implode( "\n", $return );
119
      return implode( "\n", $return );
87
   }
120
   }
88
   
121
   
-
 
122
   /**
-
 
123
    * Adds/Updates existing record
-
 
124
    * 
-
 
125
    * Extending Users::addEdit by updating the permissions
-
 
126
    * 
-
 
127
    * @param usersPermissionsDataSource $connection
-
 
128
    * 
-
 
129
    * @returns string Message saying whether the update/insert worked
-
 
130
    */
89
   protected function addEdit( $connection ) {
131
   protected function addEdit( $connection ) {
90
      print "<pre>addEdit\n" . print_r( $this->workingOn, true) . '</pre>';
-
 
91
      $return = parent::addEdit( $connection );
132
      $return = parent::addEdit( $connection );
92
      $data = array();
133
      $data = array();
93
      // now we process all of the permissions
134
      // now we process all of the permissions
94
      if ( $return != 'Error' ) {
135
      if ( $return != 'Error' ) {
95
         foreach ( $this->workingOn['permissions'] as $name => $value ) {
136
         foreach ( $this->workingOn['permissions'] as $name => $value ) {
Line 105... Line 146...
105
         $connection->updatePermissions( $this->workingOn['id'],$data );
146
         $connection->updatePermissions( $this->workingOn['id'],$data );
106
      } // if not an error
147
      } // if not an error
107
      return $return;
148
      return $return;
108
   } // addEdit
149
   } // addEdit
109
   
150
   
-
 
151
   /**
-
 
152
    * Initializes $this->workingOn
-
 
153
    * 
-
 
154
    * This is a modification to Users::initWorkingOn to add permissions
-
 
155
    */
110
   protected function initWorkingOn( $connection, $id ) {
156
   protected function initWorkingOn( $connection, $id ) {
111
      parent::initWorkingOn( $connection, $id );
157
      parent::initWorkingOn( $connection, $id );
112
      if ( ! isset( $this->workingOn['permissions'] ) ) {
158
      if ( ! isset( $this->workingOn['permissions'] ) ) {
113
         $this->workingOn['permissions'] = $connection->getPermissions( $id );
159
         $this->workingOn['permissions'] = $connection->getPermissions( $id );
114
      }
160
      }
115
   }
161
   }
-
 
162
   
-
 
163
   /**
-
 
164
    * returns boolean as to whether the user has the passed in permission
-
 
165
    * 
-
 
166
    * If user is an admin, they automatically have all permissions, otherwise
-
 
167
    * we check for the permission. NOTE: the existence of a permission
-
 
168
    * is not validated. If a permission does not exist, will return false
-
 
169
    * for anyone but an admin
-
 
170
    * 
-
 
171
    * @param string $permission short form of permission
-
 
172
    * @returns boolean
-
 
173
    */
-
 
174
   public function isAuthorized ( $permission ) {
-
 
175
      return $this->isAdmin() || $this->data['permissions'][$permission];
-
 
176
   }
116
 
177
 
-
 
178
   /**
-
 
179
    * Adds a permission to the permissions table
-
 
180
    * 
-
 
181
    * This simply adds a permission to the permissions table, adding the 
-
 
182
    * category if it doesn't exist already. Since this is already written
-
 
183
    * in usersPermissionsDataSource, we simply call it.
-
 
184
    * 
-
 
185
    * @parameter string $category Category to place the permission into
-
 
186
    * @parameter string $name The short name of the permission
-
 
187
    * @parameter string $description The long (display) name for the permission
-
 
188
    * @parameter boolean $defaultValue The default value for the permission
-
 
189
    */
-
 
190
   public function addPermission ( $connection, $category, $name, $description, $defaultValue = 0 ) {
-
 
191
      $connection->addPermission ( $category, $name, $description, $defaultValue = 0 );
-
 
192
   }
117
 
193
 
118
}
194
}
119
 
195
 
120
?>
196
?>