Home » Authentication » LiveUser » Bug #533
Suggestion: customFields for creating and updating a user
Details
| Submitted | 2004-01-07 11:43 UTC |
|---|---|
| From | corwin42 at gmx dot de |
| Assigned | dufuz |
| Status | Closed |
| Package | LiveUser |
| PHP Version | Irrelevant |
| Roadmaps | (Not assigned) |
Comments
[2004-01-07 11:43 UTC] corwin42 at gmx dot de
Description:
------------
As there is the possibility to retreive custom colums with the $customFields Array in LiveUser_Admin_Auth_Container_DB::getUsers() it would be very nice to have the same feature for addUser() and updateUser() for inserting or updating this custom fields. So it would be easy to extend the users-table with a real live name of the user and you don't have to add additional updates to your code.
[2004-03-07 11:54 UTC] simon dot hamilton at ntlworld dot com
Here's a patch that should work for the MDB container. I also made some colding style tidy ups in some SQL bits. I have yet to test it but if it works it should be trivial to port the changes to the other containers.
Here's the patch:
--- MDB.php Sun Mar 07 11:54:06 2004
+++ MDB.php.new.php Sun Mar 07 11:57:10 2004
@@ -206,10 +206,11 @@
* @param integer ID of the owning user.
* @param integer ID of the owning group.
* @param mixed If specificed no new ID will be automatically generated instead
+ * @param array Array of custom fields to be added
* @return mixed Users auth ID on success, DB error if not, false if not initialized
*/
function addUser($handle, $password = '', $active = true, $owner_user_id = null,
- $owner_group_id = null, $authId = null)
+ $owner_group_id = null, $authId = null, $customFields = array())
{
if (!$this->init_ok) {
return false;
@@ -237,6 +238,13 @@
$col[] = $this->authTableCols['owner_group_id']['name'];
$val[] = $this->dbc->getValue($this->authTableCols['owner_group_id']['type'], $owner_group_id);
}
+
+ if (sizeof($customFields) > 0) {
+ foreach ($customFields as $k => $v) {
+ $col[] = $customFields[$k]['name'];
+ $val[] = $this->dbc->getValue($customFields[$k]['type'], $v);
+ }
+ }
if (is_array($col) && count($col) > 0) {
$col = ',' . implode(',', $col);
@@ -311,10 +319,11 @@
* @param boolean Sets the user active (1) or not (0) (optional).
* @param integer ID of the owning user.
* @param integer ID of the owning group.
+ * @param array Array of custom fields to be updated
* @return mixed True on success, DB error if not.
*/
function updateUser($authId, $handle = '', $password = '', $active = null,
- $owner_user_id = null, $owner_group_id = null)
+ $owner_user_id = null, $owner_group_id = null, $customFields = array())
{
if (!$this->init_ok) {
return false;
@@ -329,7 +338,7 @@
if (!empty($handle)) {
$updateValues[] =
- $this->authTableCols['handle']['name'] . '=' . $this->dbc->getValue($this->authTableCols['handle']['type'], $handle);
+ $this->authTableCols['handle']['name'] . ' = ' . $this->dbc->getValue($this->authTableCols['handle']['type'], $handle);
}
if (!empty($password)) {
$updateValues[] =
@@ -349,6 +358,13 @@
$updateValues[] =
$this->authTableCols['owner_group_id'] . ' = ' . $this->dbc->getValue($this->authTableCols['owner_group_id']['type'], $owner_group_id);
}
+
+ if (sizeof($customFields) > 0) {
+ foreach ($customFields as $k => $v) {
+ $updateValues[] =
+ $customFields[$k] . ' = ' . $this->dbc->getValue($customFields[$k]['type'], $v);
+ }
+ }
if (count($updateValues) >= 1) {
$query .= implode(', ', $updateValues);
@@ -432,7 +448,8 @@
$fields = $where = '';
if (isset($this->authTableCols['lastlogin'])) {
- $customFields[] = $this->authTableCols['lastlogin'] . ' AS lastlogin';
+ $customFields[$this->authTableCols['lastlogin'] . ' AS lastlogin']
+ = $this->authTableCols['lastlogin']['type'];
}
if (isset($this->authTableCols['is_active'])) {
@@ -472,16 +489,16 @@
}
// First: Get all data from auth table.
- $query = "
+ $query = '
SELECT
- {$this->authTableCols['user_id']['name']} AS auth_user_id,
- {$this->authTableCols['handle']['name']} AS handle,
- {$this->authTableCols['passwd']['name']} AS passwd,
- $fields
+ ' . $this->authTableCols['user_id']['name'] . ' AS auth_user_id,
+ ' . $this->authTableCols['handle']['name'] . ' AS handle,
+ ' . $this->authTableCols['passwd']['name'] . ' AS passwd,
+ ' . $fields . '
FROM
- {$this->authTable}
- $where
- $order";
+ ' . $this->authTable
+ . $where
+ . $order;
$types = array(
$this->authTableCols['user_id']['type'],