/** * * @param unknown_type $rs */ private static function _getObject($rs) { $ret = new User(); $ret->setAvatar($rs->getAvatar()); $ret->setCos($rs->getCos()); $ret->setCreationDate($rs->getCreationDate()); $ret->setEmail($rs->getEmail()); $ret->setEnabled($rs->getEnabled()); $ret->setId($rs->getId()); $ret->setName($rs->getName()); $ret->setUsername($rs->getUsername()); // // The following is a workaround on the fact that the translation of this // serialized object to the database gets all broken, due to the fact of PHP // introducing NULL bytes around the '*' that is prepended before protected // variable members, in the serialized mode. This method replaces those // problematic NULL bytes with an identifier string '~~NULL_BYTE~~', // rendering serialization and unserialization of these specific kinds of // object safe. Credits to travis@travishegner.com on: // http://pt.php.net/manual/en/function.serialize.php#96504 // $unsafeSerializedNotifications = str_replace(CINTIENT_NULL_BYTE_TOKEN, "", $rs->getNotifications()); if (($notifications = unserialize($unsafeSerializedNotifications)) === false) { $notifications = array(); } $ret->setNotifications($notifications); $ret->resetSignature(); return $ret; }
/** * Return User object of given user_id * * @param int $user_id * @return User */ public function getObjectById($user_id, $cacheMinutes = 0) { $user_id = intval($user_id); $this->query->exec("select * from `" . Tbl::get('TBL_USERS') . "` where `id`='{$user_id}'", $cacheMinutes); if ($this->query->countRecords()) { $res = $this->query->fetchRecord(); $user = new User(); $user->setLogin($res["login"]); $user->setId($user_id); $user->setCreationDate($res["creation_date"]); $user->setStatus($res["enable"]); foreach ($res as $key => $val) { if ($key != 'id' && $key != 'enable' && $key != 'creation_date' && $key != 'login' && $key != 'password') { $user->{$key} = $val; } } $this->query->exec("select `permission_id` from `" . Tbl::get('TBL_USERS_PERMISSIONS') . "` where `user_id`='{$user_id}'", $cacheMinutes); $perms_ids_count = $this->query->countRecords(); if ($perms_ids_count) { $perms_ids = $this->query->fetchFields(0, true); $sql_statement = "select `name` from `" . Tbl::get('TBL_PERMISSIONS') . "` where `id` in ("; $count = $perms_ids_count - 1; for ($i = 0; $i < $count; ++$i) { $sql_statement .= $perms_ids[$i] . ", "; } $sql_statement .= $perms_ids[$count] . ")"; $this->query->exec($sql_statement, $cacheMinutes); $user->setPermissions($this->query->fetchFields(0, true)); } $this->query->exec("select `group_id` from `" . Tbl::get('TBL_USERS_GROUPS') . "` where `user_id`='{$user_id}'", $cacheMinutes); $groups_ids_count = $this->query->countRecords(); if ($groups_ids_count) { $groups_ids = $this->query->fetchFields(0, true); $sql_statement = "select `name` from `" . Tbl::get('TBL_GROUPS') . "` where `id` in ("; $count = $groups_ids_count - 1; for ($i = 0; $i < $count; ++$i) { $sql_statement .= $groups_ids[$i] . ", "; } $sql_statement .= $groups_ids[$count] . ")"; $this->query->exec($sql_statement, $cacheMinutes); $groups_names = $this->query->fetchFields(0, true); $user->setGroups($groups_names); foreach ($groups_names as $group_name) { $user->addPermissions($this->getGroupPermissionsList($group_name, $cacheMinutes)); } $user->setPrimaryGroup($this->getPrimaryGroup($user_id, $cacheMinutes)); } return $user; } return new User(); }