Merge pull request #945 from NicoDucou/BT10582wq

Adding verification if the user's area is in the session target -refs…
1.10.x
Yannick Warnier 9 years ago
commit 8f180a7de2
  1. 1
      plugin/advanced_subscription/lang/english.php
  2. 1
      plugin/advanced_subscription/lang/spanish.php
  3. 34
      plugin/advanced_subscription/src/AdvancedSubscriptionPlugin.php
  4. 63
      plugin/advanced_subscription/src/HookAdvancedSubscription.php
  5. 5
      plugin/advanced_subscription/src/admin_view.php
  6. 2
      plugin/advanced_subscription/views/admin_view.tpl

@ -71,6 +71,7 @@ $strings['PublicationEndDate'] = 'Publication end date';
$strings['Mode'] = 'Mode';
$strings['Postulant'] = 'Postulant';
$strings['Area'] = 'Area';
$strings['Institution'] = 'Institution';
$strings['InscriptionDate'] = 'Inscription date';
$strings['BossValidation'] = 'Boss validation';
$strings['Decision'] = 'Decision';

@ -71,6 +71,7 @@ $strings['PublicationEndDate'] = 'Fecha fin de publicación';
$strings['Mode'] = 'Modalidad';
$strings['Postulant'] = 'Postulante';
$strings['Area'] = 'Área';
$strings['Institution'] = 'Institución';
$strings['InscriptionDate'] = 'Fecha de inscripción';
$strings['BossValidation'] = 'Validación del superior';
$strings['Decision'] = 'Decisión';

