Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 13
CRAP
0.00% covered (danger)
0.00%
0 / 229
NotificationSettingsService
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 13
1806.00
0.00% covered (danger)
0.00%
0 / 229
 __construct
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 3
 __clone
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 2
 getInstance
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 7
 addUserSettings
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 3
 addGlobalSettings
0.00% covered (danger)
0.00%
0 / 1
12.00
0.00% covered (danger)
0.00%
0 / 14
 updateGlobalSettings
0.00% covered (danger)
0.00%
0 / 1
12.00
0.00% covered (danger)
0.00%
0 / 12
 updateCustomValueSettingsInGlobalSettingsAndScheduler
0.00% covered (danger)
0.00%
0 / 1
42.00
0.00% covered (danger)
0.00%
0 / 40
 updateCustomValueSettingsInGlobalSettingsAndSchedulerForNotificationsAboutUnmarkedAttendance
0.00% covered (danger)
0.00%
0 / 1
30.00
0.00% covered (danger)
0.00%
0 / 38
 updateCustomValueSettingsInGlobalSettingsAndSchedulerForUnmarkedHourReminder
0.00% covered (danger)
0.00%
0 / 1
20.00
0.00% covered (danger)
0.00%
0 / 32
 updateSchedulerForTimetableReminderSms
0.00% covered (danger)
0.00%
0 / 1
30.00
0.00% covered (danger)
0.00%
0 / 31
 updateCustomValueSettingsInGlobalSettings
0.00% covered (danger)
0.00%
0 / 1
12.00
0.00% covered (danger)
0.00%
0 / 12
 getAllGlobalSettings
0.00% covered (danger)
0.00%
0 / 1
12.00
0.00% covered (danger)
0.00%
0 / 14
 getSingleGlobalSettings
