Select Git revision
CoursesetModel.php
Forked from
Stud.IP / Stud.IP
Source project has a limited visibility.
-
Jan-Hendrik Willms authoredJan-Hendrik Willms authored
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
BlubberThread.php 41.13 KiB
<?php
/**
* BlubberThread
* Model class for BlubberThreads
*
* This program 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 2 of
* the License, or (at your option) any later version.
*
* @author Rasmus Fuhse <fuhse@data-quest.de>
* @license http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
* @category Stud.IP
* @since 4.5
*/
class BlubberThread extends SimpleORMap implements PrivacyObject
{
/**
* Configures this model.
*
* @param array $config Configuration array
*/
protected static function configure($config = [])
{
$config['db_table'] = 'blubber_threads';
$config['has_many']['comments'] = [
'class_name' => BlubberComment::class,
'on_store' => 'store',
'on_delete' => 'delete',
'order_by' => 'ORDER BY mkdate ASC'
];
$config['has_many']['mentions'] = [
'class_name' => BlubberMention::class,
'on_store' => 'store',
'on_delete' => 'delete',
];
$config['belongs_to']['user'] = [
'class_name' => User::class,
'foreign_key' => 'user_id',
'assoc_foreign_key' => 'user_id',
];
$config['serialized_fields']['metadata'] = 'JSONArrayObject';
parent::configure($config);
}
public static $mention_thread_id = null;
protected $last_visit = null;
/**
* Pre-Markup rule. Recognizes mentions in blubber as @username or @"Firstname lastname"
* and turns them into usual studip-links. The mentioned person is notified by
* sending a message to him/her as a side-effect.
* @param StudipTransformFormat $markup
* @param array $matches
* @return string
*/
public static function mention($markup, $matches)
{
$mention = $matches[1];
$thread = self::find(self::$mention_thread_id);
$username = stripslashes(mb_substr($mention, 1));
if ($username[0] !== '"') {
$user = User::findByUsername($username);
} else {
$name = mb_substr($username, 1, -1); // Strip quotes
$user = User::findOneBySQL("CONCAT(Vorname, ' ', Nachname) = ?", [$name]);