Proyectos de Subversion Moodle

Rev

Rev 11 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 11 Rev 1441
Línea 22... Línea 22...
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
23
 */
Línea 24... Línea 24...
24
 
24
 
25
namespace core_message;
25
namespace core_message;
-
 
26
use DOMDocument;
Línea 26... Línea 27...
26
use DOMDocument;
27
use stdclass;
Línea 27... Línea 28...
27
 
28
 
Línea 135... Línea 136...
135
        // Store the messages.
136
        // Store the messages.
136
        $arrmessages = array();
137
        $arrmessages = array();
Línea 137... Línea 138...
137
 
138
 
138
        foreach ($messages as $message) {
139
        foreach ($messages as $message) {
139
            // Store the message information.
140
            // Store the message information.
140
            $msg = new \stdClass();
141
            $msg = new stdClass();
141
            $msg->id = $message->id;
142
            $msg->id = $message->id;
142
            $msg->useridfrom = $message->useridfrom;
143
            $msg->useridfrom = $message->useridfrom;
143
            $msg->text = message_format_message_text($message);
144
            $msg->text = message_format_message_text($message);
144
            $msg->timecreated = $message->timecreated;
145
            $msg->timecreated = $message->timecreated;
Línea 170... Línea 171...
170
    }
171
    }
Línea 171... Línea 172...
171
 
172
 
172
    /**
173
    /**
173
     * Helper function for creating a contact object.
174
     * Helper function for creating a contact object.
174
     *
175
     *
175
     * @param \stdClass $contact
176
     * @param stdClass $contact
176
     * @param string $prefix
177
     * @param string $prefix
177
     * @return \stdClass
178
     * @return stdClass
178
     */
179
     */
179
    public static function create_contact($contact, $prefix = '') {
180
    public static function create_contact($contact, $prefix = '') {
Línea 180... Línea 181...
180
        global $PAGE;
181
        global $PAGE;
181
 
182
 
182
        // Create the data we are going to pass to the renderable.
183
        // Create the data we are going to pass to the renderable.
183
        $userfields = \user_picture::unalias($contact, array('lastaccess'), $prefix . 'id', $prefix);
184
        $userfields = \user_picture::unalias($contact, array('lastaccess'), $prefix . 'id', $prefix);
184
        $data = new \stdClass();
185
        $data = new stdClass();
185
        $data->userid = $userfields->id;
186
        $data->userid = $userfields->id;
186
        $data->useridfrom = null;
187
        $data->useridfrom = null;
187
        $data->fullname = fullname($userfields);
188
        $data->fullname = fullname($userfields);
Línea 220... Línea 221...
220
    }
221
    }
Línea 221... Línea 222...
221
 
222
 
222
    /**
223
    /**
223
     * Helper function for checking if we should show the user's online status.
224
     * Helper function for checking if we should show the user's online status.
224
     *
225
     *
225
     * @param \stdClass $user
226
     * @param stdClass $user
226
     * @return boolean
227
     * @return boolean
227
     */
228
     */
