Skip to content
Snippets Groups Projects
Select Git revision
  • 1d997428ede69fd8869725081835ea29a8c5e207
  • main default protected
  • step-3263
  • feature/plugins-cli
  • feature/vite
  • step-2484-peerreview
  • biest/issue-5051
  • tests/simplify-jsonapi-tests
  • fix/typo-in-1a70031
  • feature/broadcasting
  • database-seeders-and-factories
  • feature/peer-review-2
  • feature-feedback-jsonapi
  • feature/peerreview
  • feature/balloon-plus
  • feature/stock-images-unsplash
  • tic-2588
  • 5.0
  • 5.2
  • biest/unlock-blocks
  • biest-1514
21 results

BlubberStatusgruppeThread.php

Blame
  • Forked from Stud.IP / Stud.IP
    Source project has a limited visibility.
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    BlubberStatusgruppeThread.php 3.35 KiB
    <?php
    
    class BlubberStatusgruppeThread extends BlubberThread
    {
        protected static function configure($config = [])
        {
            $config['belongs_to']['statusgruppe'] = [
                'class_name'  => 'Statusgruppen',
                'foreign_key' => function ($thread) {
                    return $thread['metadata']['statusgruppe_id'];
                }
            ];
    
            parent::configure($config);
        }
    
        public static function findByStatusgruppe_id($statusgruppe_id)
        {
            $condition = "INNER JOIN statusgruppen ON (statusgruppen.range_id = context_id)
                          WHERE context_type = 'course'
                            AND statusgruppen.statusgruppe_id = :statusgruppe_id
                            AND display_class = 'BlubberStatusgruppeThread'
                            AND metadata LIKE :like";
            $threads = self::findBySQL($condition, [
                'statusgruppe_id' => $statusgruppe_id,
                'like'            => "%{$statusgruppe_id}%"
            ]);
            foreach ($threads as $thread) {
                if ($thread['metadata']['statusgruppe_id'] === $statusgruppe_id) {
                    return $thread;
                }
            }
            return null;
        }
    
        public function isReadable(string $user_id = null)
        {
            $user_id = $user_id ?? $GLOBALS['user']->id;
            if ($GLOBALS['perm']->have_studip_perm("tutor", $this['context_id'], $user_id)) {
                return true;
            }
    
            $query = "SELECT 1
                      FROM statusgruppe_user
                      WHERE statusgruppe_id = :statusgruppe_id
                        AND user_id = :user_id";
            return (bool) DBManager::get()->fetchColumn($query, [
                'statusgruppe_id' => $this['metadata']['statusgruppe_id'],
                'user_id'         => $user_id
            ]);
        }
    
        public function getName()
        {
            $name = sprintf(_('%s in %s'), $this->statusgruppe->name, Course::find($this['context_id'])->name);
            return $name;
        }
    
        public function getContextTemplate()
        {
            $template = $GLOBALS['template_factory']->open('blubber/coursegroup_context');
            $template->members = $this->statusgruppe->members;
            $template->course = Course::find($this['context_id']);
            $template->thread = $this;
            return $template;
        }
    
        public function notifyUsersForNewComment($comment)
        {
            $query = "SELECT statusgruppe_user.user_id
                      FROM statusgruppe_user
                      WHERE statusgruppe_id = :statusgruppe_id
                        AND user_id != :me
    
                      UNION DISTINCT
    
                      SELECT seminar_user.user_id
                      FROM seminar_user
                      INNER JOIN statusgruppen ON (statusgruppen.range_id = seminar_user.Seminar_id)
                      WHERE statusgruppen.statusgruppe_id = :statusgruppe_id
                        AND seminar_user.status IN ('dozent', 'tutor')
                        AND seminar_user.user_id != :me";
            $user_ids = DBManager::get()->fetchFirst($query, [
                'statusgruppe_id' => $this['metadata']['statusgruppe_id'],
                'me'              => $GLOBALS['user']->id
            ]);
    
            PersonalNotifications::add(
                $user_ids,
                $this->getURL(),
                sprintf(_('%s hat eine Nachricht geschrieben.'), get_fullname()),
                'blubberthread_' . $this->getId(),
                Icon::create('blubber'),
                true
            );
        }
    }