|
@@ -111,64 +111,104 @@ class AdvancedSubscriptionPlugin extends Plugin implements HookPluginInterface
|
|
|
*/
|
|
|
public function isAllowedToDoRequest($userId, $params = array())
|
|
|
{
|
|
|
- if (isset($params['is_connected']) && isset($params['profile_completed'])) {
|
|
|
- $isAllowed = null;
|
|
|
- $plugin = self::create();
|
|
|
- $wsUrl = $plugin->get('ws_url');
|
|
|
- // @TODO: Get connection status from user by WS
|
|
|
- $isConnected = $params['is_connected'];
|
|
|
- if ($isConnected) {
|
|
|
- $profileCompletedMin = (float) $plugin->get('min_profile_percentage');
|
|
|
- // @TODO: Get completed profile percentage by WS
|
|
|
+ $isAllowed = null;
|
|
|
+ $plugin = self::create();
|
|
|
+ $wsUrl = $plugin->get('ws_url');
|
|
|
+ // Student always is connected
|
|
|
+ $isConnected = true;
|
|
|
+ if ($isConnected) {
|
|
|
+ $profileCompletedMin = (float) $plugin->get('min_profile_percentage');
|
|
|
+ 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) {
|
|
|
- $checkInduction = $plugin->get('check_induction');
|
|
|
- // @TODO: check if user have completed at least one induction session
|
|
|
- $completedInduction = true;
|
|
|
- if (!$checkInduction || $completedInduction) {
|
|
|
- $uitMax = $plugin->get('yearly_cost_unit_converter');
|
|
|
- $uitMax *= $plugin->get('yearly_cost_limit');
|
|
|
- // @TODO: Get UIT completed by user this year by WS
|
|
|
- $uitUser = 0;
|
|
|
- $extra = new ExtraFieldValue('session');
|
|
|
- $var = $extra->get_values_by_handler_and_field_variable($params['session_id'], 'cost');
|
|
|
- $uitUser += $var['field_value'];
|
|
|
- if ($uitMax >= $uitUser) {
|
|
|
- $expendedTimeMax = $plugin->get('yearly_hours_limit');
|
|
|
- // @TODO: Get Expended time from user data
|
|
|
- $expendedTime = 0;
|
|
|
- $var = $extra->get_values_by_handler_and_field_variable($params['session_id'], 'duration');
|
|
|
- $expendedTime += $var['field_value'];
|
|
|
- if ($expendedTimeMax >= $expendedTime) {
|
|
|
- $expendedNumMax = $plugin->get('courses_count_limit');
|
|
|
- // @TODO: Get Expended num from user
|
|
|
- $expendedNum = 0;
|
|
|
- if ($expendedNumMax >= $expendedNum) {
|
|
|
- $isAllowed = true;
|
|
|
- } else {
|
|
|
- throw new \Exception($this->get_lang('AdvancedSubscriptionCourseXLimitReached'));
|
|
|
- }
|
|
|
+ } else {
|
|
|
+ $profileCompleted = 0;
|
|
|
+ }
|
|
|
+ if ($profileCompleted >= $profileCompletedMin) {
|
|
|
+ $checkInduction = $plugin->get('check_induction');
|
|
|
+ // @TODO: check if user have completed at least one induction session
|
|
|
+ $completedInduction = true;
|
|
|
+ if (!$checkInduction || $completedInduction) {
|
|
|
+ $uitMax = $plugin->get('yearly_cost_unit_converter');
|
|
|
+ $uitMax *= $plugin->get('yearly_cost_limit');
|
|
|
+ $uitUser = 0;
|
|
|
+ $now = new DateTime(api_get_utc_datetime());
|
|
|
+ $newYearDate = $plugin->get('course_session_credit_year_start_date');
|
|
|
+ $newYearDate = !empty($newYearDate) ?
|
|
|
+ new \DateTime($newYearDate . $now->format('/Y')) :
|
|
|
+ $now;
|
|
|
+ $extra = new ExtraFieldValue('session');
|
|
|
+ $joinSessionTable = Database::get_main_table(TABLE_MAIN_SESSION_USER) . ' su INNER JOIN ' .
|
|
|
+ Database::get_main_table(TABLE_MAIN_SESSION) . ' s ON s.id = su.id_session';
|
|
|
+ $whereSessionParams = 'su.relation_type = ? AND s.date_start >= ? AND su.id_user = ?';
|
|
|
+ $whereSessionParamsValues = array(
|
|
|
+ 0,
|
|
|
+ $newYearDate->format('Y-m-d'),
|
|
|
+ $userId
|
|
|
+ );
|
|
|
+ $whereSession = array(
|
|
|
+ 'where' => array(
|
|
|
+ $whereSessionParams => $whereSessionParamsValues
|
|
|
+ )
|
|
|
+ );
|
|
|
+ $selectSession = 's.id AS id';
|
|
|
+ $sessions = Database::select(
|
|
|
+ $selectSession,
|
|
|
+ $joinSessionTable,
|
|
|
+ $whereSession
|
|
|
+ );
|
|
|
+
|
|
|
+ if (is_array($sessions) && count($sessions) > 0) {
|
|
|
+ foreach ($sessions as $session) {
|
|
|
+ $var = $extra->get_values_by_handler_and_field_variable($session['id'], 'cost');
|
|
|
+ $uitUser += $var['field_value'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ($uitMax >= $uitUser) {
|
|
|
+ $expendedTimeMax = $plugin->get('yearly_hours_limit');
|
|
|
+ $expendedTime = 0;
|
|
|
+ if (is_array($sessions) && count($sessions) > 0) {
|
|
|
+ foreach ($sessions as $session) {
|
|
|
+ $var = $extra->get_values_by_handler_and_field_variable($session['id'], 'teaching_hours');
|
|
|
+ $expendedTime += $var['field_value'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ($expendedTimeMax >= $expendedTime) {
|
|
|
+ $expendedNumMax = $plugin->get('courses_count_limit');
|
|
|
+ $expendedNum = count($sessions);
|
|
|
+ if ($expendedNumMax >= $expendedNum) {
|
|
|
+ $isAllowed = true;
|
|
|
} else {
|
|
|
- throw new \Exception($this->get_lang('AdvancedSubscriptionTimeXLimitReached'));
|
|
|
+ throw new \Exception($this->get_lang('AdvancedSubscriptionCourseXLimitReached'));
|
|
|
}
|
|
|
} else {
|
|
|
- throw new \Exception($this->get_lang('AdvancedSubscriptionCostXLimitReached'));
|
|
|
+ throw new \Exception($this->get_lang('AdvancedSubscriptionTimeXLimitReached'));
|
|
|
}
|
|
|
} else {
|
|
|
- throw new \Exception($this->get_lang('AdvancedSubscriptionIncompleteInduction'));
|
|
|
+ throw new \Exception($this->get_lang('AdvancedSubscriptionCostXLimitReached'));
|
|
|
}
|
|
|
} else {
|
|
|
- throw new \Exception($this->get_lang('AdvancedSubscriptionProfileIncomplete'));
|
|
|
+ throw new \Exception($this->get_lang('AdvancedSubscriptionIncompleteInduction'));
|
|
|
}
|
|
|
} else {
|
|
|
- throw new \Exception($this->get_lang('AdvancedSubscriptionNotConnected'));
|
|
|
+ throw new \Exception($this->get_lang('AdvancedSubscriptionProfileIncomplete'));
|
|
|
}
|
|
|
-
|
|
|
- return $isAllowed;
|
|
|
} else {
|
|
|
- throw new \Exception($this->get_lang('AdvancedSubscriptionIncompleteParams'));
|
|
|
+ throw new \Exception($this->get_lang('AdvancedSubscriptionNotConnected'));
|
|
|
}
|
|
|
|
|
|
+ return $isAllowed;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -213,6 +253,7 @@ class AdvancedSubscriptionPlugin extends Plugin implements HookPluginInterface
|
|
|
$queueTable = Database::get_main_table(TABLE_ADVANCED_SUBSCRIPTION_QUEUE);
|
|
|
$attributes = array(
|
|
|
'last_message_id' => $mailId,
|
|
|
+ 'updated_at' => api_get_utc_datetime(),
|
|
|
);
|
|
|
|
|
|
$num = Database::update(
|
|
@@ -254,7 +295,7 @@ class AdvancedSubscriptionPlugin extends Plugin implements HookPluginInterface
|
|
|
|
|
|
/**
|
|
|
* Send message for the student subscription approval to a specific session
|
|
|
- * @param int $studentId
|
|
|
+ * @param int|array $studentId
|
|
|
* @param int $receiverId
|
|
|
* @param string $subject
|
|
|
* @param string $content
|
|
@@ -272,7 +313,14 @@ class AdvancedSubscriptionPlugin extends Plugin implements HookPluginInterface
|
|
|
|
|
|
if ($save && !empty($mailId)) {
|
|
|
// Save as sent message
|
|
|
- $this->saveLastMessage($mailId, $studentId, $sessionId);
|
|
|
+ if (is_array($studentId) && !empty($studentId)) {
|
|
|
+ foreach ($studentId as $student) {
|
|
|
+ $this->saveLastMessage($mailId, $student['user_id'], $sessionId);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $studentId = intval($studentId);
|
|
|
+ $this->saveLastMessage($mailId, $studentId, $sessionId);
|
|
|
+ }
|
|
|
}
|
|
|
return $mailId;
|
|
|
}
|
|
@@ -542,6 +590,50 @@ class AdvancedSubscriptionPlugin extends Plugin implements HookPluginInterface
|
|
|
);
|
|
|
}
|
|
|
break;
|
|
|
+ case ADVANCED_SUBSCRIPTION_ACTION_REMINDER_STUDENT:
|
|
|
+ $mailIds['render'] = $this->sendMailMessage(
|
|
|
+ $data['student']['user_id'],
|
|
|
+ $data['student']['user_id'],
|
|
|
+ $this->get_lang('MailRemindStudent'),
|
|
|
+ $template->fetch('/advanced_subscription/views/reminder_notice_student.tpl'),
|
|
|
+ $data['sessionId'],
|
|
|
+ true
|
|
|
+ );
|
|
|
+ break;
|
|
|
+ case ADVANCED_SUBSCRIPTION_ACTION_REMINDER_SUPERIOR:
|
|
|
+ $mailIds['render'] = $this->sendMailMessage(
|
|
|
+ $data['students'],
|
|
|
+ $data['superior']['user_id'],
|
|
|
+ $this->get_lang('MailRemindSuperior'),
|
|
|
+ $template->fetch('/advanced_subscription/views/reminder_notice_superior.tpl'),
|
|
|
+ $data['sessionId'],
|
|
|
+ true
|
|
|
+ );
|
|
|
+ break;
|
|
|
+ case ADVANCED_SUBSCRIPTION_ACTION_REMINDER_SUPERIOR_MAX:
|
|
|
+ $mailIds['render'] = $this->sendMailMessage(
|
|
|
+ $data['students'],
|
|
|
+ $data['superior']['user_id'],
|
|
|
+ $this->get_lang('MailRemindSuperior'),
|
|
|
+ $template->fetch('/advanced_subscription/views/reminder_notice_superior_max.tpl'),
|
|
|
+ $data['sessionId'],
|
|
|
+ true
|
|
|
+ );
|
|
|
+ break;
|
|
|
+ case ADVANCED_SUBSCRIPTION_ACTION_REMINDER_ADMIN:
|
|
|
+ // Mail to admin
|
|
|
+ foreach ($data['admins'] as $adminId => $admin) {
|
|
|
+ $template->assign('admin', $admin);
|
|
|
+ $mailIds[] = $this->sendMailMessage(
|
|
|
+ $data['students'],
|
|
|
+ $adminId,
|
|
|
+ $this->get_lang('MailRemindAdmin'),
|
|
|
+ $template->fetch('/advanced_subscription/views/reminder_notice_admin.tpl'),
|
|
|
+ $data['sessionId'],
|
|
|
+ true
|
|
|
+ );
|
|
|
+ }
|
|
|
+ break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
@@ -664,6 +756,8 @@ class AdvancedSubscriptionPlugin extends Plugin implements HookPluginInterface
|
|
|
if ($vacancy >= 0) {
|
|
|
|
|
|
return $vacancy;
|
|
|
+ } else {
|
|
|
+ return 0;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -686,7 +780,7 @@ class AdvancedSubscriptionPlugin extends Plugin implements HookPluginInterface
|
|
|
$extraField = new ExtraField('session');
|
|
|
// Get session fields
|
|
|
$fieldList = $extraField->get_all(array(
|
|
|
- 'field_variable IN ( ?, ?, ?, ?, ?)' => $fieldsArray
|
|
|
+ 'field_variable IN ( ?, ?, ?, ?, ?, ?, ? )' => $fieldsArray
|
|
|
));
|
|
|
// Index session fields
|
|
|
$fields = array();
|
|
@@ -711,6 +805,12 @@ class AdvancedSubscriptionPlugin extends Plugin implements HookPluginInterface
|
|
|
}
|
|
|
$sessionArray['description'] = SessionManager::getDescriptionFromSessionId($sessionId);
|
|
|
|
|
|
+ if (isset($sessionArray['brochure'])) {
|
|
|
+ $sessionArray['brochure'] = api_get_path(WEB_CODE_PATH) . $sessionArray['brochure'];
|
|
|
+ }
|
|
|
+ if (isset($sessionArray['banner'])) {
|
|
|
+ $sessionArray['banner'] = api_get_path(WEB_CODE_PATH) . $sessionArray['banner'];
|
|
|
+ }
|
|
|
return $sessionArray;
|
|
|
}
|
|
|
|
|
@@ -783,7 +883,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;
|