Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This plugin is supported in the mobile app too, but it needs just a little fix #12

Open
ardiandeari opened this issue Apr 10, 2021 · 4 comments

Comments

@ardiandeari
Copy link

The notifications are received on the mobile app too. But when I click the 'VIEW' button it doesn't lead to the URL OF ACTIVITY but it only leads to the course... I found the code where can I change this:

$eventdata->contexturl = new \moodle_url('/course/view.php', ['id' => $eventdata->courseid]);

The code is in /classes/notification.php

Could you just change it to redirect to the activity (url of activity) instead of course id ?

@GuillaumeAllegre
Copy link
Contributor

In the notification message, the linkactivity should lead you directly to the activity.

If you think it's confusing for the user to display 2 links, or maybe it's a little bit too complex in the context of a mobile app, where notifications are shorter, you can simply delete linkcourse from the default message and keep only linkactivity.

Please tell me if it is convenient for your use.

@ardiandeari
Copy link
Author

Can this code be changed in order that it leads to the activity or resource: $eventdata->contexturl = new \moodle_url('/course/view.php', ['id' => $eventdata->courseid]);

I tried to delete the code and it deletes the 'view' button on the mobile.
Yes, I tried to delete this and right now for mobile use, our students only click on the link (not the 'view' button which is shown it the mobile app). Tons of thanks for creating such a great plugin!

View button screenshot 1
Without the view button screenshot 2

@udriss
Copy link

udriss commented Apr 13, 2021

Hello.

I saw the same thing as ardiandeari.

  • In order to resolve the situation, it is possible to add the $msgbodyinfo parameter when defining public static function send_notification in the local / resourcenotif / classes / notification.php file. We then go from three parameters to four.

  • Then, add $msgbodyinfo when calling the send_email function in the definition of send_notification (there are therefore two additions to be made here).

  • Then in the definition of private static function send_email, add the $msgbodyinfo parameter (we go from three parameters to four).

  • Then modify the line corresponding to contexturl in the definition of the send_email function by $eventdata-> contexturl = $msgbodyinfo['urlactivite'].

In this way, it will be possible to access the activity directly by clicking on the popup that appears without having to go through the course.
If you want to access the section containing the activity instead of the activity directly, you have to go a little further but it's always the same principle. It is the modification of contexturl that gives the desired result.

Then, it remains to modify the / local / resourcenotif / resourcenotif.php file by adding the $msgbodyinfo parameter when calling send_notification (between lines 110 and 140).

Best regards.

Code in local / resourcenotif / classes / notification.php

public static function send_notification($users, $msg, $infolog, $msgbodyinfo) {
        global $USER;
        $nb = 0;
        foreach ($users as $user) {
            $res = self::send_email($user, $msg, $infolog['courseid'],$msgbodyinfo);

            if ($res) {
                ++$nb;
            }
        $commande->closeCursor();
        }
        self::send_email($USER, $msg, $infolog['courseid'], $msgbodyinfo);
        $infolog['nb'] = $nb;
        return self::get_result_action_notification($infolog);
    }

    /**
     * construit le message d'interface après l'envoi groupé de notification
     *
     * @param array $infolog informations pour le log pour les envois de mails
     * @return string message interface
     */
    private static function get_result_action_notification($infolog) {
        if ($infolog['nb'] == 0) {
            return get_string('nomessagesend', 'local_resourcenotif');
        }
        $message = get_string('numbernotification', 'local_resourcenotif', $infolog['nb']);
        return $message;
    }

    /**
     * Envoie un email à l'adresse mail spécifiée
     *
     * @param string $email
     * @param object $msg
     * @param int $courseid
     * @return mixed false ou resultat de la fonction email_to_user()
     **/
    private static function send_email($user, $msg, $courseid, $msgbodyinfo) {
        global $USER;

        if (!isset($user->email) && empty($user->email)) {
            return false;
        }
        $eventdata = new \core\message\message();
        $eventdata->courseid = (int)$courseid;
        $eventdata->component = 'local_resourcenotif';
        $eventdata->name = 'resourcenotif_notification';
        $eventdata->userfrom = $USER;
        $eventdata->userto = $user;
        $eventdata->subject = $msg->subject;
        $eventdata->fullmessage = $msg->bodytext;
        $eventdata->fullmessagehtml = $msg->bodyhtml;
        // With FORMAT_HTML, most outputs will use fullmessagehtml, and convert it to plain text if necessary.
        // but some output plugins will behave differently (airnotifier only uses fullmessage)
        $eventdata->fullmessageformat = FORMAT_HTML;
        // If smallmessage is not empty,
        // it will have priority over the 2 other fields, with a hard coded FORMAT_PLAIN.
        // But some output plugins may need it, as jabber currently does.
        $eventdata->smallmessage = "";
        **$eventdata->contexturl = $msgbodyinfo['urlactivite'];**

 //new \moodle_url('/course/view.php', ['id' => $eventdata->courseid],'&section='); partie du code a retravailler si le choix se fait sur la section.

        return \message_send($eventdata);
    }

Code in / local / resourcenotif / resourcenotif.php

if ($formdata) {
	$con =  new mysqli("localhost","notifications","123456","moodle");

    $msg = notification::get_notification_message($mailsubject, $msgbodyinfo, $formdata->complement);
    if ($formdata->send == 'all') {
        if (count($notifiedStudents)) {
            $msgresult = notification::send_notification($notifiedStudents, $msg, $infolog, $msgbodyinfo);
        }
    } elseif ($formdata->send == 'selection') {
        $groups = [];
        if (isset($formdata->groups) && count($formdata->groups)) {
           $groups =  $formdata->groups;
        }
        $groupings = [];
        if (isset($formdata->groupings) && count($formdata->groupings)) {
           $groupings =  $formdata->groupings;
        }
        $grpNotifiedStudents = notifstudents::get_users_recipients($groups, $groupings);
        if (count($grpNotifiedStudents)) {
            $msgresult = notification::send_notification($grpNotifiedStudents, $msg, $infolog, $msgbodyinfo);
        }
    } elseif ($formdata->send == 'selectionstudents') {
        $listidstudents = $formdata->students;
        if (count($listidstudents)) {
            $notifiedS = [];
            foreach ($listidstudents as $id) {
                $notifiedS[$id] = $students[$id];
            }
            $msgresult = notification::send_notification($notifiedS, $msg, $infolog, $msgbodyinfo);
        }
    }
}

@ardiandeari
Copy link
Author

ardiandeari commented Apr 13, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants