3 namespace Friendica\Repository;
6 use Friendica\BaseRepository;
7 use Friendica\Core\Hook;
9 use Friendica\Collection;
10 use Friendica\Network\HTTPException\NotFoundException;
11 use Friendica\Util\DateTimeFormat;
13 class Notification extends BaseRepository
15 protected static $table_name = 'notify';
17 protected static $model_class = Model\Notification::class;
19 protected static $collection_class = Collection\Notifications::class;
24 * @return Model\Notification
26 protected function create(array $data)
28 return new Model\Notification($this->dba, $this->logger, $this, $data);
34 * @return Collection\Notifications
36 public function select(array $condition = [], array $params = [])
38 $params['order'] = $params['order'] ?? ['date' => 'DESC'];
40 $condition = array_merge($condition, ['uid' => local_user()]);
42 return parent::select($condition, $params);
48 * @return Model\Notification
49 * @throws NotFoundException
51 public function getByID(int $id)
53 return $this->selectFirst(['id' => $id, 'uid' => local_user()]);
59 * @return bool true on success, false on error
62 public function setAllSeen(bool $seen = true)
64 return $this->dba->update('notify', ['seen' => $seen], ['uid' => local_user()]);
68 * @param array $fields
70 * @return Model\Notification
72 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
75 public function insert(array $fields)
77 $fields['date'] = DateTimeFormat::utcNow();
78 $fields['abort'] = false;
80 Hook::callAll('enotify_store', $fields);
82 if ($fields['abort']) {
83 $this->logger->debug('Abort adding notification entry', ['fields' => $fields]);
87 $this->logger->debug('adding notification entry', ['fields' => $fields]);
89 return parent::insert($fields);