1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | <?php // // Open Web Analytics - An Open Source Web Analytics Framework // // Copyright 2008 Peter Adams. All rights reserved. // // Licensed under GPL v2.0 http://www.gnu.org/copyleft/gpl.html // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // $Id$ // /** * Service User Class * * @author Peter Adams <peter@openwebanalytics.com> * @copyright Copyright © 2008 Peter Adams <peter@openwebanalytics.com> * @license http://www.gnu.org/copyleft/gpl.html GPL v2.0 * @category owa * @package owa * @version $Revision$ * @since owa 1.0.0 */ class owa_serviceUser extends owa_base { var $user; var $capabilities = array(); var $preferences = array(); var $is_authenticated; function __construct() { //parent::__construct(); $this->user = owa_coreApi::entityFactory('base.user'); } function load($user_id) { $this->user->load($user_id, 'user_id'); $this->loadRelatedUserData(); return; } function loadRelatedUserData() { $this->capabilities = $this->getCapabilities($this->user->get('role')); $this->preferences = $this->getPreferences($this->user->get('user_id')); return; } function getCapabilities($role) { $caps = owa_coreAPI::getSetting('base', 'capabilities'); if (array_key_exists($role, $caps)) { return $caps[$role]; } else { return array(); } } function getPreferences($user_id) { return false; } function getRole() { return $this->user->get('role'); } function setRole($value) { $this->user->set('role', $value); $this->capabilities = $this->getCapabilities($value); } function setUserData($name, $value) { $this->user->set($name, $value); return; } function getUserData($name) { return $this->user->get($name); } function isCapable($cap) { //owa_coreAPI::debug(print_r($this->user->getProperties(), true)); owa_coreAPI::debug("cap ".$cap); // just in case there is no cap passed if (!empty($cap)) { //adding @ here as is_array throws warning that an empty array is not the right data type! if (in_array($cap, $this->capabilities)) { return true; } else { return false; } } else { return true; } } // mark the user as authenticated and populate their capabilities function setAuthStatus($bool) { $this->is_authenticated = true; return; } function isAuthenticated() { return $this->is_authenticated; } function loadNewUserByObject($obj) { $this->user = $obj; //$this->current_user->loadNewUserByObject($obj); $this->loadRelatedUserData(); return; } function loadNewUserById($id) { // get a user object // load it // $this->loadNewUserByObject($obj); return; } } ?> |