block_efka_messages.php 3.4 KB
Newer Older
g.avgeris's avatar
g.avgeris committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.

/**
 * efka_messages block.
 *
 * @package    block_efka_messages
 * @copyright  1999 onwards Martin Dougiamas (http://dougiamas.com)
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */

defined('MOODLE_INTERNAL') || die();

class block_efka_messages extends block_base{

    function init() {
        $this->title = get_string('efka_messages', 'block_efka_messages');
    }

    function applicable_formats() {
        return array('site'     => true,
                    'course'    => true,
                    'mod'       => true,
                    'mod-quiz'  => true,
                    'mod-quiz-view' => true);
    }

    function get_content() {
        global $CFG, $OUTPUT, $USER, $DB;
        if ($this->content !== null) {
            return $this->content;
        }

        $this->content = new stdClass;
//        $this->content->items = array();
//        $this->content->icons = array();

        $courseid = $this->page->course->id;
        if ($courseid <= 0) {
            $courseid = SITEID;
        }


        if (empty($this->instance->pageid)) {
            $this->instance->pageid = SITEID;
        }

//        if ($feedbacks = feedback_get_feedbacks_from_sitecourse_map($courseid)) {
//            $baseurl = new moodle_url('/mod/feedback/view.php');
//            foreach ($feedbacks as $feedback) {
//                $url = new moodle_url($baseurl);
//                $url->params(array('id'=>$feedback->cmid, 'courseid'=>$courseid));
//                $this->content->items[] = '<a href="'.$url->out().'">'.$icon.$feedback->name.'</a>';
//            }
//        }
        if (isguestuser()) {
           return "";
        }
        if (empty($CFG->messaging)) {
            return "";
        }

        $view = "efka_messages";
//        if (! empty($this->config->username)) {
//            $userid = $this->config->username;
//            $user = $DB->get_record('user', ['username' => $this->config->username]);
//            if ($user) {
//                $userid = $user->id;
//            }
//        }
        //$bucket = crc32 ($USER->);
        $teachers = [   1348, // Χαμάκος (Εκπαιδευτής)
                        1349, // ΣΑΡΑΚΙΝΙΩΤΗ (ΕΚΠΑΙΔΕΥΤΡΙΑ)
                        1358, // ΝΙΦΟΡΟΥ
                        1364  // ΚΑΝΑΚΑΡΗ
                    ];
        $bucket = $USER->id % count($teachers);
        $userid = $teachers[$bucket];

        $conversationid = \core_message\api::get_conversation_between_users([$USER->id, $userid]);

//        \core_message\api::send_message_to_conversation()

        $this->content->text =  \core_message\helper::render_messaging_widget(false, $userid, $conversationid, $view);
        return $this->content;
    }

}