3 namespace Friendica\Repository;
6 use Friendica\BaseRepository;
7 use Friendica\Core\Hook;
9 use Friendica\Collection;
10 use Friendica\Network\HTTPException\InternalServerErrorException;
11 use Friendica\Network\HTTPException\NotFoundException;
12 use Friendica\Util\DateTimeFormat;
14 class Notify extends BaseRepository
16 protected static $table_name = 'notify';
18 protected static $model_class = Model\Notify::class;
20 protected static $collection_class = Collection\Notifies::class;
25 * @return Model\Notify
27 protected function create(array $data)
29 return new Model\Notify($this->dba, $this->logger, $this, $data);
35 * @return Collection\Notifies
37 public function select(array $condition = [], array $params = [])
39 $params['order'] = $params['order'] ?? ['date' => 'DESC'];
41 return parent::select($condition, $params);
47 * @return Model\Notify
48 * @throws NotFoundException
50 public function getByID(int $id)
52 return $this->selectFirst(['id' => $id, 'uid' => local_user()]);
56 * Set seen state of notifications of the local_user()
58 * @param bool $seen optional true or false. default true
59 * @param Model\Notify $notify optional a notify, which should be set seen (including his parents)
61 * @return bool true on success, false on error
65 public function setSeen(bool $seen = true, Model\Notify $notify = null)
68 $conditions = ['uid' => local_user()];
70 $conditions = ['(`link` = ? OR (`parent` != 0 AND `parent` = ? AND `otype` = ?)) AND `uid` = ?',
77 return $this->dba->update('notify', ['seen' => $seen], $conditions);
81 * @param array $fields
83 * @return Model\Notify|false
85 * @throws InternalServerErrorException
88 public function insert(array $fields)
90 $fields['date'] = DateTimeFormat::utcNow();
92 Hook::callAll('enotify_store', $fields);
95 $this->logger->debug('Abort adding notification entry');
99 $this->logger->debug('adding notification entry', ['fields' => $fields]);
101 return parent::insert($fields);