Exemplo n.º 1
0
function notifyCourseJoined($users_info)
{
    $_JLMS_PLUGINS =& JLMSFactory::getPlugins();
    $JLMS_CONFIG =& JLMSFactory::getConfig();
    //---->get bot info
    $dbo =& JFactory::GetDbo();
    if (!isset($_JLMS_PLUGINS->_nontify_bot_params['coursejoinnotify'])) {
        // load mambot params info
        $query = "SELECT params" . "\n FROM #__lms_plugins" . "\n WHERE element = 'coursejoinnotify'" . "\n AND folder = 'notifications'";
        $dbo->setQuery($query);
        $bot = $dbo->loadObject();
        // save query to class variable
        $_JLMS_PLUGINS->_notify_bot_params['coursejoinnotify'] = $bot;
    }
    // pull query data from class variable
    $bot = $_JLMS_PLUGINS->_notify_bot_params['coursejoinnotify'];
    $botParams = new jlmsPluginParameters($bot->params);
    $botParams->def('mail_template', 'Hello {user_name}, You have just been added to the course {course_name} attendees list.');
    $botParams->def('mail_subject', 'Course joining notification');
    //<----
    foreach ($users_info as $info_ids) {
        $query = "SELECT c.course_name AS course_name, u.name AS user_name, u.email AS mail_address FROM #__lms_courses AS c, #__users AS u" . "\n WHERE c.id={$info_ids->course_id} AND u.id={$info_ids->user_id}";
        $dbo->setQuery($query);
        $info_text = $dbo->loadObject();
        $mail_address = $dbo->getEscaped($info_text->mail_address);
        $mail_subject = $dbo->getEscaped($botParams->get('mail_subject'));
        $mail_text = $botParams->get('mail_template');
        $mail_text = str_replace('{user_name}', $info_text->user_name, $mail_text);
        $mail_text = str_replace('{course_name}', $info_text->course_name, $mail_text);
        $mail_text = str_replace('{site_URL}', $JLMS_CONFIG->get('live_site'), $mail_text);
        $mail_text = $dbo->getEscaped($mail_text);
        $query = "INSERT INTO #__lms_notifications (assigned, mail_address, mail_subject, mail_body, sent) VALUES" . "\n ({$info_ids->teacher_id}, '{$mail_address}', '{$mail_subject}', '{$mail_text}', 0)";
        $dbo->setQuery($query);
        $dbo->query();
    }
}
Exemplo n.º 2
0
function botAssociateCEO($users_info)
{
    $_JLMS_PLUGINS =& JLMSFactory::getPlugins();
    $dbo =& JFactory::GetDbo();
    //---->get bot info
    if (!isset($_JLMS_PLUGINS->_user_bot_params['ceoassoc'])) {
        // load mambot params info
        $query = "SELECT params" . "\n FROM #__lms_plugins" . "\n WHERE element = 'ceoassoc'" . "\n AND folder = 'user'";
        $dbo->setQuery($query);
        $bot = $dbo->loadObject();
        // save query to class variable
        $_JLMS_PLUGINS->_user_bot_params['ceoassoc'] = $bot;
    }
    // pull query data from class variable
    $bot = $_JLMS_PLUGINS->_user_bot_params['ceoassoc'];
    $botParams = new jlmsPluginParameters($bot->params);
    $botParams->def('ceo_user_id', 0);
    //<----
    if ($parent_id = $botParams->get('ceo_user_id', 0)) {
        if (is_array($users_info)) {
            foreach ($users_info as $user_info) {
                //---->check if user already associated to CEO and add associate if not
                $query = "SELECT COUNT(*) FROM #__lms_user_parents WHERE parent_id = {$parent_id} AND user_id = {$user_info->user_id}";
                $dbo->setQuery($query);
                if (!$dbo->loadResult()) {
                    $query = "INSERT INTO #__lms_user_parents (`parent_id`, `user_id`) VALUES ({$parent_id}, {$user_info->user_id})";
                    $dbo->setQuery($query);
                    $dbo->query();
                }
                //<----
            }
        } else {
            $user_info = $users_info;
            //---->check if user already associated to CEO and add associate if not
            $query = "SELECT COUNT(*) FROM #__lms_user_parents WHERE parent_id = {$parent_id} AND user_id = {$user_info->user_id}";
            $dbo->setQuery($query);
            if (!$dbo->loadResult()) {
                $query = "INSERT INTO #__lms_user_parents (`parent_id`, `user_id`) VALUES ({$parent_id}, {$user_info->user_id})";
                $dbo->setQuery($query);
                $dbo->query();
            }
            //<----
        }
    }
    return;
}