0.00% covered (danger)
0.00%
0 / 1
30.00
0.00% covered (danger)
0.00%
0 / 21
<?php
namespace com\linways\core\ams\professional\service\notification;
use com\linways\core\ams\professional\constant\SchedulerCodesConstant;
use com\linways\core\ams\professional\exception\ProfessionalException;
use com\linways\core\ams\professional\mapper\notification\NotificationSettingsServiceMapper;
use com\linways\core\ams\professional\request\notification\GetGlobalSettingsRequest;
use com\linways\core\ams\professional\service\BaseService;
use com\linways\nucleus\core\service\SchedulerService;
class NotificationSettingsService extends BaseService
{
    // /Condition 1 - Presence of a static member variable
    private static $_instance = null;
    private $mapper = [];
    // /Condition 2 - Locked down the constructor
    private function __construct()
    {
        $this->mapper = NotificationSettingsServiceMapper::getInstance()->getMapper();
    }
    // Prevent any oustide instantiation of this class
    // /Condition 3 - Prevent any object or instance of that class to be cloned
    private function __clone()
    {
    }
    // Prevent any copy of this object
    // /Condition 4 - Have a single globally accessible static method
    public static function getInstance()
    {
        if (!is_object(self::$_instance))// or if( is_null(self::$_instance) ) or if( self::$_instance == null )
        {
            self::$_instance = new self();
        }
        return self::$_instance;
    }
    /**
     * [addUserSettings description]
     * @param [type] $userSettingsList [description]
     */
    public function addUserSettings($userSettingsList)
    {
        $sql = "";
    }
    /**
     * [addGlobalSettings description]
     * @param [type] $globalSettingsList [description]
     */
    public function addGlobalSettings($globalSettingsList)
    {
        $sql = "";
        $globalSettingsList = $this->realEscapeArray($globalSettingsList);
        $sql = "INSERT INTO `notification_settings_global` (`context`, `feature`, `name`, `push_notification_enabled`, `native_enabled`, `email_enabled`, `sms_enabled`, `created_by`, `updated_by`, `created_date`, `updated_date`) VALUES ";
        foreach ($globalSettingsList as $globalSettings) {
            $sql .= "('$globalSettings->context', '$globalSettings->feature', '$globalSettings->name', '$globalSettings->pushNotificationEnabled', '$globalSettings->nativeEnabled', '$globalSettings->emailEnabled', '$globalSettings->smsEnabled', '$globalSettings->createdBy', '$globalSettings->updatedBy', UTC_TIMESTAMP(), UTC_TIMESTAMP()),";
        }
        $sql = rtrim($sql, ",");
        try {
            $this->executeQuery($sql);
        } catch (\Exception $e) {
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
    }
    /**
     * [addGlobalSettings description]
     * @param [type] $globalSettingsList [description]
     */
    public function updateGlobalSettings($globalSettingsList)
    {
        $sql = "";
        $globalSettingsList = $this->realEscapeArray($globalSettingsList);
        foreach ($globalSettingsList as $globalSettings) {
            $sql .= "UPDATE notification_settings_global SET native_enabled = $globalSettings->nativeEnabled, push_notification_enabled = '$globalSettings->pushNotificationEnabled', email_enabled = '$globalSettings->emailEnabled', sms_enabled = '$globalSettings->smsEnabled' WHERE id = $globalSettings->id;";
        }
        try {
            $this->executeQuery($sql);
        } catch (\Exception $e) {
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
    }
    /**
     *
     * @param unknown $globalSettingsList
     * @throws ProfessionalException
     * @author gadheyan
     */
    public function updateCustomValueSettingsInGlobalSettingsAndScheduler($globalSettingsList)
    {
        $sql = "";
        $globalSettingsList = $this->realEscapeArray($globalSettingsList);
        foreach ($globalSettingsList as $globalSettings) {
            $sql .= "UPDATE notification_settings_global SET  custom_settings_value = '" . json_encode($globalSettings->customSettingsValue) . "' WHERE id=$globalSettings->id;";
        }
        try {
            $this->executeQuery($sql);
        } catch (\Exception $e) {
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
        try {
            $schedule = new \stdClass();
            $schedule->params = [];
            $schedule->method = "com\\linways\\core\\ams\\professional\\service\\notification\\NotificationHelperService::sendSmsForTodaysUnmarkedFaculty";
            $schedule->params["command"] = 'EXECUTE SERVICE';
            $schedule->params["taskParams"] = [];
            $schedule->params["taskParams"]["className"] = "com\\\\linways\\\\core\\\\ams\\\\professional\\\\service\\\\notification\\\\NotificationHelperService";
            $schedule->params["taskParams"]["methodName"] = "sendSmsForTodaysUnmarkedFaculty";
            $schedule->params["taskParams"]["methodParams"] = [];
            $timeForSchedule = explode(':', $globalSettings->customSettingsValue['time']);
            $hour = $timeForSchedule[0];
            $minute = $timeForSchedule[1];
            $schedule->frequency = "$minute $hour" . " * * *";
            $schedule->code = SchedulerCodesConstant::SEND_SMS_TO_ATTENDANCE_UNMARKED_FACULTY;
            $schedule->code .= "_" . $GLOBALS['COLLEGE_CODE'];
            try {
                SchedulerService::getInstance()->deleteScheduledTaskByCode($schedule->code);
            } catch (\Exception $e) {
                throw new ProfessionalException($e->getCode(), $e->getMessage());
            }
            try {
                $schedule->id = SchedulerService::getInstance()->addTask($schedule);
                SchedulerService::getInstance()->updateNextExecution($schedule);
            } catch (\Exception $e) {
                throw new ProfessionalException($e->getCode(), $e->getMessage());
            }
        } catch (\Exception $e) {
        }
    }
    public function updateCustomValueSettingsInGlobalSettingsAndSchedulerForNotificationsAboutUnmarkedAttendance($globalSettings)
    {
        $sql = "";
        $globalSettings = $this->realEscapeObject($globalSettings);
        $sql = "UPDATE notification_settings_global SET  custom_settings_value = '" . json_encode($globalSettings->customSettingsValue) . "' WHERE id=$globalSettings->id;";
        try {
            $this->executeQuery($sql);
        } catch (\Exception $e) {
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
        try {
            $schedule = new \stdClass();
            $schedule->params = [];
            $schedule->method = "com\\linways\\core\\ams\\professional\\service\\notification\\ScheduledNotifications::unmarkedAttendanceReminder";
            $schedule->params["command"] = 'EXECUTE SERVICE';
            $schedule->params["taskParams"] = [];
            $schedule->params["taskParams"]["className"] = "com\\\\linways\\\\core\\\\ams\\\\professional\\\\service\\\\notification\\\\ScheduledNotifications";
            $schedule->params["taskParams"]["methodName"] = "unmarkedAttendanceReminder";
            $schedule->params["taskParams"]["methodParams"] = [];
            $timeForSchedule = explode(':', $globalSettings->customSettingsValue['time']);
            $hour = $timeForSchedule[0];
            $minute = $timeForSchedule[1];
            $schedule->frequency = "$minute $hour" . " " . $globalSettings->customSettingsValue['dates'] . " * *";
            $schedule->code = SchedulerCodesConstant::SEND_NOTIFICATIONS_ABOUT_UNMARKED_ATTENDANCE;
            $schedule->code .= "_" . $GLOBALS['COLLEGE_CODE'];
            try {
                SchedulerService::getInstance()->deleteScheduledTaskByCode($schedule->code);
            } catch (\Exception $e) {
                throw new ProfessionalException($e->getCode(), $e->getMessage());
            }
            try {
                $schedule->id = SchedulerService::getInstance()->addTask($schedule);
                SchedulerService::getInstance()->updateNextExecution($schedule);
            } catch (\Exception $e) {
                throw new ProfessionalException($e->getCode(), $e->getMessage());
            }
        } catch (\Exception $e) {
        }
    }
    public function updateCustomValueSettingsInGlobalSettingsAndSchedulerForUnmarkedHourReminder($globalSettings)
    {
        $sql = "";
        $globalSettings = $this->realEscapeObject($globalSettings);
        $sql = "UPDATE notification_settings_global SET  custom_settings_value = '" . addslashes(json_encode($globalSettings->customSettingsValue)) . "' WHERE id=$globalSettings->id;";
        try {
            $this->executeQuery($sql);
        } catch (\Exception $e) {
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
        $schedule = new \stdClass();
        $schedule->params = [];
        $schedule->method = "com\\linways\\core\\ams\\professional\\service\\notification\\ScheduledNotifications::unmarkedHourDetails";
        $schedule->params["command"] = 'EXECUTE SERVICE';
        $schedule->params["taskParams"] = [];
        $schedule->params["taskParams"]["className"] = "com\\\\linways\\\\core\\\\ams\\\\professional\\\\service\\\\notification\\\\ScheduledNotifications";
        $schedule->params["taskParams"]["methodName"] = "unmarkedHourDetails";
        $schedule->params["taskParams"]["methodParams"] = [];
        $schedule->frequency = "00 00 " . $globalSettings->customSettingsValue['date'] . " * *";
        $schedule->code = SchedulerCodesConstant::SEND_NOTIFICATIONS_ABOUT_UNMARKED_HOUR_REMINDER;
        $schedule->code .= "_" . $GLOBALS['COLLEGE_CODE'];
        try {
            SchedulerService::getInstance()->deleteScheduledTaskByCode($schedule->code);
        } catch (\Exception $e) {
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
        try {
            $schedule->id = SchedulerService::getInstance()->addTask($schedule);
            SchedulerService::getInstance()->updateNextExecution($schedule);
        } catch (\Exception $e) {
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
    }
    public function updateSchedulerForTimetableReminderSms($deleteScheduler)
    {
        try {
            $schedule = new \stdClass();
            $schedule->params = [];
            $schedule->method = "com\\linways\\core\\ams\\professional\\service\\notification\\ScheduledNotifications::timeTableReminderSms";
            $schedule->params["command"] = 'EXECUTE SERVICE';
            $schedule->params["taskParams"] = [];
            $schedule->params["taskParams"]["className"] = "com\\\\linways\\\\core\\\\ams\\\\professional\\\\service\\\\notification\\\\ScheduledNotifications";
            $schedule->params["taskParams"]["methodName"] = "timeTableReminderSms";
            $schedule->params["taskParams"]["methodParams"] = [];
            $schedule->frequency = "00 00 * * 0";//Every Sunday at 00
            $schedule->code = SchedulerCodesConstant::SEND_TIMETABLE_REMINDER_SMS;
            $schedule->code .= "_" . $GLOBALS['COLLEGE_CODE'];
            if ($deleteScheduler) {
                try {
                    SchedulerService::getInstance()->deleteScheduledTaskByCode($schedule->code);
                } catch (\Exception $e) {
                    throw new ProfessionalException($e->getCode(), $e->getMessage());
                }
            } else {
                try {
                    $schedule->id = SchedulerService::getInstance()->addTask($schedule);
                    SchedulerService::getInstance()->updateNextExecution($schedule);
                } catch (\Exception $e) {
                    throw new ProfessionalException($e->getCode(), $e->getMessage());
                }
            }
        } catch (\Exception $e) {
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
    }
    public function updateCustomValueSettingsInGlobalSettings($globalSettingsList)
    {
        $sql = "";
        $globalSettingsList = $this->realEscapeArray($globalSettingsList);
        foreach ($globalSettingsList as $globalSettings) {
            $sql .= "UPDATE notification_settings_global SET  custom_settings_value = '" . json_encode($globalSettings->customSettingsValue) . "' WHERE id=$globalSettings->id;";
        }
        try {
            $this->executeQuery($sql);
        } catch (\Exception $e) {
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
    }
    /**
     * [getAllGlobalSettings description]
     * @param GetGlobalSettingsRequest $globalsettingsRequest [description]
     * @return [type]                                          [description]
     */
    public function getAllGlobalSettings()
    {
        $sql = "";
        $response = [];
        $sql = "SELECT id as notification_settings_global_id, name as notification_settings_global_name, description as  notification_settings_global_description, notification_type_id as  notification_settings_global_notification_type_id, custom_settings_value as  notification_settings_global_custom_settings_value,  is_custom_settings_flag as  notification_settings_global_is_custom_settings_flag, push_notification_enabled as notification_settings_global_push_notification_enabled, native_enabled as notification_settings_global_native_enabled, email_enabled as notification_settings_global_email_enabled, sms_enabled as notification_settings_global_sms_enabled FROM notification_settings_global ";
        try {
            $response = $this->executeQueryForList($sql, $this->mapper[NotificationSettingsServiceMapper::GETGLOBALSETTINGS]);
            foreach ($response as $globalSettings) {
                $globalSettings->customSettingsValue = json_decode($globalSettings->customSettingsValue);
            }
        } catch (\Exception $e) {
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
        return $response;
    }
    /**
     * [getGlobalSettings description]
     * @param GetGlobalSettingsRequest $globalsettingsRequest [description]
     * @return [type]                                          [description]
     */
    public function getSingleGlobalSettings(GetGlobalSettingsRequest $globalsettingsRequest)
    {
        $sql = "";
        $response = [];
        $globalsettingsRequest = $this->realEscapeObject($globalsettingsRequest);
        if ($globalsettingsRequest->context && $globalsettingsRequest->feature) {
            $sql = "SELECT id FROM notification_type WHERE context = '$globalsettingsRequest->context' AND feature = '$globalsettingsRequest->feature'";
            try {
                $globalsettingsRequest->notificationTypeId = $this->executeQueryForObject($sql)->id;
            } catch (\Exception $e) {
                throw new ProfessionalException($e->getCode(), $e->getMessage());
            }
        }
        $sql = "SELECT id as notification_settings_global_id, name as notification_settings_global_name, description as notification_settings_global_description,custom_settings_value as notification_settings_global_custom_settings_value, notification_type_id as notification_settings_global_notification_type_id, is_custom_settings_flag as notification_settings_global_is_custom_settings_flag, push_notification_enabled as notification_settings_global_push_notification_enabled, native_enabled as notification_settings_global_native_enabled, email_enabled as notification_settings_global_email_enabled, sms_enabled as notification_settings_global_sms_enabled FROM notification_settings_global WHERE notification_type_id = '$globalsettingsRequest->notificationTypeId'";
        try {
            $response = $this->executeQueryForObject($sql, false, $this->mapper[NotificationSettingsServiceMapper::GETGLOBALSETTINGS]);
            $response->customSettingsValue = json_decode($response->customSettingsValue);
        } catch (\Exception $e) {
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
        return $response;
    }
}