Update isAllowedToDoRequest method to use ws to get profile percentage and set student always connected - refs BT#9092

1.10.x
Daniel Barreto 11 years ago
parent fea0d59272
commit ea1e4173cb
  1. 4
      plugin/advanced_subscription/ajax/advanced_subscription.ajax.php
  2. 33
      plugin/advanced_subscription/src/AdvancedSubscriptionPlugin.php

@ -21,7 +21,9 @@ $data['currentUserId'] = intval($_REQUEST['current_user_id']);
$data['studentUserId'] = intval($_REQUEST['u']);
$data['queueId'] = intval($_REQUEST['q']);
$data['newStatus'] = intval($_REQUEST['e']);
$data['is_connected'] = isset($_REQUEST['is_connected']) ? boolval($_REQUEST['is_connected']) : false;
// Student always is connected
// $data['is_connected'] = isset($_REQUEST['is_connected']) ? boolval($_REQUEST['is_connected']) : false;
$data['is_connected'] = true;
$data['profile_completed'] = isset($_REQUEST['profile_completed']) ? floatval($_REQUEST['profile_completed']) : 0;
// Init result array
$result = array('error' => true, 'errorMessage' => get_lang('ThereWasAnError'));

@ -112,17 +112,30 @@ class AdvancedSubscriptionPlugin extends Plugin implements HookPluginInterface
public function isAllowedToDoRequest($userId, $params = array())
{
$isAllowed = null;
if (isset($params['is_connected']) && isset($params['profile_completed'])) {
$plugin = self::create();
// WS URL is not yet implemented
// $wsUrl = $plugin->get('ws_url');
// @TODO: Get connection status from user by WS
$isConnected = $params['is_connected'];
$wsUrl = $plugin->get('ws_url');
// Student always is connected
$isConnected = true;
if ($isConnected) {
$profileCompletedMin = (float) $plugin->get('min_profile_percentage');
// @TODO: Get completed profile percentage by WS
if (is_string($wsUrl) && !empty($wsUrl)) {
$options = array(
'location' => $wsUrl,
'uri' => $wsUrl
);
$client = new SoapClient(null, $options);
$userInfo = UserManager::get_user_info_by_id($userId);
try {
$profileCompleted = $client->__soapCall('getProfileCompletionPercentage', $userInfo['extra']['drupal_user_id']);
} catch (\Exception $e) {
$profileCompleted = 0;
}
} elseif (isset($params['profile_completed'])) {
$profileCompleted = (float) $params['profile_completed'];
if ($profileCompleted > $profileCompletedMin) {
} else {
$profileCompleted = 0;
}
if ($profileCompleted >= $profileCompletedMin) {
$checkInduction = $plugin->get('check_induction');
// @TODO: check if user have completed at least one induction session
$completedInduction = true;
@ -196,10 +209,6 @@ class AdvancedSubscriptionPlugin extends Plugin implements HookPluginInterface
}
return $isAllowed;
} else {
throw new \Exception($this->get_lang('AdvancedSubscriptionIncompleteParams'));
}
}
/**
@ -873,7 +882,7 @@ class AdvancedSubscriptionPlugin extends Plugin implements HookPluginInterface
'e=' . intval($params['newStatus']) . '&' .
'u=' . intval($params['studentUserId']) . '&' .
'q=' . intval($params['queueId']) . '&' .
'is_connected=' . intval($params['is_connected']) . '&' .
'is_connected=' . true . '&' .
'profile_completed=' . intval($params['profile_completed']) . '&' .
'v=' . $this->generateHash($params);
return $url;

Loading…
Cancel
Save