diff --git a/plugin/advancedsubscription/lang/spanish.php b/plugin/advancedsubscription/lang/spanish.php index f833606f65..76eabeb901 100644 --- a/plugin/advancedsubscription/lang/spanish.php +++ b/plugin/advancedsubscription/lang/spanish.php @@ -7,8 +7,8 @@ $strings['ws_url'] = 'URL del Webservice'; $strings['ws_url_help'] = 'La URL de la cual se solicitará información para el proceso de la inscripción avanzada'; $strings['check_induction'] = 'Activar requerimiento de curso inducción'; $strings['check_induction_help'] = 'Escoja si se requiere que se complete los cursos de inducción'; -$strings['tool_enable'] = 'Suscripción avanzada activada'; -$strings['tool_enable_help'] = "Escoja si desea activar la suscripción avanzada."; +$strings['tool_enable'] = 'Inscripción avanzada activada'; +$strings['tool_enable_help'] = "Escoja si desea activar la inscripción avanzada."; $strings['yearly_cost_limit'] = 'Límite de UITs'; $strings['yearly_cost_limit_help'] = "El límite de UITs de cursos que se pueden llevar en un año calendario del año actual."; $strings['yearly_hours_limit'] = 'Límite de horas lectivas'; @@ -29,5 +29,8 @@ $strings['AdvancedSubscriptionCostXLimitReached'] = "Lo sentimos, usted ya ha al $strings['AdvancedSubscriptionTimeXLimitReached'] = "Lo sentimos, usted ya ha alcanzado el límite anual de %s horas para los cursos que ha seguido este año"; $strings['AdvancedSubscriptionCourseXLimitReached'] = "Lo sentimos, usted ya ha alcanzado el límite anual de %s cursos que ha seguido este año"; $strings['AdvancedSubscriptionNotMoreAble'] = "Lo sentimos, usted ya no cumple con las condiciones iniciales para poder inscribirse al curso"; +$strings['AdvancedSubscriptionIncompleteParams'] = "Los parámetros enviados no están completos o no son los correctos."; + +$strings['AdvancedSubscriptionIsNotEnabled'] = "La inscripción avanzada no está activada"; //Needed in order to show the plugin title diff --git a/plugin/advancedsubscription/src/advanced_subscription_plugin.class.php b/plugin/advancedsubscription/src/advanced_subscription_plugin.class.php index 499e2846e9..334d8ecff5 100644 --- a/plugin/advancedsubscription/src/advanced_subscription_plugin.class.php +++ b/plugin/advancedsubscription/src/advanced_subscription_plugin.class.php @@ -9,6 +9,11 @@ class AdvancedSubscriptionPlugin extends Plugin { + const ADVSUB_QUEUE_STATUS_START = 0; + const ADVSUB_QUEUE_STATUS_BOSS_DISAPPROVED = 1; + const ADVSUB_QUEUE_STATUS_BOSS_APPROVED = 2; + const ADVSUB_QUEUE_STATUS_ADMIN_DISAPPROVED = 3; + const ADVSUB_QUEUE_STATUS_ADMIN_APPROVED = 10; /** * Constructor */ @@ -57,7 +62,7 @@ class AdvancedSubscriptionPlugin extends Plugin */ public function uninstall() { - $this->unistallDatabase(); + $this->uninstallDatabase(); } /** @@ -127,60 +132,68 @@ class AdvancedSubscriptionPlugin extends Plugin /** * Return true if user is able to be added to queue for session subscription - * @param $userId + * @param int $userId + * @param array $params MUST have keys: + * "is_connected" Indicate if the user is online on external web + * "profile_completed" Percentage of completed profile, given by WS * @throws Exception * @return bool */ - public function isAbleToRequest($userId) + public function isAbleToRequest($userId, $params = array()) { - $isAble = false; - $advSubPlugin = self::create(); - $wsUrl = $advSubPlugin->get('ws_url'); - // @TODO: Get connection status from user by WS - $isConnected = true; - if ($isConnected) { - $profileCompletedMin = $advSubPlugin->get('min_profile_percentage'); - // @TODO: Get completed profile percentage by WS - $profileCompleted = 100.0; - if ($profileCompleted > $profileCompletedMin) { - $checkInduction = $advSubPlugin->get('check_induction'); - // @TODO: check if user have completed at least one induction session - $completedInduction = true; - if (!$checkInduction || $completedInduction) { - $uitMax = $advSubPlugin->get('yearly_cost_unit_converter'); - $uitMax *= $advSubPlugin->get('yearly_cost_limit'); - // @TODO: Get UIT completed by user this year by WS - $uitUser = 0; - if ($uitMax > $uitUser) { - $expendedTimeMax = $advSubPlugin->get('yearly_hours_limit'); - // @TODO: Get Expended time from user data - $expendedTime = 0; - if ($expendedTimeMax > $expendedTime) { - $expendedNumMax = $advSubPlugin->get('courses_count_limit'); - // @TODO: Get Expended num from user - $expendedNum = 0; - if ($expendedNumMax > $expendedNum) { - $isAble = true; + if (isset($params['is_connected']) && isset($params['profile_completed'])) { + $isAble = false; + $advSubPlugin = self::create(); + $wsUrl = $advSubPlugin->get('ws_url'); + // @TODO: Get connection status from user by WS + $isConnected = $params['is_connected']; + if ($isConnected) { + $profileCompletedMin = $advSubPlugin->get('min_profile_percentage'); + // @TODO: Get completed profile percentage by WS + $profileCompleted = (float) $params['profile_completed']; + if ($profileCompleted > $profileCompletedMin) { + $checkInduction = $advSubPlugin->get('check_induction'); + // @TODO: check if user have completed at least one induction session + $completedInduction = true; + if (!$checkInduction || $completedInduction) { + $uitMax = $advSubPlugin->get('yearly_cost_unit_converter'); + $uitMax *= $advSubPlugin->get('yearly_cost_limit'); + // @TODO: Get UIT completed by user this year by WS + $uitUser = 0; + if ($uitMax > $uitUser) { + $expendedTimeMax = $advSubPlugin->get('yearly_hours_limit'); + // @TODO: Get Expended time from user data + $expendedTime = 0; + if ($expendedTimeMax > $expendedTime) { + $expendedNumMax = $advSubPlugin->get('courses_count_limit'); + // @TODO: Get Expended num from user + $expendedNum = 0; + if ($expendedNumMax > $expendedNum) { + $isAble = true; + } else { + throw new \Exception(get_lang('AdvancedSubscriptionCourseXLimitReached')); + } } else { - throw new \Exception(get_lang('AdvancedSubscriptionCourseXLimitReached')); + throw new \Exception(get_lang('AdvancedSubscriptionTimeXLimitReached')); } } else { - throw new \Exception(get_lang('AdvancedSubscriptionTimeXLimitReached')); + throw new \Exception(get_lang('AdvancedSubscriptionCostXLimitReached')); } } else { - throw new \Exception(get_lang('AdvancedSubscriptionCostXLimitReached')); + throw new \Exception(get_lang('AdvancedSubscriptionIncompleteInduction')); } } else { - throw new \Exception(get_lang('AdvancedSubscriptionIncompleteInduction')); + throw new \Exception(get_lang('AdvancedSubscriptionProfileIncomplete')); } } else { - throw new \Exception(get_lang('AdvancedSubscriptionProfileIncomplete')); + throw new \Exception(get_lang('AdvancedSubscriptionNotConnected')); } + + return $isAble; } else { - throw new \Exception(get_lang('AdvancedSubscriptionNotConnected')); + throw new \Exception($this->get_lang('AdvancedSubscriptionIncompleteParams')); } - return $isAble; } /** @@ -223,71 +236,98 @@ class AdvancedSubscriptionPlugin extends Plugin } /** - * Check whether the tour should be displayed to the user - * @param string $currentPageClass The class of the current page - * @param int $userId The user id - * @return boolean If the user has seen the tour return false, otherwise return true + * Check if session is open for subscription + * @param $sessionId + * @param string $fieldVariable + * @return bool */ - public function checkTourForUser($currentPageClass, $userId) + public function isSessionOpen($sessionId, $fieldVariable = 'es_abierta') { - $pAdvSubQueueTable = Database::get_main_table(TABLE_ADV_SUB_QUEUE); - $pAdvSubMailTable = Database::get_main_table(TABLE_ADV_SUB_MAIL); - $pAdvSubMailTypeTable = Database::get_main_table(TABLE_ADV_SUB_MAIL_TYPE); - $pAdvSubMailStatusTable = Database::get_main_table(TABLE_ADV_SUB_MAIL_STATUS); - $pluginTourLogTable = Database::get_main_table(TABLE_TOUR_LOG); - - $checkResult = Database::select('count(1) as qty', $pluginTourLogTable, array( - 'where' => array( - "page_class = '?' AND " => $currentPageClass, - "user_id = ?" => intval($userId) - )), 'first'); - - if ($checkResult !== false) { - if ($checkResult['qty'] > 0) { - return false; + $sessionId = (int) $sessionId; + $fieldVariable = Database::escape_string($fieldVariable); + $isOpen = false; + if ($sessionId > 0 && !empty($fieldVariable)) { + $sfTable = Database::get_main_table(TABLE_MAIN_SESSION_FIELD); + $sfvTable = Database::get_main_table(TABLE_MAIN_SESSION_FIELD_VALUES); + $joinTable = $sfvTable . ' sfv INNER JOIN ' . $sfTable . ' sf ON sfv.field_id = sf.id '; + $row = Database::select( + 'sfv.field_value as field_value', + $joinTable, + array( + 'where' => array( + 'sfv.session_id = ? AND ' => $sessionId, + 'sf.field_variable = ?' => $fieldVariable, + ) + ) + ); + if (isset($row[0]) && is_array($row[0])) { + $isOpen = (bool) $row[0]['field_value']; } } - return true; + return $isOpen; } - /** - * Set the tour as seen - * @param string $currentPageClass The class of the current page - * @param int $userId The user id - * @return void - */ - public function saveCompletedTour($currentPageClass, $userId) + public function approvedByBoss() { - $pAdvSubQueueTable = Database::get_main_table(TABLE_ADV_SUB_QUEUE); - $pAdvSubMailTable = Database::get_main_table(TABLE_ADV_SUB_MAIL); - $pAdvSubMailTypeTable = Database::get_main_table(TABLE_ADV_SUB_MAIL_TYPE); - $pAdvSubMailStatusTable = Database::get_main_table(TABLE_ADV_SUB_MAIL_STATUS); - $pluginTourLogTable = Database::get_main_table(TABLE_TOUR_LOG); - Database::insert($pluginTourLogTable, array( - 'page_class' => $currentPageClass, - 'user_id' => intval($userId), - 'visualization_datetime' => api_get_utc_datetime() - )); } - /** - * Get the configuration to show the tour in pages - * @return array The config data - */ - public function getTourConfig() + public function disapprovedByBoss() { - $pAdvSubQueueTable = Database::get_main_table(TABLE_ADV_SUB_QUEUE); - $pAdvSubMailTable = Database::get_main_table(TABLE_ADV_SUB_MAIL); - $pAdvSubMailTypeTable = Database::get_main_table(TABLE_ADV_SUB_MAIL_TYPE); - $pAdvSubMailStatusTable = Database::get_main_table(TABLE_ADV_SUB_MAIL_STATUS); - $pluginPath = api_get_path(PLUGIN_PATH) . 'tour/'; - $jsonContent = file_get_contents($pluginPath . 'config/tour.json'); + } - $jsonData = json_decode($jsonContent, true); + public function approvedByAdmin() + { - return $jsonData; + } + + public function disapprovedByAdmin() + { + + } + + public function confirmTermsAndConditions() + { + + } + + public function checkToken() + { + + } + + public function sendMail() + { + + } + + /** + * Count the users in queue filtered by params (sessions, status) + * @param array $params Input array containing the set of + * session and status to count from queue + * e.g: + * array('sessions' => array(215, 218, 345, 502), + * 'status' => array(0, 1, 2)) + * @return int + */ + public function countQueueByParams($params) + { + $count = 0; + if (!empty($params) && is_array($params)) { + $advsubQueueTable = Database::get_main_table(TABLE_ADV_SUB_QUEUE); + $where['1 = ? '] = 1; + if (isset($params['sessions']) && is_array($params['sessions'])) { + $where['AND session_id IN ( ? ) '] = implode($params['sessions']); + } + if (isset($params['status']) && is_array($params['status'])) { + $where['AND status IN ( ? ) '] = implode($params['status']); + } + $where['where'] = $where; + $count = Database::select('COUNT(*)', $advsubQueueTable, $where); + $count = $count[0]; + } + return $count; } } diff --git a/plugin/advancedsubscription/src/index.php b/plugin/advancedsubscription/src/index.php index b3d9bbc7f3..1c6ecb8580 100644 --- a/plugin/advancedsubscription/src/index.php +++ b/plugin/advancedsubscription/src/index.php @@ -1 +1,31 @@ get_lang('CourseListOnSale'); + $templateName = $plugin->get_lang('BuyCourses'); + + $tpl = new Template($templateName); + $tpl->assign('isAdmin', $isAdmin); + $tpl->assign('title', $title); + $tpl->assign('BuySessions', $plugin->get_lang('BuySessions')); + $tpl->assign('BuyCourses', $templateName); + $tpl->assign('ConfigurationOfSessionsAndPrices', $plugin->get_lang('ConfigurationOfSessionsAndPrices')); + $tpl->assign('ConfigurationOfCoursesAndPrices', $plugin->get_lang('ConfigurationOfCoursesAndPrices')); + $tpl->assign('ConfigurationOfPayments', $plugin->get_lang('ConfigurationOfPayments')); + $tpl->assign('OrdersPendingOfPayment', $plugin->get_lang('OrdersPendingOfPayment')); + $listing_tpl = 'buycourses/view/index.tpl'; + $content = $tpl->fetch($listing_tpl); + $tpl->assign('content', $content); + // If the user is NOT an administrator, redirect it to course/session buy list + $isAdmin ? $tpl->display_one_col_template() : header('Location: src/list.php'); +}