diff options
| author | Philipp Schüttlöffel <schuettloeffel@zqs.uni-hannover.de> | 2024-09-24 10:53:31 +0200 |
|---|---|---|
| committer | Philipp Schüttlöffel <schuettloeffel@zqs.uni-hannover.de> | 2024-09-24 10:53:31 +0200 |
| commit | 4459dd7917f4d1c34f40bb68f0e991e9c3d53e4c (patch) | |
| tree | 5c07151ae61276d334e88f6309c30d439a85c12e /lib/models/StudipComment.php | |
| parent | da0022e5c1abbf9825ae76debaabdff7e8623bb4 (diff) | |
| parent | 97a188592c679890a25c37ab78463add76a52ff7 (diff) | |
Merge branch 'main' into issue-3911issue-3911
Diffstat (limited to 'lib/models/StudipComment.php')
| -rw-r--r-- | lib/models/StudipComment.php | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/lib/models/StudipComment.php b/lib/models/StudipComment.php new file mode 100644 index 0000000..79610f8 --- /dev/null +++ b/lib/models/StudipComment.php @@ -0,0 +1,115 @@ +<?php +# Lifter007: TODO +# Lifter003: TEST +# Lifter010: TODO +// +---------------------------------------------------------------------------+ +// This file is part of Stud.IP +// +// Copyright (C) 2005 Tobias Thelen , <tthelen@uni-osnabrueck.de> +// +// +---------------------------------------------------------------------------+ +// 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 any later version. +// +---------------------------------------------------------------------------+ +// This program 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 this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +---------------------------------------------------------------------------+ + +/** + * StudipComment.php + * + * + * + * + * @author André Noack <noack@data-quest>, Suchi & Berg GmbH <info@data-quest.de> + * @access public + * + * @property string $id alias column for comment_id + * @property string $comment_id database column + * @property string $object_id database column + * @property string $user_id database column + * @property string $content database column + * @property int $mkdate database column + * @property int $chdate database column + * @property StudipNews $news belongs_to StudipNews + */ + +class StudipComment extends SimpleORMap implements PrivacyObject +{ + protected static function configure($config = []) + { + $config['db_table'] = 'comments'; + + $config['belongs_to']['news'] = [ + 'class_name' => StudipNews::class, + 'foreign_key' => 'object_id', + ]; + + parent::configure($config); + } + + public static function NumCommentsForObject($object_id) + { + return self::countBySql('object_id = ?', [$object_id]); + } + + public static function NumCommentsForObjectSinceLastVisit($object_id, $comments_since = 0, $exclude_user_id = null) + { + $query = "object_id = ?"; + $query .= " AND chdate > ?"; + if ($exclude_user_id) { + $query .= " AND user_id != ?"; + } + return self::countBySql($query, [$object_id, $comments_since, $exclude_user_id]); + } + + public static function GetCommentsForObject($object_id) + { + global $_fullname_sql; + $query = "SELECT comments.content, {$_fullname_sql['full']} AS fullname, + a.username, comments.mkdate, comments.comment_id + FROM comments + LEFT JOIN auth_user_md5 AS a USING (user_id) + LEFT JOIN user_info USING (user_id) + WHERE object_id = ? + ORDER BY comments.mkdate"; + $statement = DBManager::get()->prepare($query); + $statement->execute([$object_id]); + return $statement->fetchAll(PDO::FETCH_BOTH); + } + + public static function DeleteCommentsByObject($object_ids) + { + if (!is_array($object_ids)) { + $object_ids = [$object_ids]; + } + $where = "object_id IN (?)"; + return self::deleteBySQL($where, [$object_ids]); + } + /** + * Export available data of a given user into a storage object + * (an instance of the StoredUserData class) for that user. + * + * @param StoredUserData $storage object to store data into + */ + public static function exportUserData(StoredUserData $storage) + { + $sorm = self::findBySQL("user_id = ?", [$storage->user_id]); + if ($sorm) { + $field_data = []; + foreach ($sorm as $row) { + $field_data[] = $row->toRawArray(); + } + if ($field_data) { + $storage->addTabularData(_('Ankündigungen Kommentare'), 'comments', $field_data); + } + } + } +} |
