]> git.mxchange.org Git - friendica.git/blob - src/Repository/Notify.php
8c71fc289a1bd830b08515db4b16e1ef0e57896f
[friendica.git] / src / Repository / Notify.php
1 <?php
2
3 namespace Friendica\Repository;
4
5 use Exception;
6 use Friendica\BaseRepository;
7 use Friendica\Core\Hook;
8 use Friendica\Model;
9 use Friendica\Collection;
10 use Friendica\Network\HTTPException\NotFoundException;
11 use Friendica\Util\DateTimeFormat;
12
13 class Notify extends BaseRepository
14 {
15         protected static $table_name = 'notify';
16
17         protected static $model_class = Model\Notify::class;
18
19         protected static $collection_class = Collection\Notifies::class;
20
21         /**
22          * {@inheritDoc}
23          *
24          * @return Model\Notify
25          */
26         protected function create(array $data)
27         {
28                 return new Model\Notify($this->dba, $this->logger, $this, $data);
29         }
30
31         /**
32          * {@inheritDoc}
33          *
34          * @return Collection\Notifies
35          */
36         public function select(array $condition = [], array $params = [])
37         {
38                 $params['order'] = $params['order'] ?? ['date' => 'DESC'];
39
40                 return parent::select($condition, $params);
41         }
42
43         /**
44          * {@inheritDoc}
45          *
46          * @return Model\Notify
47          * @throws NotFoundException
48          */
49         public function getByID(int $id)
50         {
51                 return $this->selectFirst(['id' => $id, 'uid' => local_user()]);
52         }
53
54         /**
55          * {@inheritDoc}
56          *
57          * @return bool true on success, false on error
58          * @throws Exception
59          */
60         public function setAllSeen(bool $seen = true)
61         {
62                 return $this->dba->update('notify', ['seen' => $seen], ['uid' => local_user()]);
63         }
64
65         /**
66          * @param array $fields
67          *
68          * @return Model\Notify|false
69          *
70          * @throws \Friendica\Network\HTTPException\InternalServerErrorException
71          * @throws Exception
72          */
73         public function insert(array $fields)
74         {
75                 $fields['date']  = DateTimeFormat::utcNow();
76
77                 Hook::callAll('enotify_store', $fields);
78
79                 if (empty($fields)) {
80                         $this->logger->debug('Abort adding notification entry');
81                         return false;
82                 }
83
84                 $this->logger->debug('adding notification entry', ['fields' => $fields]);
85
86                 return parent::insert($fields);
87         }
88 }