3 * @copyright Copyright (C) 2020, Friendica
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\Repository;
25 use Friendica\BaseRepository;
26 use Friendica\Core\Hook;
28 use Friendica\Collection;
29 use Friendica\Network\HTTPException\InternalServerErrorException;
30 use Friendica\Network\HTTPException\NotFoundException;
31 use Friendica\Util\DateTimeFormat;
33 class Notify extends BaseRepository
35 protected static $table_name = 'notify';
37 protected static $model_class = Model\Notify::class;
39 protected static $collection_class = Collection\Notifies::class;
44 * @return Model\Notify
46 protected function create(array $data)
48 return new Model\Notify($this->dba, $this->logger, $this, $data);
54 * @return Collection\Notifies
56 public function select(array $condition = [], array $params = [])
58 $params['order'] = $params['order'] ?? ['date' => 'DESC'];
60 return parent::select($condition, $params);
66 * @return Model\Notify
67 * @throws NotFoundException
69 public function getByID(int $id)
71 return $this->selectFirst(['id' => $id, 'uid' => local_user()]);
75 * Set seen state of notifications of the local_user()
77 * @param bool $seen optional true or false. default true
78 * @param Model\Notify $notify optional a notify, which should be set seen (including his parents)
80 * @return bool true on success, false on error
84 public function setSeen(bool $seen = true, Model\Notify $notify = null)
87 $conditions = ['uid' => local_user()];
89 $conditions = ['(`link` = ? OR (`parent` != 0 AND `parent` = ? AND `otype` = ?)) AND `uid` = ?',
96 return $this->dba->update('notify', ['seen' => $seen], $conditions);
100 * @param array $fields
102 * @return Model\Notify|false
104 * @throws InternalServerErrorException
107 public function insert(array $fields)
109 $fields['date'] = DateTimeFormat::utcNow();
111 Hook::callAll('enotify_store', $fields);
113 if (empty($fields)) {
114 $this->logger->debug('Abort adding notification entry');
118 $this->logger->debug('adding notification entry', ['fields' => $fields]);
120 return parent::insert($fields);