commerce_order_plugin_argument_validate_user.inc in Commerce Core 7
File
modules/order/includes/views/handlers/commerce_order_plugin_argument_validate_user.inc
View source
<?php
class commerce_order_plugin_argument_validate_user extends views_plugin_argument_validate_user {
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['restrict_roles']['#title'] = t('If the current user does not match the argument, validate the argument for users with specific roles.');
$form['roles'] = array(
'#type' => 'checkboxes',
'#title' => t('Grant access for the selected roles'),
'#description' => t('If no roles are selected, additional access will not be granted.'),
'#options' => user_roles(TRUE),
'#default_value' => $this->options['roles'],
'#dependency' => array(
'edit-options-validate-options-current-user-or-role-restrict-roles' => array(
1,
),
),
'#prefix' => '<div id="edit-options-validate-options-current-user-or-role-roles-wrapper">',
'#suffix' => '</div>',
);
}
function validate_argument($argument) {
global $user;
$type = $this->options['type'];
if (is_numeric($argument) && $argument == (int) $argument && $argument > 0 && ($type == 'uid' || $type == 'either')) {
$where = 'uid = :argument';
if ($argument == $user->uid) {
$account = clone $user;
}
}
elseif ($type == 'name' || $type == 'either') {
$where = "name = :argument";
if ($argument == $user->name) {
$account = clone $user;
}
}
if (empty($where)) {
return FALSE;
}
if (empty($account)) {
$account = db_query("SELECT uid, name FROM {users} WHERE " . $where, array(
':argument' => $argument,
))
->fetchObject();
if (empty($account)) {
return FALSE;
}
}
if ($user->uid != $account->uid) {
if (!empty($this->options['restrict_roles']) && !empty($this->options['roles'])) {
$roles = array();
foreach ($this->options['roles'] as $rid) {
if ($role = user_role_load($rid)) {
$roles[$rid] = $role->name;
}
}
$matching_roles = array_intersect($user->roles, $roles);
if (empty($matching_roles)) {
return FALSE;
}
}
else {
return FALSE;
}
}
$this->argument->argument = $account->uid;
$this->argument->validated_title = check_plain($account->name);
return TRUE;
}
}