summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThilo Wawrzik2007-05-08 14:33:22 (GMT)
committer Thilo Wawrzik2007-05-08 14:33:22 (GMT)
commit190c63c075dbc9cf2b931f48919341233bbc43aa (patch)
treede82d1579549074df84bde6839389cba89a096f5
parent72b867523649f486ba5c783d80a0ede010744631 (diff)
- task: cleanup user status code (and filter)
-rw-r--r--gallery_user.inc48
-rw-r--r--gallery_user_admin.inc23
2 files changed, 35 insertions, 36 deletions
diff --git a/gallery_user.inc b/gallery_user.inc
index a06e932..ab6e9e2 100644
--- a/gallery_user.inc
+++ b/gallery_user.inc
@@ -12,7 +12,7 @@ define(G2MAP_USER_EXISTS_BUT_NEEDS_MAPPING, 2);
define(G2MAP_USER_DOES_NOT_EXIST_BUT_IS_MAPPED, 3);
define(G2MAP_USER_DOES_NOT_EXIST, 4);
-define(G2USERINFO_ERROR_OK, 1);
+define(G2USERINFO_NOERROR, 1);
define(G2USERINFO_ERROR_MISSING, 2);
define(G2USERINFO_ERROR_USERNAME, 3);
define(G2USERINFO_ERROR_FULLNAME, 4);
@@ -246,10 +246,10 @@ function gallery_user_view($user) {
'class' => 'send-message');
}
// sync status
- if (($g2_userinfo['error']) && (user_access('administer users'))) {
+ if (($g2_userinfo['status']) && (user_access('administer users'))) {
$form['gallery_view_user'] = array(
'title' => t('Gallery2-Drupal Sync Status'),
- 'value' => implode(',<br />', gallery_user_map_info_status($g2_userinfo['error'])) .'<br />');
+ 'value' => implode(',<br />', gallery_user_map_info_status($g2_userinfo['status'])) .'<br />');
}
GalleryEmbed::done();
@@ -261,30 +261,24 @@ function gallery_user_view($user) {
/**
* Get info about user map status
*/
-function gallery_user_map_info($user) {
- $g2_userinfo['error'] = array();
+function gallery_user_map_info($user, $noerror_status = TRUE) {
+ $g2_userinfo = array('g2_id' => -1, 'status' => array());
// user map entry
$ret = GalleryEmbed::isExternalIdMapped($user->uid, 'GalleryUser');
if ($ret && !($ret->getErrorCode() & ERROR_MISSING_OBJECT)) {
- $g2_userinfo['g2_id'] = -1;
- $g2_userinfo['error'][] = G2USERINFO_ERROR_MISSING;
- $g2_userinfo['sync_ok'] = 0;
-
+ $g2_userinfo['status'][] = G2USERINFO_ERROR_MISSING;
return $g2_userinfo;
}
// but user not available
list($ret, $g2_user) = GalleryCoreApi::loadEntityByExternalId($user->uid, 'GalleryUser');
if ($ret) {
- $g2_userinfo['g2_id'] = -1;
- $g2_userinfo['error'][] = G2USERINFO_ERROR_MISSING;
- $g2_userinfo['sync_ok'] = 0;
-
+ $g2_userinfo['status'][] = G2USERINFO_ERROR_MISSING;
return $g2_userinfo;
}
// username
$g2_userinfo['g2_id'] = $g2_user->id;
if ($g2_user->getuserName() != $user->name) {
- $g2_userinfo['error'][] = G2USERINFO_ERROR_USERNAME;
+ $g2_userinfo['status'][] = G2USERINFO_ERROR_USERNAME;
}
// fullname
if (module_exists('profile') && variable_get('gallery_use_full_name', 0)) {
@@ -293,40 +287,39 @@ function gallery_user_map_info($user) {
$fullname = db_fetch_object($fullname_result);
$fullname = $fullname->value;
if ($g2_user->getfullName() != $fullname) {
- $g2_userinfo['error'][] = G2USERINFO_ERROR_FULLNAME;
+ $g2_userinfo['status'][] = G2USERINFO_ERROR_FULLNAME;
}
elseif (!$fullname) {
- $g2_userinfo['error'][] = G2USERINFO_ERROR_FULLNAME_MISSING;
+ $g2_userinfo['status'][] = G2USERINFO_ERROR_FULLNAME_MISSING;
}
}
else {
if ($g2_user->getfullName() != $user->name) {
- $g2_userinfo['error'][] = G2USERINFO_ERROR_FULLNAME_INCORRECT;
+ $g2_userinfo['status'][] = G2USERINFO_ERROR_FULLNAME_INCORRECT;
}
}
// email adress
if ($g2_user->getemail() != $user->mail) {
- $g2_userinfo['error'][] = G2USERINFO_ERROR_EMAIL;
+ $g2_userinfo['status'][] = G2USERINFO_ERROR_EMAIL;
}
// password
if ($g2_user->gethashedPassword() != $user->pass) {
- $g2_userinfo['error'][] = ($user->status) ? G2USERINFO_ERROR_PASSWORD : G2USERINFO_ERROR_BLOCKED;
+ $g2_userinfo['status'][] = ($user->status) ? G2USERINFO_ERROR_PASSWORD : G2USERINFO_ERROR_BLOCKED;
}
// overall sync status
- $g2_userinfo['sync_ok'] = (!$g2_userinfo['error']);
- if ($g2_userinfo['sync_ok']) {
- $g2_userinfo['error'][] = G2USERINFO_ERROR_OK;
+ if ($noerror_status && !count($g2_userinfo['status'])) {
+ $g2_userinfo['status'][] = G2USERINFO_NOERROR;
}
-
+
return $g2_userinfo;
}
/**
* Get string representation of the use map status
*/
-function gallery_user_map_info_status($info = array()) {
+function gallery_user_map_info_status($info = array(), $format = TRUE) {
$info_map = array(
- G2USERINFO_ERROR_OK => t('OK'),
+ G2USERINFO_NOERROR => t('OK'),
G2USERINFO_ERROR_MISSING => t('Missing from G2'),
G2USERINFO_ERROR_USERNAME => t('Different Usernames'),
G2USERINFO_ERROR_FULLNAME => t('Different Full Names'),
@@ -337,8 +330,11 @@ function gallery_user_map_info_status($info = array()) {
G2USERINFO_ERROR_BLOCKED => t('Blocked User'),
);
- if (count($info)) {
+ if ($format) {
$status = array();
+ if (!count($info)) {
+ $info[] = G2USERINFO_NOERROR;
+ }
foreach ($info as $key => $value) {
$status[] = $info_map[$value];
}
diff --git a/gallery_user_admin.inc b/gallery_user_admin.inc
index 3272f6a..79f6371 100644
--- a/gallery_user_admin.inc
+++ b/gallery_user_admin.inc
@@ -38,7 +38,7 @@ function _gallery_user_users($args) {
if (!_gallery_init(TRUE)) {
return '';
}
- list($ret, $admin) = GalleryCoreApi::isUserInSiteAdminGroup();
+ list($ret, $g2_admin) = GalleryCoreApi::isUserInSiteAdminGroup();
if ($ret) {
gallery_error(t('Error calling \'GalleryCoreApi::isUserInSiteAdminGroup\'.'), $ret);
}
@@ -52,25 +52,25 @@ function _gallery_user_users($args) {
}
while ($user = db_fetch_object($result)) {
- $g2_userinfo = gallery_user_map_info($user);
-
+ $g2_userinfo = gallery_user_map_info($user, FALSE);
+
$g2_id = ($g2_userinfo['g2_id'] >= 0) ? $g2_userinfo['g2_id'] : t('N/A');
$operations = array(l(t('edit'), "user/$user->uid/edit", array(), $destination));
- if ($admin && ($g2_userinfo['g2_id'] > 0)) {
+ if ($g2_admin && ($g2_userinfo['g2_id'] > 0)) {
$link_url = gallery_generate_url(array('view' => 'core.SiteAdmin',
'subView' => 'core.AdminEditUser',
'userId' => $g2_userinfo['g2_id']), FALSE);
$operations[] = l(t('edit G2'), $link_url);
}
- if (!$g2_userinfo['sync_ok']) {
+ if (count($g2_userinfo['status'])) {
$operations[] = l(t('sync'), 'admin/user/gallery/users/sync/'. $user->uid);
}
-
+
if (isset($filter)) {
- if (!in_array($filter, $g2_userinfo['error'])) {
+ if (!in_array($filter, $g2_userinfo['status'])) {
continue;
}
}
@@ -79,7 +79,7 @@ function _gallery_user_users($args) {
$g2_id,
theme_username($user),
$status[$user->status],
- implode(',<br />', gallery_user_map_info_status($g2_userinfo['error'])),
+ implode(',<br />', gallery_user_map_info_status($g2_userinfo['status'])),
implode(' | ', $operations));
}
@@ -88,7 +88,8 @@ function _gallery_user_users($args) {
}
$output = drupal_get_form('_gallery_user_filter_form', $filter);
- $output .= theme('table', $header, $rows); $output .= theme('pager', array(), 50);
+ $output .= theme('table', $header, $rows);
+ $output .= theme('pager', array(), 50);
GalleryEmbed::done();
return $output;
@@ -104,10 +105,12 @@ function _gallery_user_filter_form($filter) {
'#collapsible' => TRUE,
'#collapsed' => !$filter,
);
+ $filter_options = gallery_user_map_info_status(array(), FALSE);
+ unset($filter_options[G2USERINFO_NOERROR]);
$form['filter']['filter_status'] = array(
'#type' => 'select',
'#title' => t('Show only users with status'),
- '#options' => gallery_user_map_info_status(),
+ '#options' => $filter_options,
'#default_value' => $filter,
);
$form['filter']['buttons']['submit'] = array('#type' => 'submit', '#value' => t('Filter'));