]> git.mxchange.org Git - friendica.git/blob - src/Repository/Notify.php
remove now empty array from logger
[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                 $condition = array_merge($condition, ['uid' => local_user()]);
41
42                 return parent::select($condition, $params);
43         }
44
45         /**
46          * {@inheritDoc}
47          *
48          * @return Model\Notify
49          * @throws NotFoundException
50          */
51         public function getByID(int $id)
52         {
53                 return $this->selectFirst(['id' => $id, 'uid' => local_user()]);
54         }
55
56         /**
57          * {@inheritDoc}
58          *
59          * @return bool true on success, false on error
60          * @throws Exception
61          */
62         public function setAllSeen(bool $seen = true)
63         {
64                 return $this->dba->update('notify', ['seen' => $seen], ['uid' => local_user()]);
65         }
66
67         /**
68          * @param array $fields
69          *
70          * @return Model\Notify|false
71          *
72          * @throws \Friendica\Network\HTTPException\InternalServerErrorException
73          * @throws Exception
74          */
75         public function insert(array $fields)
76         {
77                 $fields['date']  = DateTimeFormat::utcNow();
78
79                 Hook::callAll('enotify_store', $fields);
80
81                 if (empty($fields)) {
82                         $this->logger->debug('Abort adding notification entry');
83                         return false;
84                 }
85
86                 $this->logger->debug('adding notification entry', ['fields' => $fields]);
87
88                 return parent::insert($fields);
89         }
90 }