@ -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->unin stallDatabase();
}
/**
@ -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('AdvancedSubscriptionTim eXLimitReached'));
}
} else {
throw new \Exception(get_lang('AdvancedSubscriptionTime XLimitReached'));
throw new \Exception(get_lang('AdvancedSubscriptionCost XLimitReached'));
}
} 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('AdvancedSubscriptionProfile Incomplete'));
}
} 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;
}
}