228
    public static function show_online_status($user) {
229
    public static function show_online_status($user) {
Línea 261... Línea 262...
261
    /**
262
    /**
262
     * Get providers preferences.
263
     * Get providers preferences.
263
     *
264
     *
264
     * @param array $providers
265
     * @param array $providers
265
     * @param int $userid
266
     * @param int $userid
266
     * @return \stdClass
267
     * @return stdClass
267
     */
268
     */
268
    public static function get_providers_preferences($providers, $userid) {
269
    public static function get_providers_preferences($providers, $userid) {
269
        $preferences = new \stdClass();
270
        $preferences = new stdClass();
Línea 270... Línea 271...
270
 
271
 
271
        // Get providers preferences.
272
        // Get providers preferences.
272
        foreach ($providers as $provider) {
273
        foreach ($providers as $provider) {
273
            $linepref = get_user_preferences('message_provider_' . $provider->component . '_' . $provider->name
274
            $linepref = get_user_preferences('message_provider_' . $provider->component . '_' . $provider->name
Línea 451... Línea 452...
451
        $otherusers = $DB->get_records_sql($userssql, $usersparams);
452
        $otherusers = $DB->get_records_sql($userssql, $usersparams);
Línea 452... Línea 453...
452
 
453
 
453
        $members = [];
454
        $members = [];
454
        foreach ($otherusers as $member) {
455
        foreach ($otherusers as $member) {
455
            // Set basic data.
456
            // Set basic data.
456
            $data = new \stdClass();
457
            $data = new stdClass();
457
            $data->id = $member->id;
458
            $data->id = $member->id;
Línea 458... Línea 459...
458
            $data->fullname = fullname($member);
459
            $data->fullname = fullname($member);
459
 
460
 
Línea 477... Línea 478...
477
            }
478
            }
Línea 478... Línea 479...
478
 
479
 
479
            // Set contact and blocked status indicators.
480
            // Set contact and blocked status indicators.
Línea -... Línea 481...
-
 
481
            $data->iscontact = ($member->contactid) ? true : false;
-
 
482
 
-
 
483
            // Set permission to create a contact request.
480
            $data->iscontact = ($member->contactid) ? true : false;
484
            $data->cancreatecontact = api::can_create_contact($referenceuserid, $member->id);
481
 
485
 
482
            // We don't want that a user has been blocked if they can message the user anyways.
486
            // We don't want that a user has been blocked if they can message the user anyways.
Línea 483... Línea 487...
483
            $canmessageifblocked = api::can_send_message($referenceuserid, $member->id, true);
487
            $canmessageifblocked = api::can_send_message($referenceuserid, $member->id, true);
Línea 550... Línea 554...
550
     * @param string|null $view The first view to load in the message widget
554
     * @param string|null $view The first view to load in the message widget
551
     * @return string The HTML.
555
     * @return string The HTML.
552
     */
556
     */
553
    public static function render_messaging_widget(
557
    public static function render_messaging_widget(
554
        bool $isdrawer,
558
        bool $isdrawer,
555
        int $sendtouser = null,
559
        ?int $sendtouser = null,
556
        int $conversationid = null,
560
        ?int $conversationid = null,
557
        string $view = null
561
        ?string $view = null
558
    ) {
562
    ) {
559
        global $USER, $CFG, $PAGE;
563
        global $USER, $CFG, $PAGE;
Línea 560... Línea 564...
560
 
564
 
561
        // Early bail out conditions.
565
        // Early bail out conditions.
Línea 666... Línea 670...
666
     * The minimum user fields are:
670
     * The minimum user fields are:
667
     *  * id
671
     *  * id
668
     *  * deleted
672
     *  * deleted
669
     *  * all potential fullname fields
673
     *  * all potential fullname fields
670
     *
674
     *
671
     * @param \stdClass $user
675
     * @param stdClass $user
672
     * @param array $userfields An array of userfields to be returned, the values must be a
676
     * @param array $userfields An array of userfields to be returned, the values must be a
673
     *                          subset of user_get_default_fields (optional)
677
     *                          subset of user_get_default_fields (optional)
674
     * @return array the array of userdetails, if visible, or an empty array otherwise.
678
     * @return array the array of userdetails, if visible, or an empty array otherwise.
675
     */
679
     */
676
    public static function search_get_user_details(\stdClass $user, array $userfields = []): array {
680
    public static function search_get_user_details(stdClass $user, array $userfields = []): array {
677
        global $CFG, $USER;
681
        global $CFG, $USER;
678
        require_once($CFG->dirroot . '/user/lib.php');
682
        require_once($CFG->dirroot . '/user/lib.php');
Línea 679... Línea 683...
679
 
683
 
680
        if ($CFG->messagingallusers || $user->id == $USER->id) {
684
        if ($CFG->messagingallusers || $user->id == $USER->id) {
Línea 719... Línea 723...
719
            }
723
            }
720
        }
724
        }
Línea 721... Línea 725...
721
 
725
 
722
        return $html;
726
        return $html;
-
 
727
    }
-
 
728
 
-
 
729
    /**
-
 
730
     * Check the support for SMS in different components.
-
 
731
     *
-
 
732
     * At the moment, SMS is not supported for all the components.
-
 
733
     * Components that supports SMS, can implement the callback to let the notification API support them.
-
 
734
     *
-
 
735
     * @param stdclass $messagedata The message data
-
 
736
     * @return bool
-
 
737
     */
-
 
738
    public static function supports_sms_notifications(stdclass $messagedata): bool {
-
 
739
        // Notification API assigns system ones as component 'moodle'.
-
 
740
        // We need a special mechanism to handle that as component callback will throw errors.
-
 
741
        if ($messagedata->component === 'moodle') {
-
 
742
            return false;
-
 
743
        }
-
 
744
 
-
 
745
        $smssupport = component_callback(
-
 
746
            $messagedata->component,
-
 
747
            'supports_sms_notifications'
-
 
748
        );
-
 
749
 
-
 
750
        if (empty($smssupport)) {
-
 
751
            return false;
-
 
752
        }
-
 
753
        return true;
723
    }
754
    }