3 * @copyright Copyright (C) 2010-2023, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Model\Post;
24 use \BadMethodCallException;
25 use Friendica\Database\Database;
26 use Friendica\Database\DBA;
27 use Friendica\Database\DBStructure;
33 * Insert a new URI user entry
35 * @param integer $uri_id
37 * @param array $fields
38 * @return bool success
41 public static function insert(int $uri_id, int $uid, array $data = [])
44 throw new BadMethodCallException('Empty URI_id');
47 $fields = DI::dbaDefinition()->truncateFieldsForTable('post-thread-user', $data);
49 // Additionally assign the key fields
50 $fields['uri-id'] = $uri_id;
51 $fields['uid'] = $uid;
53 return DBA::insert('post-thread-user', $fields, Database::INSERT_IGNORE);
57 * Update a URI user entry
59 * @param integer $uri_id
62 * @param bool $insert_if_missing
66 public static function update(int $uri_id, int $uid, array $data = [], bool $insert_if_missing = false)
69 throw new BadMethodCallException('Empty URI_id');
72 $fields = DI::dbaDefinition()->truncateFieldsForTable('post-thread-user', $data);
74 // Remove the key fields
75 unset($fields['uri-id']);
76 unset($fields['uid']);
82 return DBA::update('post-thread-user', $fields, ['uri-id' => $uri_id, 'uid' => $uid], $insert_if_missing ? true : []);
86 * Delete a row from the post-thread-user table
88 * @param array $conditions Field condition(s)
89 * @param array $options
90 * - cascade: If true we delete records in other tables that depend on the one we're deleting through
91 * relations (default: true)
93 * @return boolean was the delete successful?
96 public static function delete(array $conditions, array $options = [])
98 return DBA::delete('post-thread-user', $conditions, $options);
107 public static function getIgnored(int $uri_id, int $uid)
109 $threaduser = DBA::selectFirst('post-thread-user', ['ignored'], ['uri-id' => $uri_id, 'uid' => $uid]);
110 if (empty($threaduser)) {
113 return (bool)$threaduser['ignored'];
119 * @param int $ignored
123 public static function setIgnored(int $uri_id, int $uid, int $ignored)
125 DBA::update('post-thread-user', ['ignored' => $ignored], ['uri-id' => $uri_id, 'uid' => $uid], true);