@ -529,6 +529,40 @@ class AdvancedSubscriptionPlugin extends Plugin implements HookPluginInterface
return $isOpen;
}
/**
* Check if user is in the session's target group based on its area
* @param $userId
* @param $sessionId
* @param string $userFieldVariable
* @param string $sessionFieldVariable
* @return bool
*/
public function isUserInTargetGroup($userId, $sessionId, $userFieldVariable = 'area', $sessionFieldVariable = 'target')
{
$extraSessionFieldValue = new ExtraFieldValue('session');
$sessionTarget = $extraSessionFieldValue->get_values_by_handler_and_field_variable(
$sessionId,
$sessionFieldVariable
);
$extraUserFieldValue = new ExtraFieldValue('user');
$userArea = $extraUserFieldValue->get_values_by_handler_and_field_variable(
$userId,
$userFieldVariable
);
$isInTargetGroup = false;
if (isset($sessionTarget) && (!empty($sessionTarget)) && $sessionTarget['value'] == 'minedu') {
if (substr($userArea['value'], 0, 6) == 'MINEDU') {
$isInTargetGroup = true;
}
}
if (isset($sessionTarget) && (!empty($sessionTarget)) && $sessionTarget['value'] == 'regiones') {
if ((substr($userArea['value'], 0, 4) == 'UGEL') || (substr($userArea['value'], 0, 3) == 'DRE')) {
$isInTargetGroup = true;
}
}
return $isInTargetGroup;
}
/**
* Update the queue status for subscription approval rejected or accepted
* @param $params

@ -489,6 +489,7 @@ class HookAdvancedSubscription extends HookObserver implements
$status = $plugin->getQueueStatus($userId, $sessionId);
$vacancy = $plugin->getVacancy($sessionId);
$data = $plugin->getSessionDetails($sessionId);
$isUserInTargetGroup = $plugin->isUserInTargetGroup($userId, $sessionId);
if (!empty($data) && is_array($data)) {
$data['status'] = $status;
// Vacancy and queue status cases:
@ -499,37 +500,41 @@ class HookAdvancedSubscription extends HookObserver implements
$data['status'] = 10;
}
} else {
try {
$isAllowed = self::$plugin->isAllowedToDoRequest($userId, $params);
$data['message'] = self::$plugin->getStatusMessage($status, $isAllowed);
} catch (\Exception $e) {
$data['message'] = $e->getMessage();
}
$params['action'] = 'subscribe';
$params['sessionId'] = intval($sessionId);
$params['currentUserId'] = 0; // No needed
$params['studentUserId'] = intval($userId);
$params['queueId'] = 0; // No needed
$params['newStatus'] = ADVANCED_SUBSCRIPTION_QUEUE_STATUS_START;
if ($vacancy > 0) {
// Check conditions
if ($status == ADVANCED_SUBSCRIPTION_QUEUE_STATUS_NO_QUEUE) {
// No in Queue, require queue subscription url action
$data['action_url'] = self::$plugin->getTermsUrl($params);
} elseif ($status == ADVANCED_SUBSCRIPTION_QUEUE_STATUS_ADMIN_APPROVED) {
// send url action
$data['action_url'] = self::$plugin->getSessionUrl($sessionId);
} else {
// In queue, output status message, no more info.
}
if (!$isUserInTargetGroup) {
$data['status'] = -2;
} else {
if ($status == ADVANCED_SUBSCRIPTION_QUEUE_STATUS_ADMIN_APPROVED) {
$data['action_url'] = self::$plugin->getSessionUrl($sessionId);
} elseif ($status == ADVANCED_SUBSCRIPTION_QUEUE_STATUS_NO_QUEUE) {
// in Queue or not, cannot be subscribed to session
$data['action_url'] = self::$plugin->getTermsUrl($params);
try {
$isAllowed = self::$plugin->isAllowedToDoRequest($userId, $params);
$data['message'] = self::$plugin->getStatusMessage($status, $isAllowed);
} catch (\Exception $e) {
$data['message'] = $e->getMessage();
}
$params['action'] = 'subscribe';
$params['sessionId'] = intval($sessionId);
$params['currentUserId'] = 0; // No needed
$params['studentUserId'] = intval($userId);
$params['queueId'] = 0; // No needed
$params['newStatus'] = ADVANCED_SUBSCRIPTION_QUEUE_STATUS_START;
if ($vacancy > 0) {
// Check conditions
if ($status == ADVANCED_SUBSCRIPTION_QUEUE_STATUS_NO_QUEUE) {
// No in Queue, require queue subscription url action
$data['action_url'] = self::$plugin->getTermsUrl($params);
} elseif ($status == ADVANCED_SUBSCRIPTION_QUEUE_STATUS_ADMIN_APPROVED) {
// send url action
$data['action_url'] = self::$plugin->getSessionUrl($sessionId);
} else {
// In queue, output status message, no more info.
}
} else {
// In queue, output status message, no more info.
if ($status == ADVANCED_SUBSCRIPTION_QUEUE_STATUS_ADMIN_APPROVED) {
$data['action_url'] = self::$plugin->getSessionUrl($sessionId);
} elseif ($status == ADVANCED_SUBSCRIPTION_QUEUE_STATUS_NO_QUEUE) {
// in Queue or not, cannot be subscribed to session
$data['action_url'] = self::$plugin->getTermsUrl($params);
} else {
// In queue, output status message, no more info.
}
}
}
}

@ -72,6 +72,11 @@ if (!empty($sessionId)) {
$areaField = $fieldValue->get_values_by_handler_and_field_variable($studentId, 'area', true);
$student['area'] = $areaField['value'];
if (substr($student['area'], 0, 6) == 'MINEDU') {
$student['institution'] = 'Minedu';
} else {
$student['institution'] = 'Regiones';
}
$student['userLink'] = api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$studentId;
$data['queueId'] = intval($student['queue_id']);
$data['newStatus'] = ADVANCED_SUBSCRIPTION_QUEUE_STATUS_ADMIN_APPROVED;

@ -43,6 +43,7 @@
<th>{{ "Postulant" | get_plugin_lang('AdvancedSubscriptionPlugin') }}</th>
<th>{{ "InscriptionDate" | get_plugin_lang('AdvancedSubscriptionPlugin') }}</th>
<th>{{ "Area" | get_plugin_lang('AdvancedSubscriptionPlugin') }}</th>
<th>{{ "Institution" | get_plugin_lang('AdvancedSubscriptionPlugin') }}</th>
<th>{{ "BossValidation" | get_plugin_lang('AdvancedSubscriptionPlugin') }}</th>
<th class="advanced-subscription-decision-column">{{ "Decision" | get_plugin_lang('AdvancedSubscriptionPlugin') }}</th>
</tr>
@ -56,6 +57,7 @@
</td>
<td>{{ student.created_at }}</td>
<td>{{ student.area }}</td>
<td>{{ student.institution }}</td>
{% set cellClass = 'danger'%}
{% if student.validation == 'Yes' %}
{% set cellClass = 'success'%}

Loading…
Cancel
Save